Skip to main content

Official Python SDK for the Reupload public API

Project description

reupload-sdk

Official server-side Python SDK for the Reupload public API.

  • Typed API aligned with @reupload/sdk (Node.js)
  • Sync (Reupload) and async (AsyncReupload) clients via httpx
  • CDN upload flow (session → PUT → complete) and server direct multipart upload
  • Optional FastAPI route helpers

Install

pip install reupload-sdk

# FastAPI helpers
pip install "reupload-sdk[fastapi]"

Requires Python 3.10+.

Quick start

from reupload import create_reupload_from_env

client = create_reupload_from_env()
me = client.whoami()
print(me["projects"])

Environment variables

Variable Required Description
REUPLOAD_API_KEY Yes API key (ru_…)
REUPLOAD_PROJECT_ID Yes Default project UUID
REUPLOAD_API_BASE_URL No Default https://api.reupload.dev/api/v1

Manual client

from reupload import Reupload

client = Reupload(
    api_key="ru_…",
    default_project_id="your-project-uuid",
)

API overview

Method Description
client.whoami() Verify key and list projects
client.uploads.create_session() Start CDN upload session
put_to_upload_url(url, body, content_type) PUT bytes to signed CDN URL
client.uploads.complete() Finalize CDN upload
client.uploads.upload() Session + CDN PUT + complete
client.uploads.upload_direct() Server multipart direct upload
client.uploads.upload_direct_batch() Multiple files in one request
client.uploads.get_session() Poll session status
client.uploads.wait_for_completion() Poll until COMPLETED
client.files.get() File metadata
client.files.access() Signed download URL
client.files.delete() Delete file

Use AsyncReupload and await for the same methods in async code.

CDN upload

from pathlib import Path

from reupload import Reupload, put_to_upload_url

client = Reupload(api_key="ru_…", default_project_id="…")
payload = Path("photo.jpg").read_bytes()

session = client.uploads.create_session(
    {
        "projectId": client.default_project_id,
        "filename": "photo.jpg",
        "contentType": "image/jpeg",
        "size": len(payload),
        "isPublic": True,
    },
)

put_to_upload_url(session["uploadUrl"], payload, "image/jpeg")
done = client.uploads.complete({"uploadId": session["uploadId"]})
print(done["fileId"])

Or the combined helper:

done = client.uploads.upload(
    {
        "projectId": client.default_project_id,
        "filename": "photo.jpg",
        "contentType": "image/jpeg",
        "size": len(payload),
        "file": {
            "data": payload,
            "filename": "photo.jpg",
            "contentType": "image/jpeg",
            "size": len(payload),
        },
    },
)

Direct upload

result = client.uploads.upload_direct(
    {
        "projectId": client.default_project_id,
        "isPublic": True,
        "file": {
            "data": payload,
            "filename": "photo.jpg",
            "contentType": "image/jpeg",
            "size": len(payload),
        },
    },
)

FastAPI

from fastapi import FastAPI
from reupload import create_async_reupload_from_env
from reupload.fastapi import create_async_fastapi_direct_upload_handler

app = FastAPI()
client = create_async_reupload_from_env()

@app.post("/api/upload")
async def upload(request):
    return await create_async_fastapi_direct_upload_handler(client=client)(request)

Or build the handler once:

upload_handler = create_async_fastapi_direct_upload_handler(client=client)

@app.post("/api/upload")
async def upload(request):
    return await upload_handler(request)

Accepts multipart fields: projectId, file, optional filename, optional isPublic.

Errors

from reupload import ReuploadError, is_reupload_error, is_reupload_cdn_error

try:
    client.files.get("…")
except ReuploadError as error:
    print(error.status, error.code, error.message)

Development

cd python-packages/reupload-sdk
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest
python -m build

License

MIT

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

reupload_sdk-0.1.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

reupload_sdk-0.1.1-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file reupload_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: reupload_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for reupload_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 71c230edcc9a625b9d42ef5e6b52c796ee8e05a49cef1641aeef77db8c5a19c0
MD5 96a104ae9cdfa65a04a22d19397241a5
BLAKE2b-256 3237ad54af7482a13bf48183a5654a4dcfa4ecf659bc74cd25b7fa460af6af8b

See more details on using hashes here.

File details

Details for the file reupload_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: reupload_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for reupload_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6c07adc403baee83a5d0f30c7fdf3528a05dcb8db0eee28a71948627e14f7ecd
MD5 2836cb0283b681ab59caa8aec19d2f4a
BLAKE2b-256 ca9d6de2fc92b0455c5f846d8f7df6a04ee61a186d4eb7ede75216701f55f16b

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