Smart dispatch between pathlib.Path and s3path.S3Path. It was borrowed from the project by EMTF: emtf@megvii.com
Project description
smart_path
Dispatch to pathlib.Path if a local file system path is given,
or s3path.S3Path if the given path is prefixed with
s3://
Example
Basic
from smart_path import smart_path
from pathlib import Path
from s3path import S3Path
# A local path on file system
path_local = smart_path("/tmp/t")
assert isinstance(path_local, Path)
# A s3 path on oss
path_brainpp_oss = smart_path("s3://public-datasets-contrib/", endpoint_url='s3.amazonaws.com')
assert isinstance(path_local, S3Path)
Stub Mode
from smart_path import smart_path
# Stub mode works like the symbolic link in Unix. The source path can be either
# on local file system or brain++ oss, so do the target path. Stub Mode is
# excepted to be helpful when we need to store a large file on oss and pretend
# it is on local file system.
#
# In stub mode, smart_path writes to two destinations:
# 1. The string "hello-world" is written to `s3://somewhere/on/oss`
# 2. The path "s3://somewhere/on/oss" is written to `corresponding/local/path`
path = smart_path('s3://somewhere/on/oss', stub='corresponding/local/path')
path.write_text('hello-world')
# smart_path knows it is a stub file
stub = smart_path('corresponding/local/path')
print(stub.read_text()) # prints "hello-world"
Installation
pip install -e git://github.com/wanzysky/smart_path.git#egg=smart_path
# Or from PyPI
pip install smart_path
Notice:
The entire project is borrowed from EMTF: EMTF-at-megvii-dot-com.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smart_path-1.0.1.tar.gz.
File metadata
- Download URL: smart_path-1.0.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fc9bad24254818423a1fb971a68a4ea108acbf15f7923fb13fdbbd1ff2cb424
|
|
| MD5 |
d8cabc999ea7f2112470479148da8871
|
|
| BLAKE2b-256 |
a9c5ca112626ca96cebe4ffecdd3c3133be714155f3a180559f9445ae2174d46
|
File details
Details for the file smart_path-1.0.1-py3-none-any.whl.
File metadata
- Download URL: smart_path-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4411cc5068f0cb035fc5a188adf645679447e4964a0557b1027314b5ec713889
|
|
| MD5 |
b291a23e8986ad1c887e03389fd0f4ee
|
|
| BLAKE2b-256 |
8a597cf87da19c503c04bb6d48779a36f131fa2846e030f81ddcd0ac0ab75b00
|