Skip to main content

A Python ASGI implementation of the tus resumable upload protocol with FastAPI and Starlette integrations.

Project description

asgi-tus

A Python ASGI implementation of the tus resumable upload protocol.

Features

  • Full tus protocol 1.0.0 compliance
  • Support for all standard extensions: creation, creation-with-upload, creation-defer-length, termination, checksum, expiration
  • FastAPI and Starlette integrations in addition to pure ASGI
  • File storage backend with cleanup support
  • CORS support for web clients
  • async/await throughout

Installation

Core functionality (ASGI app only):

pip install asgi-tus

With FastAPI support:

pip install "asgi-tus[fastapi]"

With Starlette support:

pip install "asgi-tus[starlette]"

With development server:

pip install "asgi-tus[server]"

With everything:

pip install "asgi-tus[all]"

Quick Start

Pure ASGI

Core functionality with minimal dependencies:

from asgi_tus import ASGITusApp, FileStorage, TusConfig
from datetime import timedelta

# Configure storage and tus settings
storage = FileStorage("/tmp/uploads")
config = TusConfig(
    max_size=100 * 1024 * 1024,  # 100MB
    upload_expires=timedelta(hours=24),
    cors_enabled=True
)

# Create ASGI app
app = ASGITusApp(storage, config)

# Run with any ASGI server: uvicorn, hypercorn, etc.
# uvicorn main:app --host 0.0.0.0 --port 8000

FastAPI

Requires: pip install "asgi-tus[fastapi]"

from fastapi import FastAPI
from asgi_tus import FileStorage, TusConfig, create_tus_router
from datetime import timedelta

app = FastAPI()

# Configure storage and tus settings
storage = FileStorage("/tmp/uploads")
config = TusConfig(
    max_size=100 * 1024 * 1024,  # 100MB
    upload_expires=timedelta(hours=24),
    cors_enabled=True
)

# Add tus endpoints
tus_router = create_tus_router(storage, config, prefix="/files")
app.include_router(tus_router)

# Upload endpoint: http://localhost:8000/files/

Starlette

Requires: pip install "asgi-tus[starlette]"

from starlette.applications import Starlette
from starlette.routing import Route
from asgi_tus import FileStorage, TusConfig, TusMount
from datetime import timedelta

storage = FileStorage("/tmp/uploads")
config = TusConfig(
    max_size=100 * 1024 * 1024,
    upload_expires=timedelta(hours=24),
    cors_enabled=True
)

tus_mount = TusMount(storage, config, path="/files")

app = Starlette(routes=[
    tus_mount.get_mount()
])

# Upload endpoint: http://localhost:8000/files/

Usage

Test the server:

curl -X OPTIONS http://localhost:8000/files/

Upload with a tus client:

# Python client (pip install tuspy)
from tuspy import TusClient

client = TusClient("http://localhost:8000/files/")
uploader = client.uploader("./file.zip")
uploader.upload()
// JavaScript client (npm install tus-js-client)
import * as tus from "tus-js-client";

const upload = new tus.Upload(file, {
    endpoint: "http://localhost:8000/files/",
    onSuccess: () => console.log("Upload complete!")
});

upload.start();

Configuration

from asgi_tus import TusConfig
from datetime import timedelta

config = TusConfig(
    max_size=1024 * 1024 * 1024,  # 1GB max upload
    upload_expires=timedelta(days=7),  # Files expire after 7 days
    cors_enabled=True,  # Enable CORS
    extensions={  # Supported tus extensions
        "creation",
        "creation-with-upload",
        "creation-defer-length", 
        "termination",
        "checksum",
        "expiration"
    }
)

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

asgi_tus-0.1.0.tar.gz (61.3 kB view details)

Uploaded Source

Built Distribution

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

asgi_tus-0.1.0-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file asgi_tus-0.1.0.tar.gz.

File metadata

  • Download URL: asgi_tus-0.1.0.tar.gz
  • Upload date:
  • Size: 61.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for asgi_tus-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c483f9e31192ef590cd866f29116a93357a47c02e02c35a4301abafdb784ae19
MD5 9ddf67b0363ff543a8ebedd4ed1b907a
BLAKE2b-256 e0baa5708f3d1dc30f6cae7c3ebd57bf4bc407e58c0240e3db1320756d2688b4

See more details on using hashes here.

File details

Details for the file asgi_tus-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: asgi_tus-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for asgi_tus-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f546ebda398ff18a2307945a8b8c29f449303de62923523e4dc1e6099ff3c778
MD5 c1c57325f95da313c0f359500bbe7f2a
BLAKE2b-256 b30bb88f6b436dff94fb85e165c44044069fd1fbc682c9cfe7b107e5eaf6814c

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