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.9.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

File details

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

File metadata

File hashes

Hashes for aslabs_dependencies_fastapi-0.0.9.tar.gz
Algorithm Hash digest
SHA256 88ddbdf9d53934db4d58f92ae9860446b91910d8885379d9eb2c8539757a3119
MD5 e78a4e5b5bd89d05ed8986d3df22df1c
BLAKE2b-256 dce7ab29e117c7c8395a053f14d770181e1b3ddae47d95a8448dae53c17280f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aslabs_dependencies_fastapi-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 5b23ce146e1ed4ae404406178cf3b3277de0aff5e0b3043609da04f33b836282
MD5 17ff573f948b19e32098cea812102420
BLAKE2b-256 4ab3fc5303c25dd0931eb54248fbd7703c41bad82e647cd2989d803d38a5241d

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