This is python implementation for for interacting with s3, with familier syntax
Project description
libs3
The purpose of this repo is to provide an easy to use interface to s3 for python developers, the core python libraries like os, shutil are easy to use and more familier to any python programmer.
The repo aims to mimic the functionality so that your code will interact with s3 in same way as it is interacting in linux or windows filesystem, with 1 or 2 line change
Installation
pip install libs3
Documentation
A list of functions have been exposed which are working as of now and more will be added later (contributions are welcome)
os
Function | Availaible | Comments |
---|---|---|
os.listdir(x) |
yes | As s3 has no notion of directories, in order to list directories along with files we have to traverse entire bucket and filter the results. For more quick results you can use os.listdir(x, filesonly=True) is much fast but will only returns files and not directory |
os.mkdir(x) |
yes | |
os.makedirs(x) |
yes | |
os.remove(x) |
yes | |
os.removedirs(x) |
no | will be added in later releases |
os.rmdir(x) |
no | will be added in later releases |
os.rename(x) |
no | will be added in later releases |
os.renames(x) |
no | will be added in later releases |
os.replace(x) |
no | will be added in later releases |
os.scandir(x) |
no | will be added in later releases |
os.walk(x) |
no | will be added in later releases |
os.path
Function | Availaible | Comments |
---|---|---|
os.path.basename(x) |
yes | |
os.path.commonpath(x) |
no | will be added in later releases |
os.path.commonprefix(x) |
no | will be added in later releases |
os.path.dirname(x) |
yes | |
os.path.exists(x) |
yes | |
os.path.isfile(x) |
yes | |
os.path.isdir(x) |
yes | |
os.path.join(x) |
no | will be added in later releases |
shutil
Function | Availaible | Comments |
---|---|---|
shutil.copyfile() |
yes | copy file(local/s3) to file(local/s3) |
shutil.copy() |
yes | copy file(local/s3) to file/folder(local/s3) |
shutil.copytree() |
no | will be added in later releases |
shutil.rmtree() |
yes | |
shutil.move() |
yes | copy file(local/s3) to file/folder(local/s3) |
shutil.disk_usage() |
no | will be added in later releases |
Example
os - importing the module and authorizing using s3 credentials
from libs3 import os
os.authorize(bucket, aws_access_key_id, aws_secret_access_key)
After authorizing access the interface like normally accessing filesystem
print(os.listdir("/dir_1/dir_1"))
print(os.listdir("/dir_1/dir_1", filesonly=True)) # Much quicker
print(os.path.exists('/dir_1/file_2'))
print(os.path.isfile('/dir_1/file_2'))
print(os.path.isdir('/dir_1/file_2'))
print(os.path.basename('/dir_1/file_2'))
print(os.path.dirname('/dir_1/file_2'))
os.remove('/dir_2/file_ks')
shutil - importing the module and authorizing using s3 credentials
from libs3 import shutil
shutil.authorize(bucket, aws_access_key_id, aws_secret_access_key)
After authorizing access the interface like normally accessing filesystem
# Copying file
shutil.copy("/dir_2/file_1", "/dir_2/file_1_cp") # Copy within s3
shutil.copy("/dir_2/file_1", "localfile", download=True) # Copy from s3 to local
shutil.copy("localfile", "/dir_2/filename", upload=True) # Copy from local to s3
shutil.copyfile("/dir_2/file_1", "/dir_2/file_ks") # Copy within s3
# Removing
shutil.rmtree('/dir_2/cold')
# Moving
shutil.move('/dir_2/file_1_cp', '/dir_2/file_1_moved')
shutil.move('file_1_cp', '/dir_2/file_1_moved', upload=True) # Moving file from local to s3
Project details
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
File details
Details for the file libs3-1.2.tar.gz
.
File metadata
- Download URL: libs3-1.2.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0bb9898ec45b3b6f87714bcddc7356b70a04aad1c83f0eb7b3e781d0ecf74e2 |
|
MD5 | d8088c73e7fc80ce5754a2a2f0b2aff1 |
|
BLAKE2b-256 | 802dae641f307ec7d08a98c45707bd6a7f4d8c625bbb4ed57d619544f0a00eb2 |
File details
Details for the file libs3-1.2-py3-none-any.whl
.
File metadata
- Download URL: libs3-1.2-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c31c342f431b0b3de1de443190020c5f95d41b9084e9ecaf9f251f1c6f3420e2 |
|
MD5 | 99e41ffbfd1320a9c36d6066b8d39de0 |
|
BLAKE2b-256 | c5e29a72f31ee7932ebe6bdf0ec8e34c143921cbb12c4dd94fbabac68572e4ad |