惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
人人都是产品经理
人人都是产品经理
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
小众软件
小众软件
B
Blog
博客园 - 叶小钗
Microsoft Azure Blog
Microsoft Azure Blog
Apple Machine Learning Research
Apple Machine Learning Research
A
About on SuperTechFans
J
Java Code Geeks
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Recent Announcements
Recent Announcements
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
Hugging Face - Blog
Hugging Face - Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
V
V2EX

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Stop reimplementing file uploads for your Python ASGI app...
Thomas Barts · 2026-05-15 · via DEV Community

Thomas Bartscherer

Stop reimplementing file uploads for your Python ASGI app. Meet tussi.

Every few months I find myself in the same situation: "we need to support large file uploads". And every time, it's a chore.

This time, I decided to fix it properly to never have that headache again. I'm sharing my painkiller.


What I found

I discovered TUS. It's an open protocol for resumable file uploads. Clients pick up exactly where they left off after a network drop. There are TUS clients for multiple platforms and languages.

I checked out the existing Python server implementations. None of them fit my use case:

  • Most require a database to track upload state
  • Some need a separate daemon process
  • Multi-worker safety is either missing or poorly documented

So I decided, we need a better one.


Meet tussi

tussi is a TUS 1.0.0 resumable upload server for Python. ASGI-native, filesystem storage, no framework lock-in.

My USP: no database required, no separate daemon, and total thread/process/worker safety.

It works with any ASGI server, not just FastAPI. Drop it in, point a TUS client at it, done.

pip install tussi

Enter fullscreen mode Exit fullscreen mode


Quickstart

from pathlib import Path
from tussi import TUSApp, FilesystemStorage

tus = TUSApp(
    storage=FilesystemStorage(directory=Path('./uploads')),
    completed_dir=Path('./completed'),
)

# tus is a standard ASGI callable
# run with: uvicorn myapp:tus

Enter fullscreen mode Exit fullscreen mode

That's it. Works with any TUS client supporting protocol version 1.0.0.


FastAPI integration

tussi doesn't require FastAPI, but integrates cleanly:

from pathlib import Path
from fastapi import FastAPI, Request
from starlette.responses import Response
from tussi import TUSApp, FilesystemStorage

tus = TUSApp(
    storage=FilesystemStorage(directory=Path('./uploads')),
    completed_dir=Path('./completed'),
)
app = FastAPI()

@app.api_route(
    '/files/{path:path}',
    methods=['HEAD', 'PATCH', 'POST', 'OPTIONS'],
    include_in_schema=False,
)
async def tus_handler(request: Request) -> Response:
    return await tus.get_response(request.scope, request.receive)

Enter fullscreen mode Exit fullscreen mode


Processing completed uploads

wait_for_file is an async context manager that blocks until a completed upload is available, claims it with an exclusive lock, and cleans up on exit. Safe to call from multiple concurrent workers.

async with tus.wait_for_file(timeout=3600) as upload:
    filename = upload.meta.get('filename', upload.name)
    upload.save(Path('./dest') / filename)

Enter fullscreen mode Exit fullscreen mode


How it works under the hood

tussi uses posix_fallocate to pre-allocate disk space when an upload is created. No surprises when the disk fills up halfway through. fcntl.flock keeps concurrent workers from stepping on each other.

This is why it's Linux-only.


Event hooks

from tussi import TUSApp, TUSEvent, UploadCompletedEvent

async def on_event(event: TUSEvent) -> None:
    if isinstance(event, UploadCompletedEvent):
        print(f'upload complete: {event.upload_info.upload_id}')

tus = TUSApp(..., on_event=on_event)

Enter fullscreen mode Exit fullscreen mode

Available events: UploadCreatedEvent, UploadProgressEvent, UploadCompletedEvent, UploadFailedEvent.


Try it out

pip install 'tussi[cli]'
tussi-server   # interactive demo server
tussi-upload   # CLI uploader for testing

Enter fullscreen mode Exit fullscreen mode


It's my first entirely OSS library. I'd love feedback, especially on the API surface and what you'd need to actually use this in production.