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.1rc8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54ea728e92a61d204a440aeb639dfc4d5e6f7018d7b64f124684c147c8d6f641 |
|
MD5 | 120d738671dcb86760b844e4c3a86af2 |
|
BLAKE2b-256 | 2e76da410b09bcc84aef30f90c61293c28aacf6df10912103b6d649a057a3437 |
Close
Hashes for surquest_fastapi_utils-0.0.1rc8-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cff603f893aa5a98211517b9cd732d5eaa34c0aac50ceb9891cea3b3f15ab8b6 |
|
MD5 | cd09eecb70be7bc415ba15ce8c55a8b5 |
|
BLAKE2b-256 | 7d6b8668a9e4f5262a89c4a52311ab9fb7c20ec380c4ef792d222f3685bd00f3 |