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.1rc7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d10b3bf469e7c450a6dc1c641a68b4f2f905eb748357aa64d2f000ef482eff5e |
|
MD5 | ea4810929c2488328386b8f8d434047a |
|
BLAKE2b-256 | 32ec4af00d6a5088f26a2dcaac06d2781e2f7026983dc27d2b18d5f8c8eef880 |
Close
Hashes for surquest_fastapi_utils-0.0.1rc7-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30c3a5e6c3f779e2804781756af266faa27491f19cbd40fea3e0355c083f3033 |
|
MD5 | 7cab1f959f5357043fd54cb6090b446c |
|
BLAKE2b-256 | 695cb70fbb435d2c692d979259d09f53b67c7c1dc1152a30e910c405632460b4 |