Python client for the uploadthing API
Project description
UpyloadThing
Python SDK for UploadThing - 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 filesdelete_files(keys, key_type='file_key')- Delete files by key or custom IDlist_files(limit=None, offset=None)- List uploaded filesget_usage_info()- Get account usage statistics
Response Models
All response models are defined in upyloadthing/schemas.py:
UploadResult- File upload result containing:ufs_url: strurl: strapp_url: strfile_hash: strserver_data: Dict | None
DeleteFileResponse- File deletion result containing:success: booldeleted_count: int
ListFileResponse- File listing result containing:has_more: boolfiles: List[FileData]
UsageInfoResponse- Usage statistics containing:total_bytes: intapp_total_bytes: intfiles_uploaded: intlimit_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
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
File details
Details for the file upyloadthing-0.1.0.tar.gz.
File metadata
- Download URL: upyloadthing-0.1.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.0 Linux/6.8.0-51-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d436bf70b1aa3e9901ec7d4e75bba1770f1a5ec94e9ef319a36c536a1af07b10
|
|
| MD5 |
4423e721a2db40f4a71b1d09c8a6f18e
|
|
| BLAKE2b-256 |
11c89750fcae4eb8591f44882eba1f27277c6680647a3a4715ec67547b99b051
|
File details
Details for the file upyloadthing-0.1.0-py3-none-any.whl.
File metadata
- Download URL: upyloadthing-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.0 Linux/6.8.0-51-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bce29683aeca39f9b1da6dd936dfe27d4b380bcb9cbcacbdae1e581caba14df
|
|
| MD5 |
a38ac21da8453e2f2152d1c400cd6cc8
|
|
| BLAKE2b-256 |
011492f5898502a622663515af227c285047a3ea576c2e1c2d37c2a7ef0da021
|