skillfed

dishka

Cute DI framework with scopes and agreeable API

dishka v1.10.1 636.6K downloads/30d#5,623 on PyPI1,241
Permissive license Apache-2.0 Active released

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 dishka

uv

uv add dishka

poetry

poetry add dishka

Installing 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

Intended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Software Development :: LibrariesTyping :: Typed

Tags

dependency injection containerIoC container Pythonscoped dependency managementresource finalization DIfactory pattern frameworkapplication lifecycle managementmodular provider pattern
dependency-injectionioc-containerscope-management

More Libraries packages