A minimalist, zero-dependency Inversion of Control (IoC) container for Python.
Project description
📦 Pico-IoC: A Minimalist IoC Container for Python
pico-ioc is a tiny, zero-dependency, decorator-based IoC container for Python.
It helps you build loosely-coupled, testable apps without manual wiring. Inspired by the Spring ecosystem, but minimal.
⚠️ Requires Python 3.10+ (uses
typing.Annotatedandinclude_extras=True).
✨ Features
- Zero dependencies — pure Python, framework-agnostic.
- Decorator API —
@component,@factory_component,@provides,@plugin. - Fail-fast bootstrap — eager by default; missing deps surface at startup.
- Opt-in lazy —
lazy=Truewraps withComponentProxy. - Smart resolution order — parameter name → type annotation → MRO → string.
- Qualifiers & collections —
list[Annotated[T, Q]]filters by qualifier. - Plugins — lifecycle hooks (
before_scan,after_ready). - Public API helper — auto-export decorated symbols in
__init__.py. - Thread/async safe — isolation via
ContextVar.
📦 Installation
# Requires Python 3.10+
pip install pico-ioc
🚀 Quick start
from pico_ioc import component, init
@component
class Config:
url = "sqlite:///demo.db"
@component
class Repo:
def __init__(self, cfg: Config):
self.url = cfg.url
def fetch(self): return f"fetching from {self.url}"
@component
class Service:
def __init__(self, repo: Repo):
self.repo = repo
def run(self): return self.repo.fetch()
# bootstrap
import myapp
c = init(myapp)
svc = c.get(Service)
print(svc.run())
Output:
fetching from sqlite:///demo.db
📖 Documentation
- Overview — mission & concepts
- Guide — practical usage & recipes
- Architecture — internals & design rationale
🧪 Development
pip install tox
tox
📜 License
MIT — see LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pico_ioc-1.0.0.tar.gz.
File metadata
- Download URL: pico_ioc-1.0.0.tar.gz
- Upload date:
- Size: 38.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2781f961565b20abe731ba187780854a1f20d1628086bb714cb4ed550e243cda
|
|
| MD5 |
8e1dc30d68e102562102335deba1d536
|
|
| BLAKE2b-256 |
df074011667296e9ce2e4efdee7a6d08dd7301d96f88b1343bf59883dd38c26b
|
File details
Details for the file pico_ioc-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pico_ioc-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56001f1e2f7f20d1ff2b201167aa0c2ceb421389fb9a8f66ef1c511d007c056b
|
|
| MD5 |
d9ce6b254e8069245e3318fabd8cce18
|
|
| BLAKE2b-256 |
36a1b416c493832a01dc9c205f074bf86d9d0a41ce23f7eca8cb4172f6814145
|