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.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5cc953b657b287a426b3713603d45dc15ba930e54d6e45902b461378475ced6 |
|
MD5 | e6958d928a30657f5c8d4b29482295c9 |
|
BLAKE2b-256 | 2dbc379abae2885a28cf04fa7096863e51c00729ab633d41d9c47c5598411c41 |