Skip to main content

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.R2Client import R2Client as r2

# Initialize the R2Client
client = r2(
    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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

r2client-0.3.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

r2client-0.3.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file r2client-0.3.1.tar.gz.

File metadata

  • Download URL: r2client-0.3.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for r2client-0.3.1.tar.gz
Algorithm Hash digest
SHA256 070dc73cf2dbbcc20900cdaab99c623973e256413c46290cb1e1b313eff652bd
MD5 b560f8313bab592abb4d2176ab174723
BLAKE2b-256 c6518c8794fa3475ee84f306323f0a5de53888db29c664b6dcdbf703bae076e0

See more details on using hashes here.

File details

Details for the file r2client-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: r2client-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for r2client-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 52f4802e18b26b7692ddc4f23cd6095b4031e55fc93d11160ffcb371ccc8fb83
MD5 b3804c7dc5af6e145ceab26544353251
BLAKE2b-256 a6439a6d657d72dae59ed57359a23c3d157c05b0cf2e1072c19acba8bff56a4e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page