A FastAPI utility to allow Controller Class usage
Project description
What this repository contains
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.2.9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e722ffc4ecfac0e9827152e86e70c227d88c5a0465ebc5aee8ff1f49ef1be4f3 |
|
MD5 | 83e8fe965dc7bb24418d67b72a93a06d |
|
BLAKE2b-256 | a4813575c27f5b6e63f23275107bdbde40dda1fa28b118231c3fd627f5a7c17a |