Skip to main content

FastAPI integration for the MFUP/2 upload engine: MfupEngine + APIRouter you mount into your own app, or a ready-to-run standalone server.

Project description

mfup-fastapi

FastAPI integration for the MFUP/2 resumable multi-file upload engine (mfup-core).

Embed into your app

from pathlib import Path
from fastapi import FastAPI
from mfup_fastapi import MfupConfig, MfupEngine
from mfup_core import AuthRequest, AuthResult

async def authorize(req: AuthRequest) -> AuthResult | None:
    user = await my_auth(req.headers)          # cookies / Authorization
    if user is None:
        return None                            # → SESSION_ABORT(auth_failed)
    return AuthResult(
        base_dir=f"/srv/homes/{user.id}",      # per-user home
        max_total_bytes=10 * 2**30,            # 10 GiB quota
        context={"user_id": user.id},
    )

engine = MfupEngine(MfupConfig(
    base_dir=Path("/srv/uploads"),
    redis_url="redis://localhost:6379/0",
    authorize=authorize,                       # a callable — or "pkg.mod:func"
))

app = FastAPI(lifespan=engine.lifespan)
app.include_router(engine.router, prefix="/api/uploads")

Point the browser SDK (@mfup/client on npm) at the same prefix: new MfupSession({ serverUrl: "https://host/api/uploads" }).

Run standalone

pip install mfup-fastapi
MFUP_BASE_DIR=/srv/uploads REDIS_URL=redis://localhost:6379/0 \
  python -m mfup_fastapi

All MfupConfig fields map 1:1 to MFUP_* environment variables (MfupConfig.from_env()); hooks are dotted paths there (MFUP_AUTHORIZE=myapp.uploads:authorize).

Hooks

Hook When Controls
authorize HELLO, before anything is created allow/deny, per-user base_dir, target mapping, byte/file quotas, context
map_file publish, per file final layout (by type/scope/anything)
on_committed after COMMIT_OK notification; return "publish" to publish server-side (scan/moderation/billing flows). Or call engine.publish(session_id) yourself later.

Requires Redis (expiry index) and a POSIX filesystem. One worker per engine instance; resume across workers is handled via lazy recovery from the Redis index. Full contract: docs/EXTENDING.md in the repository.

Docs and source: https://github.com/n0isy/mfup

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

mfup_fastapi-0.2.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

mfup_fastapi-0.2.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file mfup_fastapi-0.2.0.tar.gz.

File metadata

  • Download URL: mfup_fastapi-0.2.0.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mfup_fastapi-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1401aac4b230d8186a437871d292872650c55504d90e7a0164fc209f1c91df1b
MD5 205bb0537dba251afab28845dfd6c786
BLAKE2b-256 2c05432f440583ae5f99896ede5c5e4512c7de44ea05a5a969103c83c9cd6b84

See more details on using hashes here.

Provenance

The following attestation bundles were made for mfup_fastapi-0.2.0.tar.gz:

Publisher: release.yml on n0isy/mfup

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mfup_fastapi-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mfup_fastapi-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mfup_fastapi-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73a199dc31c9d898871dc09c190b51120f6db77b127521f0619fae70e76f2908
MD5 f4a2f75998ea686ca686ef9b43c72f4c
BLAKE2b-256 4579a331434b9514f0dc1dff858bdd45f60645f38d8f855968796e751423740b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mfup_fastapi-0.2.0-py3-none-any.whl:

Publisher: release.yml on n0isy/mfup

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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