{"id":24275,"library":"punq","title":"punq - IOC Container for Python","description":"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.","status":"active","version":"0.7.0","language":"python","source_language":"en","source_url":"https://github.com/bobthemighty/punq","tags":["dependency-injection","ioc-container","python-3.8+"],"install":[{"cmd":"pip install punq","lang":"bash","label":"Install punq"}],"dependencies":[],"imports":[{"note":"punq is a module, not a package with a submodule named punq.","wrong":"from punq import punq","symbol":"punq","correct":"import punq"},{"note":"Scope is a class (enum), not lowercase.","wrong":"from punq import scope","symbol":"Scope","correct":"from punq import Scope"}],"quickstart":{"code":"import punq\n\ncontainer = punq.Container()\ncontainer.register(str, \"Hello, world!\")\nresolved = container.resolve(str)\nprint(resolved)","lang":"python","description":"Create a container, register a string instance, and resolve it."},"warnings":[{"fix":"Use Python >=3.8.1 or pin punq to <=0.6.2.","message":"Version 0.7.0 drops Python 3.7 support. If you need Python 3.7, use punq 0.6.2 or earlier.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Register all dependencies explicitly or use the `auto_register` feature (available in dev versions).","message":"Registering 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.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to dev version or avoid using child().","message":"The `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.","severity":"gotcha","affected_versions":"<=0.7.0"},{"fix":"Do not rely on auto-registration in production yet.","message":"Auto-registration API is in development; the final API may change. Not yet stable.","severity":"deprecated","affected_versions":"0.8.0-dev"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run: pip install punq","cause":"punq is not installed.","error":"ModuleNotFoundError: No module named 'punq'"},{"fix":"Register the type before resolving: container.register(MyClass, MyClass())","cause":"You tried to resolve a type that has not been registered.","error":"punq.exceptions.ContainerResolutionError: No registration found for <class '...'>"},{"fix":"Upgrade to the dev release with: pip install punq==0.8.0-dev1 or later.","cause":"The `child()` method was introduced in v0.8.0-dev. You are using an older version.","error":"AttributeError: 'Container' object has no attribute 'child'"},{"fix":"Use: container.register(str, 'my string')","cause":"You attempted to register a string instance without the instance argument (e.g., container.register(str) instead of container.register(str, 'value')).","error":"TypeError: 'str' object is not callable"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}