Skip to main content

FastAPI Extras

This library is a collection of utilities for running FastAPI applications at Explosion AI.

HttpizeErrorsAPIRouter

This custom router's main functionality is to handle errors per route instead of through a global exception handler by adding the httpize_errors keyword argument to the FastAPI route declaration. This allows each route to return normal informative Python errors instead of the FastAPI HTTPException class to get valid responses.

It also times each request and sets the X-Response-Time header on the Response

An example route

@router.get("/testing", httpize_errors={ValueError: 400})
def test_route(i: int):
    if i < 1:
        raise ValueError("Bad Input Data")
    return {"i": i}

If the ValueError is raised, this custom router knows to return a Response with a status code of 400 (Bad Request) and the message provided to the ValueError

Usage

FastAPI doesn't have built-in support for overriding the app Router, however this is required since we add a new keyword argument to the route declaration. FastAPI doesn't pass **kwargs forward, it only passes explict named keyword arguments.

To get around this, we need to overwrite the app router manually and refresh the routes after all of them have been included in the main app. This looks like:

from fastapi import FastAPI
from fastapi_extras import HttpizeErrorsAPIRouter, init_app
import uvicorn


# API Router (could be in another module)
api_router = HttpizeErrorsAPIRouter(tags=["tests"])


@api_router.get("/testing", httpize_errors={ValueError: 400})
def test_route(i: int):
    if i < 1:
        raise ValueError("Bad Input Data")
    return {"i": i}


# Main app definition
app = FastAPI()

# Overwrite App Router to use the custom HttpizeErrorsAPIRouter
app.router = HttpizeErrorsAPIRouter.from_app(app)

# Include API Router from above
app.include_router(api_router)

# Refresh the App (this rebuilds the Starlette Middleware Stack)
init_app(app)

uvicorn.run(app)

Metadata

Release files for fastapi-explosion-extras 0.5.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-explosion-extras 0.5.1
File Size Uploaded
fastapi_explosion_extras-0.5.1.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-explosion-extras 0.5.1
File Interpreter ABI Platform
fastapi_explosion_extras-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.2 kB

Release files / fastapi_explosion_extras-0.5.1.tar.gz

Download URL fastapi_explosion_extras-0.5.1.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
593e57de868c7db4658127dc4cd410408d028ee1987648bae77692397a46acf9
BLAKE2b-256 checksum
How to use checksums
316cd4ee21e0825950b36d4815e345166530ddf52d2bb4fc6743855dd2b766f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 15, 2026.

Transparency log

Release files / fastapi_explosion_extras-0.5.1-py3-none-any.whl

Download URL fastapi_explosion_extras-0.5.1-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9924c57f3453a4fd4f3a58bb4d2efb1a80c43225aa9e5c87e5e59aabfaef108
BLAKE2b-256 checksum
How to use checksums
8ba078c5bd3eff621c1b024b3b192952f9e2d65d4971b6f8f2b632f29d00e6f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Mar 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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