Skip to main content

Helpers for implementing errors nicely with OpenAPI and FastAPI.

Project description

Identity Lib

This Python package contains utilities enabling nicer error descriptions in OpenAPI specs generated by FastAPI.


Install fastapi-openapierrors using pip:

pip install fastapi-openapierrors

The module can then be used as fastapi_openapierrors to annotate routes:

from fastapi import FastAPI
from fastapi_openapierrors import NotFoundResponse, BadRequestResponse
from pydantic import BaseModel

app = FastAPI()

class Widget(BaseModel):
    name: str

    summary="Get a single widget",
    description="Get a single widget by name",
    responses={400: BadRequestResponse, 404: NotFoundResponse}
async def get_widget(
      name: str = Path(
        title="The name of the widget"
    # FastAPI automatically returns a Bad Request response if the request does
    # not match the route.

    # Look for widget by name.
    widget, was_found = get_widget_by_name(name)

    if not was_found:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)

    return widget

Developer quickstart

This project contains a dockerized testing environment which wraps tox.

Tests can be run using the ./ command:

# Run all PyTest tests and Flake8 checks
$ ./

# Run just PyTest
$ ./ -e py3

# Run a single test file within PyTest
$ ./ -e py3 -- tests/

# Run a single test file within PyTest with verbose logging
$ ./ -e py3 -- tests/ -vvv

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

fastapi-openapierrors-0.9.0.tar.gz (3.3 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page