Registry / web-framework / punq
library0.7.0pypypi✓ verified 86d ago

A lightweight, dependency injection container for Python 3.8+. Version 0.7.0 is the latest stable release. The library supports registering and resolving services, auto-registration, scoped containers, and singleton lifetimes. Release cadence is irregular.

pip install punq
INSTALL
IMPORT
SIG · PUNQ
P
punq
web-frameworkpythonv0.7.0
Install
1.6s avg
Import
118ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.0 · 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
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.124s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.112s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

punq
import punq
from punq import punq
punq is a module, not a package with a submodule named punq.
Scope
from punq import Scope
from punq import scope
Scope is a class (enum), not lowercase.

Create a container, register a string instance, and resolve it.

import punq container = punq.Container() container.register(str, "Hello, world!") resolved = container.resolve(str) print(resolved)
Debug
Known issues
breakingVersion 0.7.0 drops Python 3.7 support. If you need Python 3.7, use punq 0.6.2 or earlier.
fix
Use Python >=3.8.1 or pin punq to <=0.6.2.
affects: >=0.7.0
gotchaRegistering a class with a complex constructor (e.g., multiple dependencies) without using the container's auto-wiring may raise ContainerResolutionError if dependencies are not registered.
fix
Register all dependencies explicitly or use the `auto_register` feature (available in dev versions).
affects: all
gotchaThe `container.child()` method for scoped containers is only available in v0.8.0-dev and later. Using it in v0.7.0 will raise AttributeError.
fix
Upgrade to dev version or avoid using child().
affects: <=0.7.0
deprecatedAuto-registration API is in development; the final API may change. Not yet stable.
fix
Do not rely on auto-registration in production yet.
affects: 0.8.0-dev
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'punq'
punq is not installed.
fix
Run: pip install punq
punq.exceptions.ContainerResolutionError: No registration found for <class '...'>
You tried to resolve a type that has not been registered.
fix
Register the type before resolving: container.register(MyClass, MyClass())
AttributeError: 'Container' object has no attribute 'child'
The `child()` method was introduced in v0.8.0-dev. You are using an older version.
fix
Upgrade to the dev release with: pip install punq==0.8.0-dev1 or later.
TypeError: 'str' object is not callable
You attempted to register a string instance without the instance argument (e.g., container.register(str) instead of container.register(str, 'value')).
fix
Use: container.register(str, 'my string')
Upgrade
Version history
0.7.0latest on PyPI · released Nov 6, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
8
Resources
punq — pip install punq · libregistry