Skip to main content

UploadStream

Batteries-included handlers for streaming request content. Stream request content without multipart or form-data, and without loading it all into memory.

PyPI Version

This is a third-party project, not created by the FastAPI team.

Features

  • Streaming uploads - Handle large files without loading them entirely into memory
  • Binary body support - Accept raw binary data directly in request bodies
  • Content-Length aware - Automatically extract file size from request headers
  • OpenAPI documentation - Auto-generate schema documentation for streaming endpoints
  • File-like interface - Use familiar read() methods for consuming streams

Installation

pip install fastapi_uploadstream

Skills

An agent skill is also available for your agent-harness of choice. You can install it via npx skills add https://github.com/whichoneiwonder/fastapi_uploadstream or directly from the source

Quick Start

from typing import Annotated
from fastapi import FastAPI
from fastapi_uploadstream import UploadStream, StreamBody, install_uploadstream_openapi

app = FastAPI()
install_uploadstream_openapi(app)


@app.post("/upload")
async def upload_file(
    body_content: Annotated[
        UploadStream,
        StreamBody(
            media_types=["application/octet-stream"],
            title="File upload",
        ),
    ],
):
    # Read the streamed content
    data = await body_content.read()
    return {
        "size": body_content.size,
        "content_type": body_content.content_type,
    }

Usage

StreamBody Dependency

The StreamBody dependency configures how your endpoint accepts streaming uploads:

StreamBody(
    media_types=["application/octet-stream", "text/plain"],  # Accepted content types
    include_in_schema=True,  # Include in OpenAPI schema
    title="Upload content",  # OpenAPI title
)

UploadStream Object

Once received, you interact with the stream through UploadStream:

@app.post("/upload")
async def handle_upload(body: Annotated[UploadStream, StreamBody(media_types=["*/*"])]):
    # Access file metadata
    print(f"Size: {body.size}")  # From Content-Length header
    print(f"Type: {body.content_type}")
    print(f"Name: {body.filename}")  # From x-filename header

    # Read the stream in chunks
    chunk = await body.read(1024)  # Read up to 1024 bytes

    # Read remaining data at once
    remaining = await body.read()  # Read all remaining data

    # Read everything (resets on first call)
    all_data = await body.read(-1)  # Read all from beginning

OpenAPI Documentation

Call install_uploadstream_openapi() to add automatic schema documentation:

app = FastAPI()
install_uploadstream_openapi(app)

This adds proper OpenAPI definitions for binary request bodies on your streaming endpoints.

When to Use

✅ Use UploadStream for:

  • Large file uploads (to avoid memory overhead)
  • Proxying streaming content to a backend API or storage
  • Binary data streams
  • Direct binary body requests
  • Maintaining Compatibility with non-form-based legacy endpoints

❌ Use FastAPI's UploadFile for:

  • Multipart form uploads
  • Multiple files in one request
  • Form fields + file combinations

Example: File Upload with Size Tracking

@app.post("/upload-large")
async def upload_large_file(body: Annotated[UploadStream, StreamBody()]):
    bytes_received = 0
    chunk_size = 65536  # 64KB chunks

    while True:
        chunk = await body.read(chunk_size)
        if not chunk:
            break
        bytes_received += len(chunk)
        # Process chunk...

    return {"total_bytes": bytes_received}

Requirements

  • Python 3.10+
  • FastAPI 0.116.1+
  • anyio (for async streaming primitives)

License

MIT

Metadata

Release files for fastapi-uploadstream 0.1.1

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

Source distribution (sdist)

Source distribution for fastapi-uploadstream 0.1.1
File Size Uploaded Provenance Actions
fastapi_uploadstream-0.1.1.tar.gz 8.4 kB With provenance Details for fastapi_uploadstream-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-uploadstream 0.1.1
File Interpreter ABI Platform Actions
fastapi_uploadstream-0.1.1-py3-none-any.whl Python 3 none any Details for fastapi_uploadstream-0.1.1-py3-none-any.whl

Total release size: 17.4 kB

Release files / fastapi_uploadstream-0.1.1.tar.gz

Download URL fastapi_uploadstream-0.1.1.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e9f4f73ac71717324c5c90cf50464687f932d79e983e7ece9e53944a304dae38
BLAKE2b-256 checksum
How to use checksums
25c1952b9a6073e9986f9a6a36b458cbe7e502c8f046d107762ca18108c96985
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / fastapi_uploadstream-0.1.1-py3-none-any.whl

Download URL fastapi_uploadstream-0.1.1-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82a745eb9c3dca5bf1c86afea1428f349b4a5a111dc627b43a8353de5993f61e
BLAKE2b-256 checksum
How to use checksums
70367d4966902be291ade07d7190653f48b6cf64583cfd031e72439d8180a8c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Security for fastapi-uploadstream 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fastapi_uploadstream-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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