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

Uploaded Source

Built Distribution

File details

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

File metadata

File hashes

Hashes for aslabs_dependencies_fastapi-0.0.8.tar.gz
Algorithm Hash digest
SHA256 c8007d6b1f28912bbf49c7ee6e4d31ef63bc15e22131a48eecd61680146a088b
MD5 f7763e515c87e9fc41cc14b6f0cb35ed
BLAKE2b-256 0a8bb24ee698cc9debd6313afe2ca514677d3f3a18db3c5f488176dff88633f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aslabs_dependencies_fastapi-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 7be97796c18c3bf14711b0226a84b5e6b7f2f36b954927257fd8ab8fc53efef2
MD5 965ce5ef091426505a705a3a1b7f38e3
BLAKE2b-256 e381cf4a5ea2dcb543e79e91671292373d5a7d5b78bcde762152b96da8788966

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