Python SDK for Buckerio - S3-compatible object storage
Project description
Buckerio Python SDK
A Python SDK for Buckerio - S3-compatible object storage server.
Installation
pip install buckerio
Or install from source:
git clone https://github.com/KamoliddinS/buckerio.git
cd buckerio/buckerio-py
pip install -e .
Quick Start
from buckerio import Buckerio
# Initialize client
client = Buckerio(
endpoint="http://localhost:9000",
access_key="admin",
secret_key="admin",
)
# Create a bucket
client.create_bucket("my-bucket")
# Upload an object
client.put_object("my-bucket", "hello.txt", b"Hello, World!")
# Download an object
result = client.get_object("my-bucket", "hello.txt")
print(result.content) # b"Hello, World!"
# List objects
for obj in client.list_all_objects("my-bucket"):
print(f"{obj.key}: {obj.size} bytes")
# Delete an object
client.delete_object("my-bucket", "hello.txt")
# Delete the bucket
client.delete_bucket("my-bucket")
Configuration
Environment Variables
| Variable | Default | Description |
|---|---|---|
BUCKERIO_ACCESS_KEY |
admin |
Access key for authentication |
BUCKERIO_SECRET_KEY |
admin |
Secret key for authentication |
BUCKERIO_ENDPOINT |
- | S3 endpoint URL (for tests) |
Client Options
client = Buckerio(
endpoint="http://localhost:9000", # S3 endpoint URL
access_key="admin", # Access key (or env var)
secret_key="admin", # Secret key (or env var)
region="us-east-1", # AWS region for signing
timeout=30.0, # Request timeout in seconds
verify_ssl=True, # Verify SSL certificates
)
API Reference
Bucket Operations
# List all buckets
buckets = client.list_buckets()
for bucket in buckets:
print(bucket.name, bucket.creation_date)
# Create a bucket
client.create_bucket("new-bucket")
# Check if bucket exists
if client.bucket_exists("my-bucket"):
print("Bucket exists!")
# Delete a bucket (must be empty)
client.delete_bucket("my-bucket")
Object Operations
# Upload object from bytes/string
result = client.put_object("bucket", "key", b"content")
print(result.etag)
# Upload with content type and metadata
result = client.put_object(
"bucket",
"document.json",
'{"key": "value"}',
content_type="application/json",
metadata={"author": "alice", "version": "1.0"},
)
# Download object
result = client.get_object("bucket", "key")
print(result.content) # bytes
print(result.etag) # ETag hash
print(result.content_type) # MIME type
print(result.metadata) # Custom metadata
# Get object metadata (without content)
info = client.head_object("bucket", "key")
print(info.size, info.content_type)
# Check if object exists
if client.object_exists("bucket", "key"):
print("Object exists!")
# Delete object
client.delete_object("bucket", "key")
# Copy object
client.copy_object(
source_bucket="bucket1",
source_key="original.txt",
dest_bucket="bucket2",
dest_key="copy.txt",
)
File Operations
# Upload from file path
client.upload_file("bucket", "remote-key.txt", "/local/path/file.txt")
# Upload from file object
with open("file.txt", "rb") as f:
client.upload_fileobj("bucket", "key", f)
# Download to file path
client.download_file("bucket", "key", "/local/path/output.txt")
# Download to file object
with open("output.txt", "wb") as f:
client.download_fileobj("bucket", "key", f)
Listing Objects
# List objects (single page)
result = client.list_objects("bucket", prefix="data/", max_keys=100)
for obj in result.objects:
print(obj.key, obj.size)
# Handle pagination
if result.is_truncated:
next_result = client.list_objects(
"bucket",
continuation_token=result.next_continuation_token,
)
# Iterate all objects (handles pagination automatically)
for obj in client.list_all_objects("bucket", prefix="logs/"):
print(obj.key)
# List with delimiter (folder-like structure)
result = client.list_objects("bucket", delimiter="/")
for prefix in result.common_prefixes:
print(f"Folder: {prefix}")
Presigned URLs
# Generate download URL (valid for 1 hour)
result = client.presign_get("bucket", "key", expires_in=3600)
print(result.url)
# Generate upload URL
result = client.presign_put("bucket", "key", expires_in=3600)
print(result.url)
# Use with any HTTP client
import requests
response = requests.get(result.url)
Error Handling
from buckerio import (
BuckerioError,
BucketNotFoundError,
BucketAlreadyExistsError,
BucketNotEmptyError,
ObjectNotFoundError,
AccessDeniedError,
InvalidCredentialsError,
ConnectionError,
)
try:
client.get_object("bucket", "nonexistent-key")
except ObjectNotFoundError as e:
print(f"Object not found: {e.key}")
except BucketNotFoundError as e:
print(f"Bucket not found: {e.bucket}")
except AccessDeniedError:
print("Access denied!")
except ConnectionError as e:
print(f"Connection failed: {e}")
except BuckerioError as e:
print(f"Error: {e.code} - {e.message}")
Context Manager
# Client is automatically closed
with Buckerio() as client:
client.put_object("bucket", "key", b"content")
Development
Install Development Dependencies
pip install -e ".[dev]"
Run Tests
# Unit tests only
pytest tests/test_auth.py tests/test_client.py
# Integration tests (requires running Buckerio server)
pytest tests/ -m integration
Code Quality
# Linting
ruff check src/
# Type checking
mypy src/
Publishing to PyPI
# Install build tools
pip install build twine
# Build the package
python -m build
# Check the distribution
twine check dist/*
# Upload to TestPyPI (for testing)
twine upload --repository testpypi dist/*
# Upload to PyPI (production)
twine upload dist/*
Prerequisites:
- Create account on PyPI
- Create API token at https://pypi.org/manage/account/token/
- Configure
~/.pypirc:[pypi] username = __token__ password = pypi-your-api-token-here
Version bump:
# Update version in src/buckerio/__version__.py
echo '__version__ = "0.2.0"' > src/buckerio/__version__.py
# Commit and tag
git add -A
git commit -m "chore: bump version to 0.2.0"
git tag v0.2.0
git push && git push --tags
License
MIT - See LICENSE for details.
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
buckerio-0.2.0.tar.gz
(22.3 kB
view details)
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
buckerio-0.2.0-py3-none-any.whl
(19.0 kB
view details)
File details
Details for the file buckerio-0.2.0.tar.gz.
File metadata
- Download URL: buckerio-0.2.0.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba1f17c44704378b873239db2bfd2acef43dbdcc3a28751f98dbc2e705ce7137
|
|
| MD5 |
442073c8cb5ec95672780f1f6168a884
|
|
| BLAKE2b-256 |
c3e0f326e820ee284dbc1e479ab2c13be83abf42798be2046fb0d4813dc6fd46
|
File details
Details for the file buckerio-0.2.0-py3-none-any.whl.
File metadata
- Download URL: buckerio-0.2.0-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b45dbdc48cad2b4a2c35b552c0cac91a9405403fda69821ae74452462c4b3f5
|
|
| MD5 |
46da1cb18102eae131b888a074836c0e
|
|
| BLAKE2b-256 |
cbb50e65dd5b85ea513131e864240101ec0241519f71506146edfc98edd83606
|