skillfed

punq

An IOC Container for Python 3.10+

punq v0.8.0 105.5K downloads/30d#12,699 on PyPI429
License unclear Active released

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 punq

uv

uv add punq

poetry

poetry add punq

Installing 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

Intended Audience :: DevelopersProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.15Topic :: Software Development :: Libraries :: Python Modules

Tags

dependency injection container pythonioc container pythonservice locator pythonobject dependency resolutiontype-safe di frameworklightweight di librarypython inversion of control
dependency-injectionioc-containertype-safe

More Python Modules packages