AzCopy Python Wrapper
This package allows you to invoke AzCopy v10 from python.
Its design has been inspired by the NodeJS version of Azcopy Wrapper which can be found here NodeJS Azcopy
Requirements
- Azcopy
- For Linux installation,(recommended with admin privileges) you can run
# Download AzCopy
wget https://aka.ms/downloadazcopy-v10-linux
# Expand Archive
tar -xvf downloadazcopy-v10-linux
# Move AzCopy to the destination you want to store it
sudo cp ./azcopy_linux_amd64_*/azcopy /usr/bin/
# Change permissions of Azcopy
sudo chmod 777 /usr/bin/azcopy
- For windows installation, you can run
# Download and extract
Invoke-WebRequest -Uri "https://aka.ms/downloadazcopy-v10-windows" -OutFile AzCopy.zip -UseBasicParsing
Expand-Archive ./AzCopy.zip ./AzCopy -Force
# Move AzCopy
mkdir ~\AppData\Local\Programs\AZCopy
Get-ChildItem ./AzCopy/*/azcopy.exe | Move-Item -Destination ~\AppData\Local\Programs\AZCopy\
# Add AzCopy to PATH
$userenv = (Get-ItemProperty -Path 'HKCU:\Environment' -Name Path).path
$newPath = "$userenv;%USERPROFILE%\AppData\Local\Programs\AZCopy;"
New-ItemProperty -Path 'HKCU:\Environment' -Name Path -Value $newPath -Force
# Clean the kitchen
del -Force AzCopy.zip
del -Force -Recurse .\AzCopy\
Please ensure that the path to the AzCopy executable file is specified in the System variables for the AzClient to work properly. Otherwise, you will have to specify the path to the executable file while iniating the AzClient. Refer the examples and common issues portion to know more about this.
- For detailed installation steps, you can refer the following links
- AzCopy official Documentation
- AzCopy Installation Scripts Option 1
- AzCopy Installation Scripts Option 2
Basic Usage
NOTE: If you want to specify the AzCopy binary/executable to be used according to the OS, you can do it while initiating the AzClient object.
For Linux based systems (Please ensure the file specified here has the required permissions)
az_client = AzClient(exe_to_use="/usr/bin/azcopy")
For Windows
az_client = AzClient(exe_to_use="C:\\Users\\DELL\\AppData\\Local\\Programs\\AZCopy\\azcopy.exe")
1. Upload Directory to Remote Location
from azcopy_wrapper.azcopy_client import AzClient
from azcopy_wrapper.azcopy_utilities import (
AzRemoteSASLocation,
AzLocalLocation,
AzCopyOptions,
AzSyncOptions,
)
local_location = AzLocalLocation(
path="./test_data/",
use_wildcard=True,
)
remote_location = AzRemoteSASLocation(
storage_account=storage_account,
container=container,
path="test4",
sas_token=sas_token,
)
transfer_options = AzCopyOptions(
overwrite_existing=True,
recursive=True,
exclude_path=f"test2.jpg;test_data_4;test_data_3/test3.jpg",
)
az_client = AzClient()
job_info = az_client.upload_data_to_remote_location(
src=local_location, dest=remote_location, transfer_options=transfer_options
)
print(job_info.__dict__)
2. Download a remote file to local path
remote_location = AzRemoteSASLocation(
storage_account=storage_account,
container=container,
path="test1.jpg",
sas_token=sas_token,
)
local_location = AzLocalLocation(
path="./test_data/test4.jpg",
)
transfer_options = AzCopyOptions(
overwrite_existing=True,
)
az_client = AzClient()
job_info = az_client.download_data_to_local_location(
src=remote_location, dest=local_location, transfer_options=transfer_options
)
print(job_info.__dict__)
3. Transfer files from one container to container
remote_location_src = AzRemoteSASLocation(
storage_account=storage_account1,
container=container1,
path="test1/",
sas_token=sas_token_cont1,
use_wildcard=True,
)
remote_location_dest = AzRemoteSASLocation(
storage_account=storage_account2,
container=container2,
path="test_dest5/",
sas_token=sas_token_cont2,
)
transfer_options = AzCopyOptions(
overwrite_existing=True,
recursive=True,
put_md5=True,
)
az_client = AzClient()
job_info = az_client.copy_remote_data_from_container_to_container(
src=remote_location_src, dest=remote_location_dest, transfer_options=transfer_options
)
print(job_info.__dict__)
4. Sync a local directory to remote location
src = AzLocalLocation(
path="./test_data/test_data3/",
)
dest = AzRemoteSASLocation(
storage_account=storage_account,
container=container,
path="test7/",
sas_token=sas_token,
)
transfer_options = AzSyncOptions(
recursive=True,
exclude_path="test_data_2;test_data_5"
)
az_client = AzClient()
job_info = az_client.sync_to_remote_location(
src=src, dest=dest, transfer_options=transfer_options
)
print(job_info.__dict__)
For more examples, you can refer AzCopy Wrapper Examples Notebook
Common Issues
- For Windows operating system, if there is an error "FileNotFoundError: [WinError 2] The system cannot find the file specified", please ensure that the path to AzCopy exectable file is set in System Environment Variables.
If the error persists even after setting the path, you can specify the path to the executable while creating the AzClient object.
az_client = AzClient(exe_to_use="C:\\Users\\DELL\\AppData\\Local\\Programs\\AZCopy\\azcopy.exe")
v1.0.0
- First version of this python azcopy wrapper!
- Validated against AzCopy 10.17.0.
- Copy and Sync commands
- Tested on Ubuntu 20.04 and Windows 10.
Metadata
Release files for azcopy-wrapper 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| azcopy_wrapper-1.0.0.tar.gz | 11.2 kB | Without provenance | Details for azcopy_wrapper-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| azcopy_wrapper-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for azcopy_wrapper-1.0.0-py3-none-any.whl |
Total release size: 22.5 kB
Release files / azcopy_wrapper-1.0.0.tar.gz
| Download URL | azcopy_wrapper-1.0.0.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a18bc0f1e48c05737e0c70f243cb4ff454c70530ef30a722785eb17137162272
|
|
BLAKE2b-256 checksum How to use checksums |
f6046569e9d17baade072ffb3a3a19b47276a3d073bd899edaa630e787ad9635
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Release files / azcopy_wrapper-1.0.0-py3-none-any.whl
| Download URL | azcopy_wrapper-1.0.0-py3-none-any.whl |
|---|---|
| Size | 11.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b0ba329c18ad12225318ee571c54babd0c39562bff40d20be7f6e567ad4a30b2
|
|
BLAKE2b-256 checksum How to use checksums |
479a60fd07dd12ddf098ea7cde97e222093bff3c246d14e925fe50486a9b6ff2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Security for azcopy-wrapper 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.