A lightweight framework to manage your R2 bucket.
Project description
R2Client
R2Client
is a Python client library for interacting with Cloudflare R2 storage, facilitating easy and quick HTTP requests to manage files within an R2 bucket. This framework leverages Python's native packages to sign and send requests, making it straightforward to integrate into existing Python projects.
Features
- File upload and download
- Listing files and folders within a bucket
Installation
To install r2client
, simply use pip:
pip install r2client
Quick Start
Here's how to get started with r2client
:
Setting Up
First, import R2Client
and initialize it with your credentials:
from r2client import R2Client
# Initialize the R2Client
client = R2Client(
access_key='<ACCESS_KEY>',
secret_key='<SECRET_KEY>',
endpoint='<ENDPOINT> (example: "https://***.r2.cloudflarestorage.com")'
)
Uploading a File
To upload a file to your R2 bucket:
bucket_name = 'your-bucket-name'
local_file_path = 'path/to/your/local/file'
r2_file_key = 'desired/path/in/bucket'
client.upload_file(bucket_name, local_file_path, r2_file_key)
Downloading a File
To download a file from your R2 bucket:
file_key = 'path/to/the/file/in/bucket'
local_file_name = 'path/to/save/the/downloaded/file'
client.download_file(bucket_name, file_key, local_file_name)
Listing Files
To list files in a specific bucket:
files_dict = client.list_files(bucket_name)
print(files_dict)
Listing Folders
To list folders within a bucket:
folders = client.list_folders(bucket_name)
print(folders)
Contributing
Contributions are welcome! Please feel free to submit a pull request or create an issue for any bugs or feature requests.
License
This project is licensed under the MIT License - see the LICENSE file 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
Built Distribution
File details
Details for the file r2client-0.2.1.tar.gz
.
File metadata
- Download URL: r2client-0.2.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83d1ea4ccd58e792b74b8f19a24ad619ea209f23e6ff2faa0ca2e8bf3f845b88 |
|
MD5 | 7e41adbe931edc0de04b376a10c28c04 |
|
BLAKE2b-256 | 8916b7ff768e04d431ec7bf57d386610462ff052e534d1f553eb5557161e6ec4 |
File details
Details for the file r2client-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: r2client-0.2.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91a1af0563937c03882428466cf35519f15f7d896b0db270edd96bf3b1ea7960 |
|
MD5 | a629f3a70ddbe8e63bebcf34fc192a89 |
|
BLAKE2b-256 | 4db51db15945e4b2974e420cc36c237936257c79e4fff53f9fb5285885e17f4c |