This project provides collection of utilities for FastAPI framework as: Catcher, Middleware, etc.
Project description
Introduction
This project provides collection of utilities for FastAPI framework as:
- Custom Middlewares
- Exception Catchers
- Custom Routes
Quick Start
This section shows how to use the utilities provided by this project:
from fastapi import FastAPI, Request
from fastapi.exceptions import RequestValidationError
from starlette.exceptions import HTTPException
from surquest.fastapi.utils.route import Route
from surquest.fastapi.utils.middleware import BasicMiddleware
from surquest.fastapi.utils.catcher import (
catch_validation_exceptions,
catch_http_exceptions,
)
app = FastAPI(
title="Sample REST API application",
openapi_url="/openapi.json"
)
# add middleware
app.add_middleware(BasicMiddleware) # this middleware writes request and response to the log
# exception handlers
app.add_exception_handler(HTTPException, catch_http_exceptions)
app.add_exception_handler(RequestValidationError, catch_validation_exceptions)
# custom routes
app.add_api_route(path="/", endpoint=Route.get_documentation, include_in_schema=False)
Local development
You are more than welcome to contribute to this project. To make your start easier we have prepared a docker image with all the necessary tools to run it as interpreter for Pycharm or to run tests.
Build docker image
docker build `
--tag surquest/fastapi/utils `
--file package.base.dockerfile `
--target test .
Run tests
docker run --rm -it `
-v "${pwd}:/opt/project" `
-e "GOOGLE_APPLICATION_CREDENTIALS=/opt/project/credentials/keyfile.json" `
-w "/opt/project/test" `
surquest/fastapi/utils pytest
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 surquest_fastapi_utils-0.0.1rc9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d176273b108654cab9cf2fb19a6dff0537aabf2a8565fd9374832f2909b501f7 |
|
MD5 | 31ad35d1d4ffb0aeb2fc4a9ff913b17b |
|
BLAKE2b-256 | fe37958fd03da74a89e83af2596cd5f102fa8b91aa9e71ad2ca08b4a5f8b69a0 |
Close
Hashes for surquest_fastapi_utils-0.0.1rc9-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbe36e6ada9f5df87c7d39159bc660a50dc5e7b32a86b75258d40b1700da5afc |
|
MD5 | 2d4158e464a1413a3a3b492dc3282a4c |
|
BLAKE2b-256 | a4a97549db1d869a4fac18a1570821c4e4481611e21bd55ed64d567cfbd5a931 |