Registry / web-framework / dishka

dishka

JSON →
library1.10.1pypypi✓ verified 87d ago

Dishka is a lightweight and performant dependency injection framework for Python, designed to be framework-agnostic and support asynchronous operations and scopes. It leverages type hints for dependency resolution, aiming for a 'cute' and agreeable API. The current version is 1.9.1, and it maintains an active release cadence with frequent minor updates and bug fixes.

pip install dishka
INSTALL
IMPORT
SIG · DISHKA
D
dishka
web-frameworkpythonv1.10.1
Install
1.6s avg
Import
415ms
Disk
17MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.10.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 1.66s
py 3.11
✓ —
✓ 1.67s
py 3.12
✓ —
✓ 1.52s
py 3.13
✓ —
✓ 1.58s
py 3.9
✕ build_error
✕ build_error
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Provider
from dishka import Provider
Scope
from dishka import Scope
provide
from dishka import provide
inject
from dishka import inject
make_container
from dishka import make_container

This quickstart demonstrates how to define dependencies using `Provider` and `provide`, manage scopes (`Scope.APP`, `Scope.REQUEST`) with `make_container`, and retrieve services. Dependencies are automatically resolved based on type hints.

import asyncio from dishka import Provider, Scope, provide, make_container class MyDependency: def __init__(self, name: str): self.name = name class MyService: def __init__(self, dep: MyDependency): self.dep = dep class MyProvider(Provider): @provide(scope=Scope.APP) def get_dependency(self) -> MyDependency: return MyDependency(name="Global Dep") @provide(scope=Scope.REQUEST) def get_service(self, dep: MyDependency) -> MyService: return MyService(dep) async def main(): # 1. Create a container with your providers container = make_container(MyProvider()) # 2. Enter an application scope async with container(scope=Scope.APP) as app_container: # 3. Enter a request scope (or other child scope) async with app_container(scope=Scope.REQUEST) as request_container: # 4. Get a dependency from the current scope service = await request_container.get(MyService) print(f"Service created with dependency name: {service.dep.name}") await container.close() if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
gotchaDishka's framework integrations (e.g., FastAPI, AioGram) require installing extra packages (e.g., `dishka[fastapi]`). Forgetting these will result in `ModuleNotFoundError` for integration-specific imports.
fix
Ensure you install Dishka with the correct extra, e.g., `pip install dishka[fastapi]`.
affects: >=1.0.0
gotchaIncorrect scope management, such as trying to exit a scope that isn't the current active one or accessing a shorter-lived dependency from a longer-lived scope, will lead to `ScopeExitError` or `InvalidDependencyGraphError`.
fix
Carefully manage the lifetime of your `Container` and its nested scopes using `async with` blocks. Always resolve dependencies from the appropriate scope context.
affects: >=1.0.0
gotchaDishka relies heavily on accurate type hints for dependency resolution. Complex or ambiguous type hints (e.g., `Union`, `Annotated`, `Protocol`) can sometimes lead to `NotAFactoryError` or `UnsupportedAnnotationError` if not handled precisely.
fix
Ensure all dependencies have clear, resolvable type hints. Refer to Dishka's official documentation for best practices regarding advanced type hinting constructs like `Annotated`.
affects: >=1.5.0
Errors
Common errors & fixes
TypeError: object is not a Provider
A class intended to define dependencies does not inherit from `dishka.Provider`.
fix
Ensure your dependency provider class inherits from `dishka.Provider`, e.g., `class MyProvider(Provider):`.
dishka.exceptions.InvalidDependencyGraphError: Cannot find dependency for MyService
The requested type (e.g., `MyService`) or one of its dependencies cannot be found in the registered providers, or there's a circular dependency.
fix
Verify that all types required by `MyService` (and `MyService` itself) are provided by a `@provide` decorated method in your `Provider`s, and check for circular dependencies.
ModuleNotFoundError: No module named 'dishka.integrations.fastapi'
You are attempting to use a Dishka integration (e.g., for FastAPI) without installing the necessary extra package.
fix
Install Dishka with the required extra: `pip install dishka[fastapi]` (replace `fastapi` with your desired integration).
dishka.exceptions.ScopeExitError: Cannot exit scope REQUEST: it is not the current active scope.
You are trying to exit a container scope that is not the most recently entered or active scope, often due to mismatched `async with` blocks.
fix
Ensure that container scopes are entered and exited in the correct LIFO (Last-In, First-Out) order, typically by nesting `async with container(scope=...)` blocks correctly.
Upgrade
Version history
1.10.1latest on PyPI · released Apr 25, 2026
Audit
Dependencies
fastapioptionalOptional integration with FastAPI
aiogramoptionalOptional integration with AioGram
litestaroptionalOptional integration with Litestar
faststreamoptionalOptional integration with FastStream
starliteoptionalOptional integration with Starlite
taskiqoptionalOptional integration with Taskiq
arqoptionalOptional integration with ARQ
Agent activity
15 hits · last 30 days
node
14
Resources