Larz โ€บ File uploads in Python

File uploads in Python, done right

Multipart form parsing without the deprecated cgi module and without a framework that fights you. In Larz, uploads land on req.files.

pip install larz
from larz.storage import LocalStorage
store = LocalStorage("uploads", url_prefix="/files").mount(app)

@app.post("/upload")
def upload(req):
    f = req.files.get("avatar")
    if not f: return ("no file", 400)
    name = store.save(f)              # safe, unique filename
    return {"url": store.url(name), "size": f.size}

QuickstartGitHubFree course

What Larz handles

FAQ

Does Larz use the cgi module?

No โ€” the cgi module is deprecated and removed in Python 3.13. Larz parses multipart/form-data with its own standard-library parser.

Where do uploaded files go?

Wherever your storage backend puts them. LocalStorage writes to a directory with safe, unique names and can serve them at a URL prefix.