| 1 |
Microsoft Azure Data Lake Store Filesystem Library for Python |
| 2 |
============================================================= |
| 3 |
|
| 4 |
.. image:: https://travis-ci.org/Azure/azure-data-lake-store-python.svg?branch=dev |
| 5 |
:target: https://travis-ci.org/Azure/azure-data-lake-store-python |
| 6 |
.. image:: https://coveralls.io/repos/github/Azure/azure-data-lake-store-python/badge.svg?branch=master |
| 7 |
:target: https://coveralls.io/github/Azure/azure-data-lake-store-python?branch=master |
| 8 |
|
| 9 |
This project is the Python filesystem library for Azure Data Lake Store. |
| 10 |
|
| 11 |
INSTALLATION |
| 12 |
============ |
| 13 |
|
| 14 |
To install from source instead of pip (for local testing and development): |
| 15 |
|
| 16 |
.. code-block:: bash |
| 17 |
|
| 18 |
> pip install -r dev_requirements.txt |
| 19 |
> python setup.py develop |
| 20 |
|
| 21 |
Usage: Sample Code |
| 22 |
================== |
| 23 |
|
| 24 |
To play with the code, here is a starting point: |
| 25 |
|
| 26 |
.. code-block:: python |
| 27 |
|
| 28 |
from azure.datalake.store import core, lib, multithread |
| 29 |
token = lib.auth(tenant_id, username, password) |
| 30 |
adl = core.AzureDLFileSystem(token, store_name=store_name) |
| 31 |
|
| 32 |
# typical operations |
| 33 |
adl.ls('') |
| 34 |
adl.ls('tmp/', detail=True) |
| 35 |
adl.ls('tmp/', detail=True, invalidate_cache=True) |
| 36 |
adl.cat('littlefile') |
| 37 |
adl.head('gdelt20150827.csv') |
| 38 |
|
| 39 |
# file-like object |
| 40 |
with adl.open('gdelt20150827.csv', blocksize=2**20) as f: |
| 41 |
print(f.readline()) |
| 42 |
print(f.readline()) |
| 43 |
print(f.readline()) |
| 44 |
# could have passed f to any function requiring a file object: |
| 45 |
# pandas.read_csv(f) |
| 46 |
|
| 47 |
with adl.open('anewfile', 'wb') as f: |
| 48 |
# data is written on flush/close, or when buffer is bigger than |
| 49 |
# blocksize |
| 50 |
f.write(b'important data') |
| 51 |
|
| 52 |
adl.du('anewfile') |
| 53 |
|
| 54 |
# recursively download the whole directory tree with 5 threads and |
| 55 |
# 16MB chunks |
| 56 |
multithread.ADLDownloader(adl, "", 'my_temp_dir', 5, 2**24) |
| 57 |
|
| 58 |
Progress can be tracked using a callback function in the form `track(current, total)` |
| 59 |
When passed, this will keep track of transferred bytes and be called on each complete chunk. |
| 60 |
|
| 61 |
Here's an example using the Azure CLI progress controller as the `progress_callback`: |
| 62 |
|
| 63 |
.. code-block:: python |
| 64 |
|
| 65 |
from cli.core.application import APPLICATION |
| 66 |
|
| 67 |
def _update_progress(current, total): |
| 68 |
hook = APPLICATION.get_progress_controller(det=True) |
| 69 |
hook.add(message='Alive', value=current, total_val=total) |
| 70 |
if total == current: |
| 71 |
hook.end() |
| 72 |
|
| 73 |
... |
| 74 |
ADLUploader(client, destination_path, source_path, thread_count, overwrite=overwrite, |
| 75 |
chunksize=chunk_size, |
| 76 |
buffersize=buffer_size, |
| 77 |
blocksize=block_size, |
| 78 |
progress_callback=_update_progress) |
| 79 |
|
| 80 |
This will output a progress bar to the stdout: |
| 81 |
|
| 82 |
.. code-block:: bash |
| 83 |
|
| 84 |
Alive[######################### ] 40.0881% |
| 85 |
|
| 86 |
Finished[#############################################################] 100.0000% |
| 87 |
|
| 88 |
Usage: Command Line Sample |
| 89 |
========================== |
| 90 |
|
| 91 |
To interact with the API at a higher-level, you can use the provided |
| 92 |
command-line interface in "samples/cli.py". You will need to set |
| 93 |
the appropriate environment variables |
| 94 |
|
| 95 |
* :code:`azure_username` |
| 96 |
|
| 97 |
* :code:`azure_password` |
| 98 |
|
| 99 |
* :code:`azure_data_lake_store_name` |
| 100 |
|
| 101 |
* :code:`azure_subscription_id` |
| 102 |
|
| 103 |
* :code:`azure_resource_group_name` |
| 104 |
|
| 105 |
* :code:`azure_service_principal` |
| 106 |
|
| 107 |
* :code:`azure_service_principal_secret` |
| 108 |
|
| 109 |
to connect to the Azure Data Lake Store. Optionally, you may need to define :code:`azure_tenant_id` or :code:`azure_data_lake_store_url_suffix`. |
| 110 |
|
| 111 |
Below is a simple sample, with more details beyond. |
| 112 |
|
| 113 |
|
| 114 |
.. code-block:: bash |
| 115 |
|
| 116 |
python samples\cli.py ls -l |
| 117 |
|
| 118 |
Execute the program without arguments to access documentation. |
| 119 |
|
| 120 |
To start the CLI in interactive mode, run "python samples/cli.py" |
| 121 |
and then type "help" to see all available commands (similiar to Unix utilities): |
| 122 |
|
| 123 |
.. code-block:: bash |
| 124 |
|
| 125 |
> python samples/cli.py |
| 126 |
azure> help |
| 127 |
|
| 128 |
Documented commands (type help <topic>): |
| 129 |
======================================== |
| 130 |
cat chmod close du get help ls mv quit rmdir touch |
| 131 |
chgrp chown df exists head info mkdir put rm tail |
| 132 |
|
| 133 |
azure> |
| 134 |
|
| 135 |
|
| 136 |
While still in interactive mode, you can run "ls -l" to list the entries in the |
| 137 |
home directory ("help ls" will show the command's usage details). If you're not |
| 138 |
familiar with the Unix/Linux "ls" command, the columns represent 1) permissions, |
| 139 |
2) file owner, 3) file group, 4) file size, 5-7) file's modification time, and |
| 140 |
8) file name. |
| 141 |
|
| 142 |
.. code-block:: bash |
| 143 |
|
| 144 |
> python samples/cli.py |
| 145 |
azure> ls -l |
| 146 |
drwxrwx--- 0123abcd 0123abcd 0 Aug 02 12:44 azure1 |
| 147 |
-rwxrwx--- 0123abcd 0123abcd 1048576 Jul 25 18:33 abc.csv |
| 148 |
-r-xr-xr-x 0123abcd 0123abcd 36 Jul 22 18:32 xyz.csv |
| 149 |
drwxrwx--- 0123abcd 0123abcd 0 Aug 03 13:46 tmp |
| 150 |
azure> ls -l --human-readable |
| 151 |
drwxrwx--- 0123abcd 0123abcd 0B Aug 02 12:44 azure1 |
| 152 |
-rwxrwx--- 0123abcd 0123abcd 1M Jul 25 18:33 abc.csv |
| 153 |
-r-xr-xr-x 0123abcd 0123abcd 36B Jul 22 18:32 xyz.csv |
| 154 |
drwxrwx--- 0123abcd 0123abcd 0B Aug 03 13:46 tmp |
| 155 |
azure> |
| 156 |
|
| 157 |
|
| 158 |
To download a remote file, run "get remote-file [local-file]". The second |
| 159 |
argument, "local-file", is optional. If not provided, the local file will be |
| 160 |
named after the remote file minus the directory path. |
| 161 |
|
| 162 |
.. code-block:: bash |
| 163 |
|
| 164 |
> python samples/cli.py |
| 165 |
azure> ls -l |
| 166 |
drwxrwx--- 0123abcd 0123abcd 0 Aug 02 12:44 azure1 |
| 167 |
-rwxrwx--- 0123abcd 0123abcd 1048576 Jul 25 18:33 abc.csv |
| 168 |
-r-xr-xr-x 0123abcd 0123abcd 36 Jul 22 18:32 xyz.csv |
| 169 |
drwxrwx--- 0123abcd 0123abcd 0 Aug 03 13:46 tmp |
| 170 |
azure> get xyz.csv |
| 171 |
2016-08-04 18:57:48,603 - ADLFS - DEBUG - Creating empty file xyz.csv |
| 172 |
2016-08-04 18:57:48,604 - ADLFS - DEBUG - Fetch: xyz.csv, 0-36 |
| 173 |
2016-08-04 18:57:49,726 - ADLFS - DEBUG - Downloaded to xyz.csv, byte offset 0 |
| 174 |
2016-08-04 18:57:49,734 - ADLFS - DEBUG - File downloaded (xyz.csv -> xyz.csv) |
| 175 |
azure> |
| 176 |
|
| 177 |
|
| 178 |
It is also possible to run in command-line mode, allowing any available command |
| 179 |
to be executed separately without remaining in the interpreter. |
| 180 |
|
| 181 |
For example, listing the entries in the home directory: |
| 182 |
|
| 183 |
.. code-block:: bash |
| 184 |
|
| 185 |
> python samples/cli.py ls -l |
| 186 |
drwxrwx--- 0123abcd 0123abcd 0 Aug 02 12:44 azure1 |
| 187 |
-rwxrwx--- 0123abcd 0123abcd 1048576 Jul 25 18:33 abc.csv |
| 188 |
-r-xr-xr-x 0123abcd 0123abcd 36 Jul 22 18:32 xyz.csv |
| 189 |
drwxrwx--- 0123abcd 0123abcd 0 Aug 03 13:46 tmp |
| 190 |
> |
| 191 |
|
| 192 |
|
| 193 |
Also, downloading a remote file: |
| 194 |
|
| 195 |
.. code-block:: bash |
| 196 |
|
| 197 |
> python samples/cli.py get xyz.csv |
| 198 |
2016-08-04 18:57:48,603 - ADLFS - DEBUG - Creating empty file xyz.csv |
| 199 |
2016-08-04 18:57:48,604 - ADLFS - DEBUG - Fetch: xyz.csv, 0-36 |
| 200 |
2016-08-04 18:57:49,726 - ADLFS - DEBUG - Downloaded to xyz.csv, byte offset 0 |
| 201 |
2016-08-04 18:57:49,734 - ADLFS - DEBUG - File downloaded (xyz.csv -> xyz.csv) |
| 202 |
> |
| 203 |
|
| 204 |
Tests |
| 205 |
===== |
| 206 |
|
| 207 |
For detailed documentation about our test framework, please visit the |
| 208 |
`tests folder <https://github.com/Azure/azure-data-lake-store-python/tree/master/tests>`__. |
| 209 |
|
| 210 |
Need Help? |
| 211 |
========== |
| 212 |
|
| 213 |
Be sure to check out the Microsoft Azure `Developer Forums on Stack Overflow <http://go.microsoft.com/fwlink/?LinkId=234489>`__ |
| 214 |
if you have trouble with the provided code. Most questions are tagged `azure and python <https://stackoverflow.com/questions/tagged/azure+python>`__. |
| 215 |
|
| 216 |
|
| 217 |
Contribute Code or Provide Feedback |
| 218 |
=================================== |
| 219 |
|
| 220 |
If you would like to become an active contributor to this project please |
| 221 |
follow the instructions provided in `Microsoft Azure Projects Contribution Guidelines <http://azure.github.io/guidelines/>`__. |
| 222 |
Furthermore, check out `GUIDANCE.md <https://github.com/Azure/azure-data-lake-store-python/blob/master/GUIDANCE.md>`__ |
| 223 |
for specific information related to this project. |
| 224 |
|
| 225 |
If you encounter any bugs with the library please file an issue in the |
| 226 |
`Issues <https://github.com/Azure/azure-data-lake-store-python/issues>`__ |
| 227 |
section of the project. |
| 228 |
|
| 229 |
|
| 230 |
Code of Conduct |
| 231 |
=============== |
| 232 |
This project has adopted the `Microsoft Open Source Code of Conduct <https://opensource.microsoft.com/codeofconduct/>`__. |
| 233 |
For more information see the `Code of Conduct FAQ <https://opensource.microsoft.com/codeofconduct/faq/>`__ or contact |
| 234 |
`[email protected] <mailto:[email protected]>`__ with any additional questions or comments. |