punq
An IOC Container for Python 3.10+
What it is and what it does
Punq is a lightweight inversion-of-control container that manages object construction and dependency injection in Python applications. It lets you register service implementations against abstract types or keys, then resolve them on demand with automatic recursive dependency injection—all without global state, decorators, or unusual syntax. The library is designed to work cleanly with type checkers like mypy and pyright in strict mode.
You create a container at your application's entry point, register your services and their implementations, and then resolve them when needed. Punq handles nested dependencies automatically: if a registered class depends on another registered service, Punq injects it. You can register instances, classes, or provide constructor arguments at registration or resolution time. The library is small, well-tested, and intentionally simple to understand.
Use it for:
- Wire up application services in a web framework or CLI tool without global state or service-locator antipatterns.
- Manage database connections, configuration readers, and other shared resources as singleton or transient instances.
- Test code by registering mock implementations of services without modifying production code.
- Build modular applications where components declare their dependencies through constructor parameters.
- Integrate with type checkers to catch missing or mismatched dependencies at development time.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Punq is a dependency injection container for Python that registers and resolves object dependencies without global state, decorators, or special syntax.
Yes. Punq is actively maintained, has no known vulnerabilities, installs with minimal friction, and solves a real problem—dependency injection without magic or global state. The only caveat is the unclear license: verify the actual license terms before committing to a production dependency, but the library itself is sound and well-designed.
Install
punq on PyPI
pip
pip install punquv
uv add punqpoetry
poetry add punqInstalling punq
Before you install
Low install friction; single pure-Python wheel with only typing-extensions as a runtime dependency. Active maintenance with a release 42 days ago and last commit on 2026-08-14.
License in practice
License treatment is unclear—no SPDX identifier or raw license text is recorded in the metadata. Verify the actual license before use in proprietary or restricted contexts.
Quickstart
pip install punq
import punq
container = punq.Container()
container.register("key", instance="value")
result = container.resolve("key")
Requires Python 3.10 or later (supports up to 3.15).
Verify before relying
- Actual license terms—metadata shows no SPDX or raw license field despite active development.
Package facts
| License | not declared (unclear) |
| Python support | supports the current Python release (<4.0,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — typing-extensions |
| Maintenance | actively maintained — 42 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 105,453/month — #12,699 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: punq-0.8.0-py3-none-any.whl
Keywords: python
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
slackA dependency injection container that registers…
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
kinkKink is a lightweight dependency injection…
permissive · top 15,000 on PyPI
simple-diA strictly typed dependency injection library…
permissive · top 15,000 on PyPI
dependenciesImplements constructor injection for dependency…
permissive · top 15,000 on PyPI
in-n-outLightweight dependency injection framework…
permissive · top 15,000 on PyPI
injectorInjector is a Python dependency injection…
permissive · top 5,000 on PyPI
allukaAlluka is a type-based dependency injection…
permissive · top 15,000 on PyPI
pygnuutilsProvides pure Python implementations of GNU…
copyleft · top 15,000 on PyPI