Skip to main content

Python client for the uploadthing API

Project description

Upyloadthing

Build Status PyPI version Python Versions

Python client for the uploadthing API - The easiest way to add file uploads to your Python application.

Installation

pip install upyloadthing

Quick Start

from upyloadthing import UTApi, UTApiOptions

# Initialize with token
api = UTApi(UTApiOptions(token="your-token"))

# Upload a file
with open("example.png", "rb") as f:
    result = api.upload_files(f)
    print(f"File uploaded: {result.url}")

Environment Variables

The SDK can be configured using environment variables:

  • UPLOADTHING_TOKEN - Your uploadthing API token (required if not passed to UTApiOptions)
  • UPLOADTHING_REGION - Preferred upload region (optional, defaults to first available region found in the decoded token)

Examples

Upload Multiple Files

files = [
    open("image1.jpg", "rb"),
    open("image2.jpg", "rb")
]
results = api.upload_files(files)
for result in results:
    print(f"Uploaded: {result.url}")

Delete Files

# Delete by file key
response = api.delete_files("file_key_123")

# Delete multiple files
response = api.delete_files(["key1", "key2"])

# Delete by custom ID
response = api.delete_files("custom_123", key_type="custom_id")

List Files

# Get first 10 files
files = api.list_files(limit=10)
for file in files.files:
    print(f"{file.name}: {file.url}")

# Pagination
files = api.list_files(limit=10, offset=10)

Check Usage

usage = api.get_usage_info()
print(f"Total storage used: {usage.total_bytes / 1024 / 1024:.2f} MB")
print(f"Files uploaded: {usage.files_uploaded}")

Error Handling

The SDK uses standard Python exceptions:

from requests.exceptions import HTTPError

try:
    api.upload_files(file)
except HTTPError as e:
    if e.response.status_code == 413:
        print("File too large")
    else:
        print(f"Upload failed: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")

API Reference

UTApi Methods

All methods are defined in upyloadthing/client.py:

  • upload_files(files) - Upload one or more files
  • delete_files(keys, key_type='file_key') - Delete files by key or custom ID
  • list_files(limit=None, offset=None) - List uploaded files
  • get_usage_info() - Get account usage statistics

Response Models

All response models are defined in upyloadthing/schemas.py:

  • UploadResult - File upload result containing:
    • ufs_url: str
    • url: str
    • app_url: str
    • file_hash: str
    • server_data: Dict | None
  • DeleteFileResponse - File deletion result containing:
    • success: bool
    • deleted_count: int
  • ListFileResponse - File listing result containing:
    • has_more: bool
    • files: List[FileData]
  • UsageInfoResponse - Usage statistics containing:
    • total_bytes: int
    • app_total_bytes: int
    • files_uploaded: int
    • limit_bytes: int

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

upyloadthing-0.1.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

upyloadthing-0.1.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: upyloadthing-0.1.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.8.0-1020-azure

File hashes

Hashes for upyloadthing-0.1.1.tar.gz
Algorithm Hash digest
SHA256 44dd91f0064cde979358a5491114e9444f52ff5522e981fb1d0bdaa9999db2ac
MD5 a83836fd48401077a32a20c40db77bde
BLAKE2b-256 1b6454dad996567b97c02ece477ef160697d384f3236f7f2074a6094e0555abd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: upyloadthing-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.8.0-1020-azure

File hashes

Hashes for upyloadthing-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2484c3649203b6af426cbf9ce9871ee558b41b93d1555af7e70b88646318f30d
MD5 e16b9e01d758c54162260286efa8ca1d
BLAKE2b-256 29e8afdda9481367355eb32294755a8863214d907881031c3343b77b158fe6a4

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