Skip to main content

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 aslabs.dependencies.fastapi 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 aslabs.dependencies.fastapi 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aslabs_dependencies_fastapi-0.0.7.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file aslabs_dependencies_fastapi-0.0.7.tar.gz.

File metadata

File hashes

Hashes for aslabs_dependencies_fastapi-0.0.7.tar.gz
Algorithm Hash digest
SHA256 4a5e2a54c332d4599f9d21d1a2ae31579fe78d30eff29912a5cde8d1ed715acc
MD5 a3d147db08f858d3ed2e825f8ec82ca4
BLAKE2b-256 e4dafc4a60f774df5732425e8c1745d11bc8f9efa52262aeb787c54d61cdf90f

See more details on using hashes here.

File details

Details for the file aslabs_dependencies_fastapi-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for aslabs_dependencies_fastapi-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 db3d40cfc9d482ac02f10ca5dbbaf30587543b067e1de371c7cd538440088a16
MD5 4f148fb82bbe34814ff381b6f2c8c0d5
BLAKE2b-256 ac9043be9f5352ca78ef5f9f0c407add5c8b35e8e1ec3c486f4466ab93228048

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page