A FastAPI utility to allow Controller Class usage
Project description
fastapi-router-controller
A FastAPI utility to allow Controller Class usage
Installation:
install the package
pip install fastapi-router-controller
How to use
In a Class module
from fastapi import APIRouter, Depends
from fastapi_router_controller import Controller
router = APIRouter()
controller = Controller(router)
async def amazing_fn():
return 'amazing_variable'
@controller.resource()
class ExampleController():
# you can define in the Controller init some FastApi Dependency and them are automatically loaded in controller methods
def __init__(self, x: Foo = Depends(amazing_fn)):
self.x = x
@controller.route.get(
'/some_aoi',
summary='A sample description')
def sample_api(self):
print(self.x) # -> amazing_variable
return 'A sample response'
Load the controller to the main FastAPI app
from fastapi import FastAPI
from fastapi_router_controller import Controller
import ExampleController
app = FastAPI(
title='A sample application using fastapi_router_controller',
version="0.1.0")
app.include_router(ExampleController.router())
For some Example use-cases visit the example folder
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
Close
Hashes for fastapi-router-controller-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 063af3c77196ab3eb54efb24a2de66079b475aab2f30bdb25299f31eaa3d8075 |
|
MD5 | 6028ce1a9486139387d58ddcf8eac9a4 |
|
BLAKE2b-256 | d8cc116b11058e576dff9034ffaed8c1415033236a465e254276418752914e51 |