Created
September 29, 2020 13:36
-
-
Save amalgjose/03b7a083f19efe7111979896a254ecc0 to your computer and use it in GitHub Desktop.
Python program to write a file into Microsoft Azure Data Lake Storage (ADLS Gen2) file system. For more details, refer to https://amalgjose.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from azure.storage.filedatalake import DataLakeServiceClient | |
# install the following package | |
# pip install azure-storage-file-datalake | |
# Get the below details from your storage account | |
storage_account_name = "" | |
storage_account_key = "" | |
container_name = "" | |
directory_name = "" | |
service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format( | |
"https", storage_account_name), credential=storage_account_key) | |
file_system_client = service_client.get_file_system_client(file_system=container_name) | |
dir_client = file_system_client.get_directory_client(directory_name) | |
dir_client.create_directory() | |
data = """ | |
Sample data for testing. | |
This is a multiline text for testing the ADLS Gen2 file system operations. | |
""" | |
file_client = dir_client.create_file("sampledata.txt") | |
file_client.append_data(data, 0, len(data)) | |
file_client.flush_data(len(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment