dishka
Cute DI framework with scopes and agreeable API
What it is and what it does
dishka is a dependency injection container that solves the problem of passing objects through layers of constructors by centralizing dependency creation and lifecycle management. It lets you define providers that specify how to create dependencies, assign them to scopes (app-wide, per-request, or custom), and automatically handle resource cleanup when scopes end. The library focuses narrowly on DI without mixing in configuration, logging, or other concerns.
You define your classes with type hints, create providers that specify factories and scopes, combine them into a container, and then retrieve dependencies through the container. Higher-scoped dependencies (like app-level singletons) are accessible from lower scopes (like request-level), and finalization hooks let you close database connections or release other resources when a scope ends. It supports multiple Python versions from 3.10 onward and integrates with popular web frameworks.
Use it for:
- Web application request handling: create app-level singletons (database pools, config) and request-level instances (services, DAOs) with automatic cleanup.
- Modular service architecture: split dependency factories into reusable provider classes instead of monolithic configuration.
- Resource management: define cleanup logic (e.g., closing connections) alongside creation, ensuring resources are released when scopes exit.
- Testing: swap real implementations for mocks by providing alternate providers without changing application code.
- Multi-scope applications: manage dependencies with custom lifetimes beyond just app and request (e.g., per-user, per-transaction).
- Framework integration: use built-in middleware or decorators to wire dishka into FastAPI, Starlette, or other supported frameworks.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
dishka is an IoC container that manages dependency injection with support for multiple scopes and resource finalization, letting you define how and when dependencies are created and released.
Yes. dishka is actively maintained, has no known vulnerabilities, installs with minimal friction, and solves a real problem—managing complex object graphs without global state or scattered markers. It's a good fit if you're building a modular application with multiple dependency scopes or need resource finalization. Not necessary for small scripts or projects with simple, flat dependencies.
Install
dishka on PyPI
pip
pip install dishkauv
uv add dishkapoetry
poetry add dishkaInstalling dishka
Before you install
Low friction: pure Python wheel with a single runtime dependency (exceptiongroup). Active maintenance with recent releases; repository shows 1241 stars and last commit on 2026-08-14.
License in practice
Apache-2.0 permissive license allows commercial and private use with minimal restrictions, making it suitable for most projects.
Quickstart
pip install dishka
from dishka import Provider, Scope, make_container, provide
provider = Provider(scope=Scope.APP)
provider.provide(MyService)
container = make_container(provider)
service = container.get(MyService)
container.close()
Requires Python 3.10 or later.
Verify before relying
- Performance comparison claims against other DI frameworks—fact sheet notes it 'outperforms many alternatives' but provides no benchmarks.
- Specific framework integrations supported beyond the documentation reference—which frameworks are 'out of the box'.
- Whether finalization (cleanup on scope exit) works reliably with all dependency types or has known limitations.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — exceptiongroup |
| Maintenance | actively maintained — 111 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 636,639/month — #5,623 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: dishka-1.10.1-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
slackA dependency injection container that registers…
permissive · top 15,000 on PyPI
kinkKink is a lightweight dependency injection…
permissive · top 15,000 on PyPI
rodiRodi is a dependency injection container for…
permissive · top 15,000 on PyPI
dependency-injectorDependency Injector is a dependency injection…
permissive · top 5,000 on PyPI
wireupWireup is a type-driven dependency injection…
permissive · top 15,000 on PyPI
allukaAlluka is a type-based dependency injection…
permissive · top 15,000 on PyPI
simple-diA strictly typed dependency injection library…
permissive · top 15,000 on PyPI
injectorInjector is a Python dependency injection…
permissive · top 5,000 on PyPI
fast-dependsFastDepends provides a standalone dependency…
permissive · top 5,000 on PyPI
in-n-outLightweight dependency injection framework…
permissive · top 15,000 on PyPI