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 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


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

Uploaded Source

Built Distribution

File details

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

File metadata

File hashes

Hashes for aslabs_dependencies_fastapi-0.0.3.tar.gz
Algorithm Hash digest
SHA256 afb7d77dc0179831c741a081cb876b83dcaa09c3e316d815e59528e80b9a7769
MD5 b0b64c291bd6926b6102ddc3dca87f7f
BLAKE2b-256 ce4ace6aeed5080003fe65a2a083882ae3b8ce7bcb45cfea32fa8ce0989e5e6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aslabs_dependencies_fastapi-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9e66e3b3707b58f0e2c057f142ae62fdc47a0162a03158da71e5181eee78a44c
MD5 d6de99c307a944f7826a6ec3f37c8da2
BLAKE2b-256 fde3af10a42a6006024f6db9c3206e4aee4b5b8cd6bc77debf2289b7a4cc1ace

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