Skip to main content

FastAPI Problems

uv ruff image image image style tests codecov

fastapi_problem is a set of exceptions and handlers for use in fastapi applications to support easy error management and responses.

Each exception easily marshals to JSON based on the RFC9457 spec for use in api errors.

Check the docs for more details.

Custom Errors

Subclassing the convenience classes provide a simple way to consistently raise the same error with detail/extras changing based on the raised context.

from fastapi_problem.error import NotFoundProblem


class UserNotFoundError(NotFoundProblem):
    title = "User not found."

raise UserNotFoundError(detail="detail")
{
    "type": "user-not-found",
    "title": "User not found",
    "detail": "detail",
    "status": 404,
}

Usage

import fastapi
from fastapi_problem.handler import add_exception_handler, new_exception_handler


app = fastapi.FastAPI()
eh = new_exception_handler()
add_exception_handler(app, eh)

@app.get("/user")
async def get_user():
    raise UserNotFoundError("No user found.")
$ curl localhost:8000/user
{

    "type": "user-not-found",
    "title": "User not found",
    "detail": "No user found.",
    "status": 404,
}

Metadata

Release files for fastapi-problem 0.12.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-problem 0.12.1
File Size Uploaded
fastapi_problem-0.12.1.tar.gz 92.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-problem 0.12.1
File Interpreter ABI Platform
fastapi_problem-0.12.1-py3-none-any.whl Python 3 none any Details

Total release size: 102.2 kB

Release files / fastapi_problem-0.12.1.tar.gz

Download URL fastapi_problem-0.12.1.tar.gz
Size 92.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ef8ae98d88b1889820474b5659c455cca785f09aeda7d51b46a3599720aeebe6
BLAKE2b-256 checksum
How to use checksums
83f9c334ef17cdd218e507b4ea2348623adc9c6d6e87d8c6d12300d3d763776f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / fastapi_problem-0.12.1-py3-none-any.whl

Download URL fastapi_problem-0.12.1-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
913517925ea3ceca9c7db9a84f25c7520a5ec4993d16e36b4384db98a1e9ac6c
BLAKE2b-256 checksum
How to use checksums
268965f13940d6598a2aecf07ca046014fe2b0d394dbfb2876e3aa7b06d487d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.12.1 This release

2 release files

0.11.6

2 release files

0.11.5

2 release files

0.11.2

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.9

2 release files

0.10.8

2 release files

0.10.7

2 release files

0.10.6

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.20

2 release files

0.7.19

2 release files

0.7.18

2 release files

0.7.17

2 release files

0.7.16

2 release files

0.7.15

2 release files

0.7.14

2 release files

0.7.13

2 release files

0.7.12

2 release files

0.7.11

2 release files

0.7.10

2 release files

0.7.9

2 release files

0.7.8

2 release files

0.7.7

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.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