Skip to main content

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

Metadata

Release files for libs3 1.2

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

Source distribution (sdist)

Source distribution for libs3 1.2
File Size Uploaded
libs3-1.2.tar.gz 4.7 kB Details

Built distribution (wheel)

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

Total release size: 10.3 kB

Release files / libs3-1.2.tar.gz

Download URL libs3-1.2.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d0bb9898ec45b3b6f87714bcddc7356b70a04aad1c83f0eb7b3e781d0ecf74e2
BLAKE2b-256 checksum
How to use checksums
802dae641f307ec7d08a98c45707bd6a7f4d8c625bbb4ed57d619544f0a00eb2
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / libs3-1.2-py3-none-any.whl

Download URL libs3-1.2-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c31c342f431b0b3de1de443190020c5f95d41b9084e9ecaf9f251f1c6f3420e2
BLAKE2b-256 checksum
How to use checksums
c5e29a72f31ee7932ebe6bdf0ec8e34c143921cbb12c4dd94fbabac68572e4ad
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.2 This release

2 release files

1.1

2 release files

1.0

2 release files

0.1

2 release files

0.0.2

2 release files

0.0.1

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