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

Uploaded Source

Built Distribution

File details

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

File metadata

File hashes

Hashes for aslabs_dependencies_fastapi-0.0.6.tar.gz
Algorithm Hash digest
SHA256 fb178dde7eee8d4116bfdcdc1e24b01a6911f3eb57173162677f546f4c3955cc
MD5 761d8f36c00b97e33ca6e2a3ace16dbb
BLAKE2b-256 9d9b1eae0d600a9f61ad876c15b3900bde7ed81c17f883ac80e37ce4dbb8dfab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aslabs_dependencies_fastapi-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 173166228c9f1afdcc5a3f1e508e6474a948e1be3dad9ab2218dfb2371a4ebd3
MD5 9370975ebac0113d706a6c8d77f44a6d
BLAKE2b-256 e694d3d007cc53109b5e10f373aa530abb61fd32be545cf09a0be126bfb76958

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