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.
Use
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
@api.get(
'/widget/{name}',
summary="Get a single widget",
description="Get a single widget by name",
response_model=Widget,
responses={400: BadRequestResponse, 404: NotFoundResponse}
)
async def get_widget(
name: str = Path(
...,
example=f"frobnicator2000",
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 ./test.sh
command:
# Run all PyTest tests and Flake8 checks
$ ./test.sh
# Run just PyTest
$ ./test.sh -e py3
# Run a single test file within PyTest
$ ./test.sh -e py3 -- tests/test_identifiers.py
# Run a single test file within PyTest with verbose logging
$ ./test.sh -e py3 -- tests/test_identifiers.py -vvv
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for fastapi-openapierrors-0.9.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a053f84ac99097c15a5bf370c407c4fdbcdefd3f5967b97cc2f2d4dec4d39da |
|
MD5 | 188ac1eb8feb0c1067ae39640a6f18a0 |
|
BLAKE2b-256 | 3d496427c124678eb2044f110d7bb14dc5c7954bec6f9acf4e009448e7bddc28 |
Close
Hashes for fastapi_openapierrors-0.9.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aefa0769a333cf73c406d01e5188b1c1427a7e960c440491b8d46af67964360b |
|
MD5 | 357dead1799377179307bb16d61711b9 |
|
BLAKE2b-256 | 0401b89238396b943ced9e1e39f68523b75975b2b3167584826205d94beae702 |