Skip to main content

Docs Status PyPI conda-forge tests codecov

Our goal is to be the meringue of file management libraries: the subtle sweetness of pathlib working in harmony with the ethereal lightness of the cloud.

A Python library with classes that mimic pathlib.Path's interface for URIs from different cloud storage services.

with CloudPath("s3://bucket/filename.txt").open("w+") as f:
    f.write("Send my changes to the cloud!")

Why use cloudpathlib?

  • Familiar: If you know how to interact with Path, you know how to interact with CloudPath. All of the cloud-relevant Path methods are implemented.
  • Supported clouds: AWS S3, Google Cloud Storage, and Azure Blob Storage are implemented. FTP is on the way.
  • Extensible: The base classes do most of the work generically, so implementing two small classes MyPath and MyClient is all you need to add support for a new cloud storage service.
  • Read/write support: Reading just works. Using the write_text, write_bytes or .open('w') methods will all upload your changes to cloud storage without any additional file management as a developer.
  • Seamless caching: Files are downloaded locally only when necessary. You can also easily pass a persistent cache folder so that across processes and sessions you only re-download what is necessary.
  • Tested: Comprehensive test suite and code coverage.
  • Testability: Local filesystem implementations that can be used to easily mock cloud storage in your unit tests.

Installation

cloudpathlib depends on the cloud services' SDKs (e.g., boto3, google-cloud-storage, azure-storage-blob) to communicate with their respective storage service. If you try to use cloud paths for a cloud service for which you don't have dependencies installed, cloudpathlib will error and let you know what you need to install.

To install a cloud service's SDK dependency when installing cloudpathlib, you need to specify it using pip's "extras" specification. For example:

pip install cloudpathlib[s3,gs,azure]

Currently supported cloud storage services are: azure, gs, s3. You can also use all to install all available services' dependencies.

If you do not specify any extras or separately install any cloud SDKs, you will only be able to develop with the base classes for rolling your own cloud path class.

conda

cloudpathlib is also available using conda from conda-forge. Note that to install the necessary cloud service SDK dependency, you should include the appropriate suffix in the package name. For example:

conda install cloudpathlib-s3 -c conda-forge

If no suffix is used, only the base classes will be usable. See the conda-forge/cloudpathlib-feedstock for all installation options.

Development version

You can get latest development version from GitHub:

pip install https://github.com/drivendataorg/cloudpathlib.git#egg=cloudpathlib[all]

Note that you similarly need to specify cloud service dependencies, such as all in the above example command.

Quick usage

Here's an example to get the gist of using the package. By default, cloudpathlib authenticates with the environment variables supported by each respective cloud service SDK. For more details and advanced authentication options, see the "Authentication" documentation.

from cloudpathlib import CloudPath

# dispatches to S3Path based on prefix
root_dir = CloudPath("s3://drivendata-public-assets/")
root_dir
#> S3Path('s3://drivendata-public-assets/')

# there's only one file, but globbing works in nested folder
for f in root_dir.glob('**/*.txt'):
    text_data = f.read_text()
    print(f)
    print(text_data)
#> s3://drivendata-public-assets/odsc-west-2019/DATA_DICTIONARY.txt
#> Eviction Lab Data Dictionary
#>
#> Additional information in our FAQ evictionlab.org/help-faq/
#> Full methodology evictionlab.org/methods/
#>
#> ... (additional text output truncated)

# use / to join paths (and, in this case, create a new file)
new_file_copy = root_dir / "nested_dir/copy_file.txt"
new_file_copy
#> S3Path('s3://drivendata-public-assets/nested_dir/copy_file.txt')

# show things work and the file does not exist yet
new_file_copy.exists()
#> False

# writing text data to the new file in the cloud
new_file_copy.write_text(text_data)
#> 6933

# file now listed
list(root_dir.glob('**/*.txt'))
#> [S3Path('s3://drivendata-public-assets/nested_dir/copy_file.txt'),
#>  S3Path('s3://drivendata-public-assets/odsc-west-2019/DATA_DICTIONARY.txt')]

# but, we can remove it
new_file_copy.unlink()

# no longer there
list(root_dir.glob('**/*.txt'))
#> [S3Path('s3://drivendata-public-assets/odsc-west-2019/DATA_DICTIONARY.txt')]

Supported methods and properties

Most methods and properties from pathlib.Path are supported except for the ones that don't make sense in a cloud context. There are a few additional methods or properties that relate to specific cloud services or specifically for cloud paths.

Methods + properties AzureBlobPath S3Path GSPath
anchor ✅ ✅ ✅
as_uri ✅ ✅ ✅
drive ✅ ✅ ✅
exists ✅ ✅ ✅
glob ✅ ✅ ✅
is_dir ✅ ✅ ✅
is_file ✅ ✅ ✅
iterdir ✅ ✅ ✅
joinpath ✅ ✅ ✅
match ✅ ✅ ✅
mkdir ✅ ✅ ✅
name ✅ ✅ ✅
open ✅ ✅ ✅
parent ✅ ✅ ✅
parents ✅ ✅ ✅
parts ✅ ✅ ✅
read_bytes ✅ ✅ ✅
read_text ✅ ✅ ✅
rename ✅ ✅ ✅
replace ✅ ✅ ✅
rglob ✅ ✅ ✅
rmdir ✅ ✅ ✅
samefile ✅ ✅ ✅
stat ✅ ✅ ✅
stem ✅ ✅ ✅
suffix ✅ ✅ ✅
suffixes ✅ ✅ ✅
touch ✅ ✅ ✅
unlink ✅ ✅ ✅
with_name ✅ ✅ ✅
with_suffix ✅ ✅ ✅
write_bytes ✅ ✅ ✅
write_text ✅ ✅ ✅
absolute ❌ ❌ ❌
as_posix ❌ ❌ ❌
chmod ❌ ❌ ❌
cwd ❌ ❌ ❌
expanduser ❌ ❌ ❌
group ❌ ❌ ❌
home ❌ ❌ ❌
is_absolute ❌ ❌ ❌
is_block_device ❌ ❌ ❌
is_char_device ❌ ❌ ❌
is_fifo ❌ ❌ ❌
is_mount ❌ ❌ ❌
is_relative_to ❌ ❌ ❌
is_reserved ❌ ❌ ❌
is_socket ❌ ❌ ❌
is_symlink ❌ ❌ ❌
lchmod ❌ ❌ ❌
link_to ❌ ❌ ❌
lstat ❌ ❌ ❌
owner ❌ ❌ ❌
readlink ❌ ❌ ❌
relative_to ❌ ❌ ❌
resolve ❌ ❌ ❌
root ❌ ❌ ❌
symlink_to ❌ ❌ ❌
with_stem ❌ ❌ ❌
cloud_prefix ✅ ✅ ✅
copy ✅ ✅ ✅
copytree ✅ ✅ ✅
download_to ✅ ✅ ✅
etag ✅ ✅ ✅
fspath ✅ ✅ ✅
is_valid_cloudpath ✅ ✅ ✅
rmtree ✅ ✅ ✅
upload_from ✅ ✅ ✅
blob ✅ ❌ ✅
bucket ❌ ✅ ✅
container ✅ ❌ ❌
key ❌ ✅ ❌
md5 ✅ ❌ ❌

Icon made by srip from www.flaticon.com.
Sample code block generated using the reprexpy package.

Metadata

Release files for cloudpathlib 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cloudpathlib 0.5.0
File Size Uploaded
cloudpathlib-0.5.0.tar.gz 40.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cloudpathlib 0.5.0
File Interpreter ABI Platform
cloudpathlib-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 89.7 kB

Release files / cloudpathlib-0.5.0.tar.gz

Download URL cloudpathlib-0.5.0.tar.gz
Size 40.9 kB
Tags Source
SHA-256 checksum
How to use checksums
04af66bf7fe11c2c37422fa9e00e45ec0d615e27ef58637a0b75a7bd336739c2
BLAKE2b-256 checksum
How to use checksums
0ee8fdefcc17d5c03845d632fb6b2269e80e695f7c41c61e0e7207f258bb4476
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.12

Release files / cloudpathlib-0.5.0-py3-none-any.whl

Download URL cloudpathlib-0.5.0-py3-none-any.whl
Size 48.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
083e3c37a640a72f210fb63f72d43bd0531bfcf0037a5d6e44ce89d535cdfe81
BLAKE2b-256 checksum
How to use checksums
b9768093ed7131e1f53cecd30a9a53585035e3abb0810ddcf005f985b3db4212
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.12

Release history Release notifications | RSS feed

0.25.0

2 release files

0.24.0

2 release files

0.22.0

2 release files

0.21.1

2 release files

0.20.0

2 release files

0.19.0

2 release files

0.18.1

2 release files

0.18.0

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

This release

0.5.0 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page