No project description provided
Project description
ASLabs Dependencies: FastAPI
FastAPI Adapter for the ASLabs Dependencies package.
How to use it:
In your main.py
, add the Dependencies
additional handler:
from fastapi import FastAPI
from deps import Dependencies
app = FastAPI()
deps = Dependencies(app) # Add line
In your various routers, replace APIRouter
with DependencyRouter
and use it to register your dependencies:
from deps import DependencyRouter, D
router = DependencyRouter()
router.register_dependencies(lambda deps: deps.add_direct(MyDependencyClass)) # Register your dependencies here
Once registered, use the D
parameter function to request dependencies. Notably, you must specify the type as the parameter for D
(cannot be infered).
@router.get("/")
def index(dep: MyDependencyClass = D(MyDependencyClass)):
return {"Hello": dep.get_world()}
Once setup, back in your main.py
, register the router on deps
, not on app
. The same parameters can be used as app.include_router
deps.include_router(router)
You are now done.
Adding global dependencies
You can add dependencies directly to the deps
object, by calling register_with
:
deps.register_with(lambda deps: deps.add_direct(GlobalDependency))
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
File details
Details for the file aslabs_dependencies_fastapi-0.0.4.tar.gz
.
File metadata
- Download URL: aslabs_dependencies_fastapi-0.0.4.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.1 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dab1f96dec5e2c4770326628e89b4008f54cb94946615cff1435b4c464aceb76 |
|
MD5 | a7e88df14a6fffadb913235e8b263a1e |
|
BLAKE2b-256 | 4189f5a20cb023c8271354cf35398baed480d24c552f19d5028906052ccd0939 |
File details
Details for the file aslabs_dependencies_fastapi-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: aslabs_dependencies_fastapi-0.0.4-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.1 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb064233ba8b64e401550995d4eedc5755a8bdd660683eee71ab79b7366d0578 |
|
MD5 | f4aea18c3277f6b152f89beac3219643 |
|
BLAKE2b-256 | b6af325e636345233e53e9d172786640971fb2ba8154696dfdeb310a41fa25ad |