handtruck
The simple module for putting and getting object from Amazon S3 compatible endpoints.
Installation
pip install handtruck
Usage
from http import HTTPStatus
from httpx import AsyncClient
from handtruck import S3Client
client = S3Client(
url="http://s3-url",
client=AsyncClient(),
access_key_id="key-id",
secret_access_key="hackme",
region="us-east-1"
)
# Upload str object to bucket "bucket" and key "str"
resp = await client.put("bucket/str", "hello, world")
assert resp.status_code == HTTPStatus.OK
# Upload bytes object to bucket "bucket" and key "bytes"
resp = await client.put("bucket/bytes", b"hello, world")
assert resp.status_code == HTTPStatus.OK
# Upload AsyncIterable to bucket "bucket" and key "iterable"
async def gen():
yield b'some bytes'
resp = await client.put("bucket/file", gen())
assert resp.status_code == HTTPStatus.OK
# Upload file to bucket "bucket" and key "file"
resp = await client.put_file("bucket/file", "/path_to_file" )
assert resp.status_code == HTTPStatus.OK
# Check object exists using bucket+key
resp = await client.head("bucket/key")
assert resp.status_code == HTTPStatus.OK
# Get object by bucket+key
resp = await client.get("bucket/key")
data = resp.content
# Delete object using bucket+key
resp = await client.delete("bucket/key")
assert resp == HTTPStatus.NO_CONTENT
# List objects by prefix
async for result in client.list_objects_v2("bucket/", prefix="prefix"):
# Each result is a list of metadata objects representing an object
# stored in the bucket.
do_work(result)
Bucket may be specified as subdomain or in object name:
import httpx
from handtruck import S3Client
client = S3Client(url="http://bucket.your-s3-host",
client=httpx.AsyncClient())
resp = await client.put("key", gen())
...
client = S3Client(url="http://your-s3-host",
client=httpx.AsyncClient())
resp = await client.put("bucket/key", gen())
...
client = S3Client(url="http://your-s3-host/bucket",
client=httpx.AsyncClient())
resp = await client.put("key", gen())
...
Auth may be specified with keywords or in URL:
import httpx
from handtruck import S3Client
client_credentials_as_kw = S3Client(
url="http://your-s3-host",
access_key_id="key_id",
secret_access_key="access_key",
client=httpx.AsyncClient(),
)
client_credentials_in_url = S3Client(
url="http://key_id:access_key@your-s3-host",
client=httpx.AsyncClient(),
)
Credentials
By default S3Client trying to collect all available credentials from keyword
arguments like access_key_id= and secret_access_key=, after that from the
username and password from passed url argument, so the nex step is environment
variables parsing and the last source for collection is the config file.
You can pass credentials explicitly using the handtruck.credentials module.
Parallel Transfer
Parallel transfer is fully supported, either with multipart uploading or the Range header.
import httpx
from handtruck import S3Client
client = S3Client(url="http://your-s3-host", client=httpx.AsyncClient())
await client.put_file_multipart(
"test/bigfile.csv",
headers={
"Content-Type": "text/csv",
},
workers_count=8,
)
await client.get_file_parallel(
"dump/bigfile.csv",
"/home/user/bigfile.csv",
workers_count=8,
)
Metadata
Release files for handtruck 0.3.2
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 |
|---|---|---|---|---|
| handtruck-0.3.2.tar.gz | 24.4 kB | Without provenance | Details for handtruck-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| handtruck-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for handtruck-0.3.2-py3-none-any.whl |
Total release size: 53.7 kB
Release files / handtruck-0.3.2.tar.gz
| Download URL | handtruck-0.3.2.tar.gz |
|---|---|
| Size | 24.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30b1e658ce0e227974ed6dcec5668ff78ca6bd1cf01e309c770b860348773cbd
|
|
BLAKE2b-256 checksum How to use checksums |
730ade180429366ff72fadd28e43ffee7f80f4b0fc516452dbd0c99b2028b931
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.12.3 Linux/6.12.85+deb13-amd64
|
Release files / handtruck-0.3.2-py3-none-any.whl
| Download URL | handtruck-0.3.2-py3-none-any.whl |
|---|---|
| Size | 29.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d692b4098e897a9ca56216ec41bcb18b7368eb71065a912b52f4509c6df3155
|
|
BLAKE2b-256 checksum How to use checksums |
745fdf36b57a21f29396bae8c2158480f92fed9c626c6d3190e105229d00d101
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.12.3 Linux/6.12.85+deb13-amd64
|
Security for handtruck 0.3.2
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.