Skip to main content

openavaban

Python library for managing profile avatars and banners via UploadThing and MongoDB.

Installation

pip install openavaban

Quick Start

1. Set up credentials

Create a .env file or pass credentials directly:

UPLOADTHING_TOKEN=eyJ...
MONGODB_URI=mongodb+srv://...

2. Initialize the client

from openavaban import OpenavaBan

# Option 1: Auto-load from .env
client = OpenavaBan()

# Option 2: Pass directly
client = OpenavaBan(
    uploadthing_token="eyJ...",
    mongo_uri="mongodb+srv://...",
    database="openavaban",       # optional, default: "openavaban"
    collection="profiles"        # optional, default: "profiles"
)

Usage

Upload an avatar

avatar = client.upload(
    file="photo.jpg",
    name="Profile Photo",
    class_type="avatar",       # "avatar" or "banner"
    user_id="user_123",
    category="profile",
    tags=["main", "profile"]
)

print(avatar["url"])  # https://utfs.io/f/...

Get user's avatar

avatar = client.get(user_id="user_123", class_type="avatar")

Get all user's images

images = client.get_all(user_id="user_123")

Get image by ID

image = client.get_by_id("64f1a2b3...")

Update an image

client.update(
    image_id="64f1a2b3...",
    name="New Name",
    tags=["updated", "v2"]
)

Delete an image

client.delete("64f1a2b3...")

Query images

results = client.query(
    user_id="user_123",
    class_type="avatar",
    category="profile",
    tags=["main"]
)

Response Format

{
    "id": "64f1a2b3...",
    "name": "Profile Photo",
    "class_type": "avatar",
    "category": "profile",
    "url": "https://utfs.io/f/...",
    "key": "...",
    "user_id": "user_123",
    "created_at": "2026-08-09T10:00:00+00:00",
    "updated_at": "2026-08-09T10:00:00+00:00",
    "file_size": 102400,
    "mime_type": "image/jpeg",
    "tags": ["main", "profile"],
    "metadata": {},
    "dimensions": {"width": 800, "height": 600}
}

Exceptions

Exception Description
ConfigError Missing UploadThing token or MongoDB URI
UploadError UploadThing API failure
InvalidClassError Invalid class_type (must be "avatar" or "banner")
NotFoundError Image not found in MongoDB
ValidationError Invalid file type, file too large, or missing fields

Environment Variables

Variable Description
UPLOADTHING_TOKEN Your UploadThing v7 token
MONGODB_URI Your MongoDB connection string

License

MIT

Metadata

Release files for openavaban 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openavaban 0.4.0
File Size Uploaded
openavaban-0.4.0.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openavaban 0.4.0
File Interpreter ABI Platform
openavaban-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.3 kB

Release files / openavaban-0.4.0.tar.gz

Download URL openavaban-0.4.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4f809b31a42baff43425f7602fc162e66d87bdf8e73b0d3348de0bd3bdb84b59
BLAKE2b-256 checksum
How to use checksums
3975df3629c6a1178a66f08c0a4c3076a66c24664a5d2d85b39e6ed6dde0e2fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / openavaban-0.4.0-py3-none-any.whl

Download URL openavaban-0.4.0-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc675f63bee89fdc98bbcb1f470d22858b593f4cabc40a32e8feb16d474ed488
BLAKE2b-256 checksum
How to use checksums
d58ccd40d8d35c35d3fcb167496b8a954f269d5352f24cd0d6aefb29bf3f0bb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release history Release notifications | RSS feed

1.0.0

2 release files

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page