pico-ioc 1.5.0__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pico_ioc-1.5.0 → pico_ioc-2.0.0}/.github/workflows/ci.yml +1 -1
- pico_ioc-2.0.0/PKG-INFO +230 -0
- pico_ioc-2.0.0/README.md +184 -0
- pico_ioc-2.0.0/docs/DECISIONS.md +156 -0
- pico_ioc-2.0.0/docs/README.md +96 -0
- pico_ioc-2.0.0/docs/adr/README.md +8 -0
- pico_ioc-2.0.0/docs/adr/adr-0001-async-native.md +32 -0
- pico_ioc-2.0.0/docs/adr/adr-0002-tree-based-configuration.md +31 -0
- pico_ioc-2.0.0/docs/adr/adr-0003-context-aware-scopes.md +32 -0
- pico_ioc-2.0.0/docs/adr/adr-0004-observability.md +32 -0
- pico_ioc-2.0.0/docs/adr/adr-0005-aop.md +32 -0
- pico_ioc-2.0.0/docs/adr/adr-0006-eager-validation.md +29 -0
- pico_ioc-2.0.0/docs/adr/adr-0007-event_bus.md +32 -0
- pico_ioc-2.0.0/docs/advanced-features/README.md +66 -0
- pico_ioc-2.0.0/docs/advanced-features/aop-interceptors.md +278 -0
- pico_ioc-2.0.0/docs/advanced-features/async-resolution.md +197 -0
- pico_ioc-2.0.0/docs/advanced-features/conditional-binding.md +202 -0
- pico_ioc-2.0.0/docs/advanced-features/event-bus.md +225 -0
- pico_ioc-2.0.0/docs/advanced-features/health-checks.md +137 -0
- pico_ioc-2.0.0/docs/api-reference/README.md +36 -0
- pico_ioc-2.0.0/docs/api-reference/container.md +200 -0
- pico_ioc-2.0.0/docs/api-reference/decorators.md +127 -0
- pico_ioc-2.0.0/docs/api-reference/glossary.md +74 -0
- pico_ioc-2.0.0/docs/api-reference/protocols.md +155 -0
- pico_ioc-2.0.0/docs/architecture/README.md +47 -0
- pico_ioc-2.0.0/docs/architecture/comparison.md +111 -0
- pico_ioc-2.0.0/docs/architecture/design-principles.md +83 -0
- pico_ioc-2.0.0/docs/architecture/internals.md +165 -0
- pico_ioc-2.0.0/docs/architecture.md +160 -0
- pico_ioc-2.0.0/docs/cookbook/README.md +41 -0
- pico_ioc-2.0.0/docs/cookbook/pattern-aop-feature-toggle.md +277 -0
- pico_ioc-2.0.0/docs/cookbook/pattern-aop-profiling.md +82 -0
- pico_ioc-2.0.0/docs/cookbook/pattern-aop-security.md +298 -0
- pico_ioc-2.0.0/docs/cookbook/pattern-aop-structured-logging.md +230 -0
- pico_ioc-2.0.0/docs/cookbook/pattern-cli-app.md +198 -0
- pico_ioc-2.0.0/docs/cookbook/pattern-cqrs.md +208 -0
- pico_ioc-2.0.0/docs/cookbook/pattern-dynamic-langchain.md +212 -0
- pico_ioc-2.0.0/docs/cookbook/pattern-hot-reload.md +234 -0
- pico_ioc-2.0.0/docs/cookbook/pattern-multi-tenant.md +232 -0
- pico_ioc-2.0.0/docs/getting-started.md +195 -0
- pico_ioc-2.0.0/docs/guide.md +416 -0
- pico_ioc-2.0.0/docs/integrations/README.md +51 -0
- pico_ioc-2.0.0/docs/integrations/ai-langchain.md +187 -0
- pico_ioc-2.0.0/docs/integrations/web-django.md +158 -0
- pico_ioc-2.0.0/docs/integrations/web-fastapi.md +185 -0
- pico_ioc-2.0.0/docs/integrations/web-flask.md +195 -0
- pico_ioc-2.0.0/docs/observability/README.md +54 -0
- pico_ioc-2.0.0/docs/observability/container-context.md +143 -0
- pico_ioc-2.0.0/docs/observability/exporting-graph.md +117 -0
- pico_ioc-2.0.0/docs/observability/observers-metrics.md +167 -0
- pico_ioc-2.0.0/docs/overview.md +80 -0
- pico_ioc-2.0.0/docs/user-guide/configuration-basic.md +200 -0
- pico_ioc-2.0.0/docs/user-guide/configuration-binding.md +530 -0
- pico_ioc-2.0.0/docs/user-guide/core-concepts.md +170 -0
- pico_ioc-2.0.0/docs/user-guide/qualifiers-lists.md +182 -0
- pico_ioc-2.0.0/docs/user-guide/testing.md +206 -0
- {pico_ioc-1.5.0 → pico_ioc-2.0.0}/pyproject.toml +2 -1
- pico_ioc-2.0.0/src/pico_ioc/__init__.py +104 -0
- pico_ioc-2.0.0/src/pico_ioc/_version.py +1 -0
- pico_ioc-2.0.0/src/pico_ioc/aop.py +247 -0
- pico_ioc-2.0.0/src/pico_ioc/api.py +805 -0
- pico_ioc-2.0.0/src/pico_ioc/config_runtime.py +289 -0
- pico_ioc-2.0.0/src/pico_ioc/constants.py +10 -0
- pico_ioc-2.0.0/src/pico_ioc/container.py +305 -0
- pico_ioc-2.0.0/src/pico_ioc/event_bus.py +224 -0
- pico_ioc-2.0.0/src/pico_ioc/exceptions.py +66 -0
- pico_ioc-2.0.0/src/pico_ioc/factory.py +48 -0
- pico_ioc-2.0.0/src/pico_ioc/locator.py +53 -0
- pico_ioc-2.0.0/src/pico_ioc/scope.py +112 -0
- pico_ioc-2.0.0/src/pico_ioc.egg-info/PKG-INFO +230 -0
- pico_ioc-2.0.0/src/pico_ioc.egg-info/SOURCES.txt +84 -0
- pico_ioc-2.0.0/tests/test_configured.py +314 -0
- pico_ioc-2.0.0/tests/test_container_context.py +51 -0
- pico_ioc-2.0.0/tests/test_container_runtime.py +110 -0
- pico_ioc-2.0.0/tests/test_event_bus.py +107 -0
- pico_ioc-2.0.0/tests/test_pico_extends.py +368 -0
- pico_ioc-2.0.0/tests/test_pico_integration.py +310 -0
- {pico_ioc-1.5.0 → pico_ioc-2.0.0}/tox.ini +7 -2
- pico_ioc-1.5.0/.llm/ARCHITECTURE.md +0 -437
- pico_ioc-1.5.0/.llm/DECISIONS.md +0 -197
- pico_ioc-1.5.0/.llm/FEATURES/FEATURE-2025-0001-scope-subgraphs.md +0 -151
- pico_ioc-1.5.0/.llm/FEATURES/FEATURE-2025-0003-interceptor-auto-registration.md +0 -148
- pico_ioc-1.5.0/.llm/FEATURES/FEATURE-2025-0004-config-injection.md +0 -158
- pico_ioc-1.5.0/.llm/GUIDE-CONFIGURATION-INJECTION.md +0 -129
- pico_ioc-1.5.0/.llm/GUIDE-CQRS.md +0 -110
- pico_ioc-1.5.0/.llm/GUIDE-CREATING-PLUGINS-AND-INTERCEPTORS.md +0 -224
- pico_ioc-1.5.0/.llm/GUIDE.md +0 -522
- pico_ioc-1.5.0/.llm/OVERVIEW.md +0 -167
- pico_ioc-1.5.0/PKG-INFO +0 -249
- pico_ioc-1.5.0/README.md +0 -204
- pico_ioc-1.5.0/src/pico_ioc/__init__.py +0 -68
- pico_ioc-1.5.0/src/pico_ioc/_state.py +0 -75
- pico_ioc-1.5.0/src/pico_ioc/_version.py +0 -1
- pico_ioc-1.5.0/src/pico_ioc/api.py +0 -222
- pico_ioc-1.5.0/src/pico_ioc/builder.py +0 -210
- pico_ioc-1.5.0/src/pico_ioc/config.py +0 -332
- pico_ioc-1.5.0/src/pico_ioc/container.py +0 -168
- pico_ioc-1.5.0/src/pico_ioc/decorators.py +0 -120
- pico_ioc-1.5.0/src/pico_ioc/infra.py +0 -196
- pico_ioc-1.5.0/src/pico_ioc/interceptors.py +0 -76
- pico_ioc-1.5.0/src/pico_ioc/plugins.py +0 -28
- pico_ioc-1.5.0/src/pico_ioc/policy.py +0 -245
- pico_ioc-1.5.0/src/pico_ioc/proxy.py +0 -115
- pico_ioc-1.5.0/src/pico_ioc/public_api.py +0 -76
- pico_ioc-1.5.0/src/pico_ioc/resolver.py +0 -101
- pico_ioc-1.5.0/src/pico_ioc/scanner.py +0 -178
- pico_ioc-1.5.0/src/pico_ioc/scope.py +0 -41
- pico_ioc-1.5.0/src/pico_ioc/utils.py +0 -25
- pico_ioc-1.5.0/src/pico_ioc.egg-info/PKG-INFO +0 -249
- pico_ioc-1.5.0/src/pico_ioc.egg-info/SOURCES.txt +0 -65
- pico_ioc-1.5.0/tests/conftest.py +0 -22
- pico_ioc-1.5.0/tests/helpers.py +0 -46
- pico_ioc-1.5.0/tests/test_api.py +0 -135
- pico_ioc-1.5.0/tests/test_config_injection.py +0 -176
- pico_ioc-1.5.0/tests/test_container.py +0 -181
- pico_ioc-1.5.0/tests/test_core_helpers_and_errors.py +0 -86
- pico_ioc-1.5.0/tests/test_decorator_on_missing.py +0 -103
- pico_ioc-1.5.0/tests/test_decorators.py +0 -139
- pico_ioc-1.5.0/tests/test_defaults.py +0 -69
- pico_ioc-1.5.0/tests/test_factory_policy_and_defaults.py +0 -179
- pico_ioc-1.5.0/tests/test_fingerprint_public.py +0 -25
- pico_ioc-1.5.0/tests/test_infrastructure.py +0 -364
- pico_ioc-1.5.0/tests/test_init.py +0 -316
- pico_ioc-1.5.0/tests/test_no_overrides_needed_with_on_missing.py +0 -30
- pico_ioc-1.5.0/tests/test_policy_and_container_helpers.py +0 -106
- pico_ioc-1.5.0/tests/test_policy_env_activation.py +0 -33
- pico_ioc-1.5.0/tests/test_policy_profile_primary.py +0 -35
- pico_ioc-1.5.0/tests/test_proxy_unit.py +0 -188
- pico_ioc-1.5.0/tests/test_public_api.py +0 -220
- pico_ioc-1.5.0/tests/test_qualifiers_unit.py +0 -70
- pico_ioc-1.5.0/tests/test_resolver_unit.py +0 -121
- pico_ioc-1.5.0/tests/test_scanner_providers.py +0 -146
- pico_ioc-1.5.0/tests/test_scanner_unit.py +0 -190
- pico_ioc-1.5.0/tests/test_scope.py +0 -326
- {pico_ioc-1.5.0 → pico_ioc-2.0.0}/.coveragerc +0 -0
- {pico_ioc-1.5.0 → pico_ioc-2.0.0}/.github/workflows/publish-to-pypi.yml +0 -0
- {pico_ioc-1.5.0 → pico_ioc-2.0.0}/CHANGELOG.md +0 -0
- {pico_ioc-1.5.0 → pico_ioc-2.0.0}/LICENSE +0 -0
- {pico_ioc-1.5.0 → pico_ioc-2.0.0}/MANIFEST.in +0 -0
- {pico_ioc-1.5.0 → pico_ioc-2.0.0}/setup.cfg +0 -0
- {pico_ioc-1.5.0 → pico_ioc-2.0.0}/src/pico_ioc.egg-info/dependency_links.txt +0 -0
- {pico_ioc-1.5.0 → pico_ioc-2.0.0}/src/pico_ioc.egg-info/top_level.txt +0 -0
pico_ioc-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pico-ioc
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: A minimalist, zero-dependency Inversion of Control (IoC) container for Python.
|
|
5
|
+
Author-email: David Perez Cabrera <dperezcabrera@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 David Pérez Cabrera
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/dperezcabrera/pico-ioc
|
|
29
|
+
Project-URL: Repository, https://github.com/dperezcabrera/pico-ioc
|
|
30
|
+
Project-URL: Issue Tracker, https://github.com/dperezcabrera/pico-ioc/issues
|
|
31
|
+
Keywords: ioc,di,dependency injection,inversion of control,decorator
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Programming Language :: Python :: 3
|
|
34
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
40
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
41
|
+
Classifier: Operating System :: OS Independent
|
|
42
|
+
Requires-Python: >=3.8
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
License-File: LICENSE
|
|
45
|
+
Dynamic: license-file
|
|
46
|
+
|
|
47
|
+
# 📦 Pico-IoC: A Robust, Async-Native IoC Container for Python
|
|
48
|
+
|
|
49
|
+
[](https://pypi.org/project/pico-ioc/)
|
|
50
|
+
[](https://deepwiki.com/dperezcabrera/pico-ioc)
|
|
51
|
+
[](https://opensource.org/licenses/MIT)
|
|
52
|
+

|
|
53
|
+
[](https://codecov.io/gh/dperezcabrera/pico-ioc)
|
|
54
|
+
[](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-ioc)
|
|
55
|
+
[](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-ioc)
|
|
56
|
+
[](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-ioc)
|
|
57
|
+
|
|
58
|
+
**pico-ioc** is a **robust, async-native, decorator-based IoC container for Python**.
|
|
59
|
+
It helps you build loosely-coupled, testable, enterprise-grade applications without manual wiring. Inspired by the Spring ecosystem, but fully Pythonic.
|
|
60
|
+
|
|
61
|
+
> ⚠️ **Requires Python 3.10+** (due to extensive use of modern `typing` features).
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## ⚖️ Principles
|
|
66
|
+
|
|
67
|
+
* **Focus & Simplicity**: A declarative API for one job: managing dependencies. It avoids accidental complexity by doing one thing well.
|
|
68
|
+
* **Declarative & Explicit**: No magic. Behavior is deterministic, relying on explicit decorators (`@component`, `@factory`) and type hints.
|
|
69
|
+
* **Unified Composition Root**: The application is assembled from a single entry point (`init`) which defines a clear, predictable boundary.
|
|
70
|
+
* **Fail-Fast by Design**: Catches **circular dependencies** and **missing bindings** at startup, not at runtime. If the application runs, it's wired correctly.
|
|
71
|
+
* **Testability First**: Features like `@conditional`, profiles, and `overrides` are first-class citizens, enabling fast and isolated testing.
|
|
72
|
+
* **Async Native & Extensible**: Full `async`/`await` support, AOP (`@intercepted_by`), and a built-in `EventBus` are available out-of-the-box.
|
|
73
|
+
* **Framework Agnostic**: Zero hard dependencies (standard library only). It works with any Python application, from simple scripts to complex web servers.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## ✨ Why Pico-IoC?
|
|
78
|
+
|
|
79
|
+
`pico-ioc` exists to solve a common problem that arises as Python applications grow: managing how objects are created and connected becomes complex and brittle. This manual wiring, where a change deep in the application can cause a cascade of updates, makes the code hard to test and maintain.
|
|
80
|
+
|
|
81
|
+
`pico-ioc` introduces the principle of Inversion of Control (IoC) in a simple, Pythonic way. Instead of you creating and connecting every object, you declare your components with a simple `@component` decorator, and the container automatically wires them together based on their type hints. It brings the architectural robustness and testability of mature frameworks like Spring to the Python ecosystem, allowing you to build complex, loosely-coupled applications that remain simple to manage.
|
|
82
|
+
|
|
83
|
+
| Feature | Manual Wiring | With Pico-IoC |
|
|
84
|
+
| :--- | :--- | :--- |
|
|
85
|
+
| **Object Creation** | `service = Service(Repo(Config()))` | `svc = container.get(Service)` |
|
|
86
|
+
| **Testing** | Manual replacement or monkey-patching | `overrides={Repo: FakeRepo()}` |
|
|
87
|
+
| **Coupling** | High (code knows about constructors) | Low (code just asks for a type) |
|
|
88
|
+
| **Maintenance** | Brittle (changing a constructor breaks consumers) | Robust (changes are isolated) |
|
|
89
|
+
| **Learning Curve** | Ad-hoc, implicit patterns | Uniform, explicit, documented |
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 🧩 Features
|
|
94
|
+
|
|
95
|
+
### Core
|
|
96
|
+
|
|
97
|
+
* **Zero external dependencies** — pure Python, framework-agnostic.
|
|
98
|
+
* **Decorator-based API** — `@component`, `@factory`, `@provides`, `@configuration`.
|
|
99
|
+
* **Fail-fast Bootstrap** — Detects **circular dependencies** and **missing bindings** at startup.
|
|
100
|
+
* **Async-Native Resolution** — Full `async`/`await` support with `container.aget()`.
|
|
101
|
+
* **Sophisticated Scopes** — `singleton`, `prototype`, and `ContextVar`-based scopes (e.g., `request`, `session`).
|
|
102
|
+
* **Typed Configuration** — Injects `dataclasses` from environment/files via `@configuration`.
|
|
103
|
+
* **Test-Driven** — Built-in `overrides` and `profiles` for easy mocking.
|
|
104
|
+
|
|
105
|
+
### Advanced
|
|
106
|
+
|
|
107
|
+
* **AOP / Interceptors** — Intercept method calls with `@intercepted_by`.
|
|
108
|
+
* **Qualifiers** — Inject subsets of components with `Annotated[List[T], Qualifier(...)]`.
|
|
109
|
+
* **Async Event Bus** — Built-in `EventBus` for decoupled, event-driven architecture.
|
|
110
|
+
* **Conditional Registration** — `@conditional` (by profile, env var) and `@on_missing` (fallbacks).
|
|
111
|
+
* **Lifecycle Hooks** — `@configure` (post-init) and `@cleanup` (on shutdown).
|
|
112
|
+
* **Health Checks** — Built-in `@health` decorator and `container.health_check()`.
|
|
113
|
+
* **Serializable Proxies** — Lazy (`@lazy`) and AOP proxies are `pickle`-safe.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 📦 Installation
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# Requires Python 3.10+
|
|
121
|
+
pip install pico-ioc
|
|
122
|
+
````
|
|
123
|
+
|
|
124
|
+
-----
|
|
125
|
+
|
|
126
|
+
## 🚀 Quick Start
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from pico_ioc import component, init, configuration
|
|
130
|
+
from dataclasses import dataclass
|
|
131
|
+
|
|
132
|
+
@configuration
|
|
133
|
+
@dataclass
|
|
134
|
+
class Config:
|
|
135
|
+
url: str = "sqlite:///demo.db"
|
|
136
|
+
|
|
137
|
+
@component
|
|
138
|
+
class Repo:
|
|
139
|
+
def __init__(self, cfg: Config):
|
|
140
|
+
self.url = cfg.url
|
|
141
|
+
def fetch(self):
|
|
142
|
+
return f"fetching from {self.url}"
|
|
143
|
+
|
|
144
|
+
@component
|
|
145
|
+
class Service:
|
|
146
|
+
def __init__(self, repo: Repo):
|
|
147
|
+
self.repo = repo
|
|
148
|
+
def run(self):
|
|
149
|
+
return self.repo.fetch()
|
|
150
|
+
|
|
151
|
+
# Bootstrap the container by scanning modules
|
|
152
|
+
# We use __name__ to scan the current module
|
|
153
|
+
container = init(modules=[__name__])
|
|
154
|
+
|
|
155
|
+
# Resolve the service and run
|
|
156
|
+
svc = container.get(Service)
|
|
157
|
+
print(svc.run())
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Output:**
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
fetching from sqlite:///demo.db
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
-----
|
|
167
|
+
|
|
168
|
+
### Quick Overrides for Testing
|
|
169
|
+
|
|
170
|
+
The `init` function accepts `overrides` to replace any component for testing.
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
import my_app_module
|
|
174
|
+
from pico_ioc import init
|
|
175
|
+
|
|
176
|
+
# Define a fake repository
|
|
177
|
+
class FakeRepo:
|
|
178
|
+
def fetch(self):
|
|
179
|
+
return "fake-data"
|
|
180
|
+
|
|
181
|
+
# Initialize the container, overriding the real Repo
|
|
182
|
+
container = init(
|
|
183
|
+
modules=[my_app_module],
|
|
184
|
+
overrides={
|
|
185
|
+
Repo: FakeRepo() # Override by type
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
# The service now receives FakeRepo instead of the real one
|
|
190
|
+
svc = container.get(Service)
|
|
191
|
+
assert svc.run() == "fake-data"
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
-----
|
|
195
|
+
|
|
196
|
+
## 📖 Documentation
|
|
197
|
+
|
|
198
|
+
* **🚀 New to pico-ioc? Start with the User Guide.**
|
|
199
|
+
|
|
200
|
+
* [**guide.md**](.docs/guide.md) — Learn with practical examples: testing, configuration, AOP, async, and web framework integration.
|
|
201
|
+
|
|
202
|
+
* **🏗️ Want to understand the internals? See the Architecture.**
|
|
203
|
+
|
|
204
|
+
* [**architecture.md**](./docs/architecture.md) — A deep dive into the resolution algorithm, lifecycle, and internal design.
|
|
205
|
+
|
|
206
|
+
-----
|
|
207
|
+
|
|
208
|
+
## 🧪 Development
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
pip install tox
|
|
212
|
+
tox
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
-----
|
|
216
|
+
|
|
217
|
+
## 📜 Changelog
|
|
218
|
+
|
|
219
|
+
See [CHANGELOG.md](./CHANGELOG.md) for version history.
|
|
220
|
+
|
|
221
|
+
-----
|
|
222
|
+
|
|
223
|
+
## 📜 License
|
|
224
|
+
|
|
225
|
+
MIT — see [LICENSE](https://opensource.org/licenses/MIT)
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
|
pico_ioc-2.0.0/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# 📦 Pico-IoC: A Robust, Async-Native IoC Container for Python
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/pico-ioc/)
|
|
4
|
+
[](https://deepwiki.com/dperezcabrera/pico-ioc)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+

|
|
7
|
+
[](https://codecov.io/gh/dperezcabrera/pico-ioc)
|
|
8
|
+
[](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-ioc)
|
|
9
|
+
[](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-ioc)
|
|
10
|
+
[](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-ioc)
|
|
11
|
+
|
|
12
|
+
**pico-ioc** is a **robust, async-native, decorator-based IoC container for Python**.
|
|
13
|
+
It helps you build loosely-coupled, testable, enterprise-grade applications without manual wiring. Inspired by the Spring ecosystem, but fully Pythonic.
|
|
14
|
+
|
|
15
|
+
> ⚠️ **Requires Python 3.10+** (due to extensive use of modern `typing` features).
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## ⚖️ Principles
|
|
20
|
+
|
|
21
|
+
* **Focus & Simplicity**: A declarative API for one job: managing dependencies. It avoids accidental complexity by doing one thing well.
|
|
22
|
+
* **Declarative & Explicit**: No magic. Behavior is deterministic, relying on explicit decorators (`@component`, `@factory`) and type hints.
|
|
23
|
+
* **Unified Composition Root**: The application is assembled from a single entry point (`init`) which defines a clear, predictable boundary.
|
|
24
|
+
* **Fail-Fast by Design**: Catches **circular dependencies** and **missing bindings** at startup, not at runtime. If the application runs, it's wired correctly.
|
|
25
|
+
* **Testability First**: Features like `@conditional`, profiles, and `overrides` are first-class citizens, enabling fast and isolated testing.
|
|
26
|
+
* **Async Native & Extensible**: Full `async`/`await` support, AOP (`@intercepted_by`), and a built-in `EventBus` are available out-of-the-box.
|
|
27
|
+
* **Framework Agnostic**: Zero hard dependencies (standard library only). It works with any Python application, from simple scripts to complex web servers.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## ✨ Why Pico-IoC?
|
|
32
|
+
|
|
33
|
+
`pico-ioc` exists to solve a common problem that arises as Python applications grow: managing how objects are created and connected becomes complex and brittle. This manual wiring, where a change deep in the application can cause a cascade of updates, makes the code hard to test and maintain.
|
|
34
|
+
|
|
35
|
+
`pico-ioc` introduces the principle of Inversion of Control (IoC) in a simple, Pythonic way. Instead of you creating and connecting every object, you declare your components with a simple `@component` decorator, and the container automatically wires them together based on their type hints. It brings the architectural robustness and testability of mature frameworks like Spring to the Python ecosystem, allowing you to build complex, loosely-coupled applications that remain simple to manage.
|
|
36
|
+
|
|
37
|
+
| Feature | Manual Wiring | With Pico-IoC |
|
|
38
|
+
| :--- | :--- | :--- |
|
|
39
|
+
| **Object Creation** | `service = Service(Repo(Config()))` | `svc = container.get(Service)` |
|
|
40
|
+
| **Testing** | Manual replacement or monkey-patching | `overrides={Repo: FakeRepo()}` |
|
|
41
|
+
| **Coupling** | High (code knows about constructors) | Low (code just asks for a type) |
|
|
42
|
+
| **Maintenance** | Brittle (changing a constructor breaks consumers) | Robust (changes are isolated) |
|
|
43
|
+
| **Learning Curve** | Ad-hoc, implicit patterns | Uniform, explicit, documented |
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## 🧩 Features
|
|
48
|
+
|
|
49
|
+
### Core
|
|
50
|
+
|
|
51
|
+
* **Zero external dependencies** — pure Python, framework-agnostic.
|
|
52
|
+
* **Decorator-based API** — `@component`, `@factory`, `@provides`, `@configuration`.
|
|
53
|
+
* **Fail-fast Bootstrap** — Detects **circular dependencies** and **missing bindings** at startup.
|
|
54
|
+
* **Async-Native Resolution** — Full `async`/`await` support with `container.aget()`.
|
|
55
|
+
* **Sophisticated Scopes** — `singleton`, `prototype`, and `ContextVar`-based scopes (e.g., `request`, `session`).
|
|
56
|
+
* **Typed Configuration** — Injects `dataclasses` from environment/files via `@configuration`.
|
|
57
|
+
* **Test-Driven** — Built-in `overrides` and `profiles` for easy mocking.
|
|
58
|
+
|
|
59
|
+
### Advanced
|
|
60
|
+
|
|
61
|
+
* **AOP / Interceptors** — Intercept method calls with `@intercepted_by`.
|
|
62
|
+
* **Qualifiers** — Inject subsets of components with `Annotated[List[T], Qualifier(...)]`.
|
|
63
|
+
* **Async Event Bus** — Built-in `EventBus` for decoupled, event-driven architecture.
|
|
64
|
+
* **Conditional Registration** — `@conditional` (by profile, env var) and `@on_missing` (fallbacks).
|
|
65
|
+
* **Lifecycle Hooks** — `@configure` (post-init) and `@cleanup` (on shutdown).
|
|
66
|
+
* **Health Checks** — Built-in `@health` decorator and `container.health_check()`.
|
|
67
|
+
* **Serializable Proxies** — Lazy (`@lazy`) and AOP proxies are `pickle`-safe.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 📦 Installation
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Requires Python 3.10+
|
|
75
|
+
pip install pico-ioc
|
|
76
|
+
````
|
|
77
|
+
|
|
78
|
+
-----
|
|
79
|
+
|
|
80
|
+
## 🚀 Quick Start
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from pico_ioc import component, init, configuration
|
|
84
|
+
from dataclasses import dataclass
|
|
85
|
+
|
|
86
|
+
@configuration
|
|
87
|
+
@dataclass
|
|
88
|
+
class Config:
|
|
89
|
+
url: str = "sqlite:///demo.db"
|
|
90
|
+
|
|
91
|
+
@component
|
|
92
|
+
class Repo:
|
|
93
|
+
def __init__(self, cfg: Config):
|
|
94
|
+
self.url = cfg.url
|
|
95
|
+
def fetch(self):
|
|
96
|
+
return f"fetching from {self.url}"
|
|
97
|
+
|
|
98
|
+
@component
|
|
99
|
+
class Service:
|
|
100
|
+
def __init__(self, repo: Repo):
|
|
101
|
+
self.repo = repo
|
|
102
|
+
def run(self):
|
|
103
|
+
return self.repo.fetch()
|
|
104
|
+
|
|
105
|
+
# Bootstrap the container by scanning modules
|
|
106
|
+
# We use __name__ to scan the current module
|
|
107
|
+
container = init(modules=[__name__])
|
|
108
|
+
|
|
109
|
+
# Resolve the service and run
|
|
110
|
+
svc = container.get(Service)
|
|
111
|
+
print(svc.run())
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Output:**
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
fetching from sqlite:///demo.db
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
-----
|
|
121
|
+
|
|
122
|
+
### Quick Overrides for Testing
|
|
123
|
+
|
|
124
|
+
The `init` function accepts `overrides` to replace any component for testing.
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
import my_app_module
|
|
128
|
+
from pico_ioc import init
|
|
129
|
+
|
|
130
|
+
# Define a fake repository
|
|
131
|
+
class FakeRepo:
|
|
132
|
+
def fetch(self):
|
|
133
|
+
return "fake-data"
|
|
134
|
+
|
|
135
|
+
# Initialize the container, overriding the real Repo
|
|
136
|
+
container = init(
|
|
137
|
+
modules=[my_app_module],
|
|
138
|
+
overrides={
|
|
139
|
+
Repo: FakeRepo() # Override by type
|
|
140
|
+
}
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
# The service now receives FakeRepo instead of the real one
|
|
144
|
+
svc = container.get(Service)
|
|
145
|
+
assert svc.run() == "fake-data"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
-----
|
|
149
|
+
|
|
150
|
+
## 📖 Documentation
|
|
151
|
+
|
|
152
|
+
* **🚀 New to pico-ioc? Start with the User Guide.**
|
|
153
|
+
|
|
154
|
+
* [**guide.md**](.docs/guide.md) — Learn with practical examples: testing, configuration, AOP, async, and web framework integration.
|
|
155
|
+
|
|
156
|
+
* **🏗️ Want to understand the internals? See the Architecture.**
|
|
157
|
+
|
|
158
|
+
* [**architecture.md**](./docs/architecture.md) — A deep dive into the resolution algorithm, lifecycle, and internal design.
|
|
159
|
+
|
|
160
|
+
-----
|
|
161
|
+
|
|
162
|
+
## 🧪 Development
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
pip install tox
|
|
166
|
+
tox
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
-----
|
|
170
|
+
|
|
171
|
+
## 📜 Changelog
|
|
172
|
+
|
|
173
|
+
See [CHANGELOG.md](./CHANGELOG.md) for version history.
|
|
174
|
+
|
|
175
|
+
-----
|
|
176
|
+
|
|
177
|
+
## 📜 License
|
|
178
|
+
|
|
179
|
+
MIT — see [LICENSE](https://opensource.org/licenses/MIT)
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# DECISIONS.md — pico-ioc
|
|
2
|
+
|
|
3
|
+
This document records **technical and architectural decisions** for pico-ioc.
|
|
4
|
+
Each entry includes a rationale and implications. If a decision is later changed, mark it **[REVOKED]** and link to the replacement.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## ✅ Current Decisions (Reflecting v2 Architecture)
|
|
9
|
+
|
|
10
|
+
### 1) Minimum Python version: **3.10**
|
|
11
|
+
**Decision**: Require Python **3.10+**.
|
|
12
|
+
**Rationale**: `typing.Annotated` and improved `get_type_hints` are crucial for qualifiers, list injection, and clean internal implementation.
|
|
13
|
+
**Implications**: Users must use Python 3.10 or newer. CI/CD targets 3.10+.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
### 2) Keys: **Typed keys preferred**
|
|
18
|
+
**Decision**: Primarily use class/type keys (e.g., `UserService`) for registration and resolution. String keys are supported but discouraged.
|
|
19
|
+
**Rationale**: Enhances type safety, IDE support, and reduces potential collisions.
|
|
20
|
+
**Implications**: Documentation emphasizes type-based injection. String keys remain for specific cases (e.g., configuration values, legacy integration).
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
### 3) Default Lifecycle: **Singleton per container**
|
|
25
|
+
**Decision**: The default scope for components (`@component`) is `singleton`. One instance is created per container and cached.
|
|
26
|
+
**Rationale**: Simple, fast, and matches common use cases for services and clients.
|
|
27
|
+
**Implications**: Users must explicitly use `@scope("prototype")` or other scope decorators for different lifecycles.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
### 4) Fail-Fast Bootstrap: **Eager Validation**
|
|
32
|
+
**Decision**: Perform **eager validation** of component dependencies during `init()`. Check if a provider exists for every required dependency (excluding `@lazy` components by default).
|
|
33
|
+
**Rationale**: Surface wiring errors (missing providers) immediately at startup, enhancing reliability over runtime failures.
|
|
34
|
+
**Implications**: Increases startup time slightly. Potential `ProviderNotFoundError` for dependencies only used by `@lazy` components may be deferred until first access. *(See ADR-006)*
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
### 5) Qualifiers & Collection Injection: **First-class via `Annotated`**
|
|
39
|
+
**Decision**: Support `Qualifier` tags via `@qualifier(...)` and inject filtered lists using `typing.Annotated[List[Type], Qualifier(...)]`.
|
|
40
|
+
**Rationale**: Provides a standard, type-safe mechanism for managing multiple implementations of an interface without custom registries.
|
|
41
|
+
**Implications**: Requires Python 3.9+ for `Annotated`. Preserves registration order in injected lists.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
### 6) Overrides in `init(...)`
|
|
46
|
+
**Decision**: Allow replacing components at bootstrap via `init(..., overrides={...})`.
|
|
47
|
+
**Rationale**: Simplifies unit testing and mocking without needing complex setup or separate modules.
|
|
48
|
+
**Implications**: Overrides are applied *before* any instances are created. Supports overriding with instances, callables (providers), or `(callable, lazy_bool)`.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
### 7) Conditional Providers: **Profiles, Env Vars, Predicates**
|
|
53
|
+
**Decision**: Support conditional registration using `@conditional(profiles=..., require_env=..., predicate=...)`.
|
|
54
|
+
**Rationale**: Enables environment-specific configurations (prod vs. test vs. dev), feature flags, and optional integrations declaratively.
|
|
55
|
+
**Implications**: Components might not be registered if conditions aren't met, potentially leading to `ProviderNotFoundError` if depended upon. Bootstrap error occurs if a required *eager* dependency is inactive. *(See ADR-006)*
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
### 8) Deterministic Provider Selection: **Prefer `@primary`**
|
|
60
|
+
**Decision**: When multiple providers implement the same key (type), select the one marked `@primary`. If ambiguity remains, raise `InvalidBindingError`. `@on_missing` acts as a fallback if no primary or direct provider is found.
|
|
61
|
+
**Rationale**: Provides explicit control over default implementations, making wiring predictable. Avoids reliance on implicit scan order.
|
|
62
|
+
**Implications**: Developers must use `@primary` (or qualifiers/overrides) to resolve ambiguity between multiple implementations.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### 9) Concurrency & Safety: **Immutable Container, Context-Aware Scopes**
|
|
67
|
+
**Decision**: The container's configuration (providers, metadata) is **immutable** after `init()`. Caches (`singleton`, `request`, etc.) are isolated and thread/task-safe using appropriate locking or `contextvars`.
|
|
68
|
+
**Rationale**: Ensure safe usage in multi-threaded and asynchronous applications without external locking.
|
|
69
|
+
**Implications**: Components themselves must be thread/task-safe if used concurrently across scopes. `contextvars` require proper context propagation in complex threading/async scenarios.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### 10) Configuration: **Dual System (`@configuration` and `@configured`)**
|
|
74
|
+
**Decision**: Support two configuration injection mechanisms:
|
|
75
|
+
1. **`@configuration`**: For simple, flat key-value settings populated from ordered `ConfigSource`s (`EnvSource`, `FileSource`).
|
|
76
|
+
2. **`@configured`**: For complex, nested configuration trees populated from ordered `TreeSource`s (`YamlTreeSource`, `JsonTreeSource`), mapping directly to `dataclass` graphs.
|
|
77
|
+
**Rationale**: `@configuration` handles simple cases easily. `@configured` provides a powerful, type-safe solution for modern, structured configuration practices, inspired by frameworks like Spring Boot.
|
|
78
|
+
**Implications**: Developers choose the system appropriate for their needs. `@configured` is generally recommended for new, complex applications. *(See ADR-002)*
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
### 11) AOP: **Explicit Proxy via `@intercepted_by`**
|
|
83
|
+
**Decision**: Implement AOP using **method interception** via a dynamic **`UnifiedComponentProxy`**. Interceptors are defined using the `MethodInterceptor` protocol and applied explicitly with `@intercepted_by(...)`. Rejected alternatives involving metaclass programming or bytecode manipulation.
|
|
84
|
+
**Rationale**: Provides powerful AOP capabilities using standard Python features (decorators, proxies). Explicit application (`@intercepted_by`) is clearer and more controllable than global or rule-based interception. Avoids the complexity and potential fragility of metaprogramming/bytecode.
|
|
85
|
+
**Implications**: Adds a proxy layer (minor performance overhead, potential debug complexity). Developers must explicitly decorate methods to apply aspects. *(See ADR-005)*
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### 12) Async Support: **Native Integration**
|
|
90
|
+
**Decision**: Integrate `asyncio` support deeply throughout the container. Provide `container.aget()`, support `async def` providers, `__ainit__`, async lifecycle hooks (`@configure`, `@cleanup`), async AOP, and an async Event Bus.
|
|
91
|
+
**Rationale**: Essential for modern I/O-bound Python applications. Avoids blocking the event loop during component resolution or lifecycle management.
|
|
92
|
+
**Implications**: Dual API (`get`/`aget`). Developers must use `aget` and `cleanup_all_async` in async contexts. *(See ADR-001)*
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
### 13) Context-Aware Scopes: **`contextvars`-Based**
|
|
97
|
+
**Decision**: Implement dynamic scopes (`request`, `session`, custom) using `contextvars`. Provide `ScopeProtocol`, `ContextVarScope`, `ScopeManager`, `ScopedCaches` (with LRU), and `with container.scope(...)`.
|
|
98
|
+
**Rationale**: `contextvars` provide a robust mechanism for managing context-local state in both threaded and async environments. Enables per-request or other contextual lifecycles.
|
|
99
|
+
**Implications**: Requires explicit scope management (e.g., via middleware) using `container.scope()` or `activate/deactivate`. Potential complexity with context propagation in advanced scenarios. *(See ADR-003)*
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
### 14) Observability: **Built-in Features**
|
|
104
|
+
**Decision**: Include features for monitoring and debugging: `container_id`, `container context` (`as_current`), `container.stats()`, `ContainerObserver` protocol, and `container.export_graph()`.
|
|
105
|
+
**Rationale**: Essential for understanding and managing complex applications, especially multi-container setups. Makes the container less of a "black box".
|
|
106
|
+
**Implications**: Slight overhead for context tracking. `ContainerObserver` and `export_graph` are optional features. *(See ADR-004)*
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
### 15) Event Bus: **Integrated Async Pub/Sub**
|
|
111
|
+
**Decision**: Provide a built-in, asynchronous `EventBus` component with `@subscribe` decorator and `AutoSubscriberMixin`.
|
|
112
|
+
**Rationale**: Facilitates decoupled, event-driven architectures directly within the container ecosystem. Provides a standard mechanism over ad-hoc solutions.
|
|
113
|
+
**Implications**: Adds functionality beyond core DI. Requires registering the `pico_ioc.event_bus` module. Bus is in-process, not a distributed queue replacement. *(See ADR-007)*
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## ❌ Won’t-Do Decisions (Confirmed for v2)
|
|
118
|
+
|
|
119
|
+
### A) Alternative scopes (request/session) beyond `contextvars`
|
|
120
|
+
**Decision**: Stick to `contextvars` for built-in dynamic scopes. Do not add framework-specific scope implementations (e.g., Flask `g`, Django `request`) directly into the core library.
|
|
121
|
+
**Rationale**: Keep `pico-ioc` framework-agnostic. `contextvars` provide a universal mechanism. Framework integrations can bridge framework contexts to `pico-ioc` scopes if needed.
|
|
122
|
+
**Implications**: Integration recipes (like for Flask/FastAPI) show how to manage `contextvars`-based scopes using middleware or request hooks.
|
|
123
|
+
|
|
124
|
+
### B) Hot reload / dynamic re-scan
|
|
125
|
+
**Decision**: The container configuration remains **immutable** after `init()`. No built-in support for watching files and automatically reloading the container.
|
|
126
|
+
**Rationale**: Conflicts with fail-fast validation and immutability principles. Adds significant complexity and potential for inconsistent states. Hot-reload is better handled by development server tools (like `uvicorn --reload` or the `watchdog` pattern shown in the cookbook).
|
|
127
|
+
**Implications**: Developers use external tools or patterns (like the cookbook example) for development-time hot-reloading.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 🗃️ Deprecated / Revoked
|
|
132
|
+
|
|
133
|
+
* **[REVOKED] Decision #11 (Old)**: Infrastructure-based Interceptor API via `@infrastructure`.
|
|
134
|
+
* **Reason:** Replaced by the simpler, more explicit `@intercepted_by` AOP mechanism using `UnifiedComponentProxy` (ADR-005). The `@infrastructure` role might be repurposed or removed in future versions.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 📜 Changelog of Decisions (v2 Focus)
|
|
139
|
+
|
|
140
|
+
* **v2.0**: Minimum Python **3.10** adopted.
|
|
141
|
+
* **v2.0**: **Native Async Support** added (`aget`, `__ainit__`, async hooks/AOP/EventBus - ADR-001).
|
|
142
|
+
* **v2.0**: **Tree-Based Configuration Binding** added (`@configured`, `TreeSource`, `ConfigResolver`, `ObjectGraphBuilder` - ADR-002).
|
|
143
|
+
* **v2.0**: **Context-Aware Scopes** implemented (`@scope("request")`, `contextvars`, `container.scope()` - ADR-003).
|
|
144
|
+
* **v2.0**: **Observability Features** added (`container_id`, `as_current`, `stats`, `ContainerObserver`, `export_graph` - ADR-004).
|
|
145
|
+
* **v2.0**: **AOP Implementation** finalized using `@intercepted_by` and `UnifiedComponentProxy` (ADR-005). Explicit decision against metaprogramming. Old `@infrastructure`-based interceptor plan revoked.
|
|
146
|
+
* **v2.0**: **Eager Startup Validation** confirmed as core principle (ADR-006).
|
|
147
|
+
* **v2.0**: **Built-in Async Event Bus** added (ADR-007).
|
|
148
|
+
* **v2.0**: **`@primary`** confirmed as the primary mechanism for resolving ambiguity (Decision #8 refined).
|
|
149
|
+
* **v2.0**: **Configuration Injection** clarified as a dual system (`@configuration` + `@configured`) (Decision #10 updated).
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
**Summary**: `pico-ioc` v2 prioritizes **robustness, async-native operation, powerful configuration, observability, and explicit AOP** using standard Python features. It remains deterministic and aims to fail fast at startup.
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
How does this look? It incorporates the key decisions from the ADRs and clarifies the v2 architecture.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Welcome to pico-ioc
|
|
2
|
+
|
|
3
|
+
`pico-ioc` is a powerful, async-native, and observability-first Inversion of Control (IoC) container for Python. It's designed to bring the power of enterprise-grade dependency injection, configuration binding, and AOP (Aspect-Oriented Programming) from frameworks like Spring into the modern Python ecosystem.
|
|
4
|
+
|
|
5
|
+
This documentation site guides you from your first component to building complex, observable, and testable applications.
|
|
6
|
+
|
|
7
|
+
## Key Features
|
|
8
|
+
|
|
9
|
+
* 🚀 **Async-Native:** Full support for `async`/`await` in component resolution (`aget`), lifecycle methods (`__ainit__`, `@cleanup`), AOP interceptors, and the Event Bus.
|
|
10
|
+
* 🌳 **Advanced Tree-Binding:** Use `@configured` to map complex YAML/JSON configuration trees directly to `dataclass` graphs, including support for `Union` types and custom discriminators.
|
|
11
|
+
* 🔬 **Observability-First:** Built-in container contexts (`as_current`), stats (`.stats()`), and observer protocols (`ContainerObserver`) to monitor, trace, and debug your application's components.
|
|
12
|
+
* ✨ **Powerful AOP:** Intercept method calls for cross-cutting concerns (like logging, tracing, or caching) using `@intercepted_by` without modifying your business logic.
|
|
13
|
+
* ✅ **Fail-Fast Validation:** The container validates all component dependencies at startup (`init()`), preventing `ProviderNotFoundError` exceptions at runtime.
|
|
14
|
+
* 🧩 **Rich Lifecycle:** Full control over component lifecycles with `@scope`, `@lazy` instantiation, `@configure` setup methods, and `@cleanup` teardown hooks.
|
|
15
|
+
|
|
16
|
+
## Documentation Structure
|
|
17
|
+
|
|
18
|
+
### 1. Getting Started
|
|
19
|
+
|
|
20
|
+
Start here for a 5-minute tutorial to get `pico-ioc` running.
|
|
21
|
+
|
|
22
|
+
* [Overview](./getting-started/README.md)
|
|
23
|
+
* [Installation](./getting-started/installation.md)
|
|
24
|
+
* [5-Minute Quick Start](./getting-started/quick-start.md)
|
|
25
|
+
|
|
26
|
+
### 2. User Guide
|
|
27
|
+
|
|
28
|
+
The main guide covering the 80% of features you'll use daily.
|
|
29
|
+
|
|
30
|
+
* [Overview](./user-guide/README.md)
|
|
31
|
+
* [Core Concepts (`@component`, `@factory`)](./user-guide/core-concepts.md)
|
|
32
|
+
* [Basic Configuration (`@configuration`)](./user-guide/configuration-basic.md)
|
|
33
|
+
* [Configuration Tree Binding (`@configured`)](./user-guide/configuration-binding.md)
|
|
34
|
+
* [Scopes, Lifecycle & `@lazy`](./user-guide/scopes-lifecycle.md)
|
|
35
|
+
* [Qualifiers & List Injection](./user-guide/qualifiers-lists.md)
|
|
36
|
+
* [Testing Applications](./user-guide/testing.md)
|
|
37
|
+
|
|
38
|
+
### 3. Advanced Features
|
|
39
|
+
|
|
40
|
+
Powerful features for complex application architectures.
|
|
41
|
+
|
|
42
|
+
* [Overview](./advanced-features/README.md)
|
|
43
|
+
* [Async Resolution (`aget`, `__ainit__`)](./advanced-features/async-resolution.md)
|
|
44
|
+
* [AOP & Interceptors](./advanced-features/aop-interceptors.md)
|
|
45
|
+
* [The Event Bus](./advanced-features/event-bus.md)
|
|
46
|
+
* [Conditional Binding (`@conditional`, `@primary`)](./advanced-features/conditional-binding.md)
|
|
47
|
+
* [Health Checks (`@health`)](./advanced-features/health-checks.md)
|
|
48
|
+
|
|
49
|
+
### 4. Observability
|
|
50
|
+
|
|
51
|
+
Monitor, trace, and debug your application's components.
|
|
52
|
+
|
|
53
|
+
* [Overview](./observability/README.md)
|
|
54
|
+
* [Container Context (`as_current`)](./observability/container-context.md)
|
|
55
|
+
* [Observers & Metrics (`stats`)](./observability/observers-metrics.md)
|
|
56
|
+
* [Exporting the Dependency Graph](./observability/exporting-graph.md)
|
|
57
|
+
|
|
58
|
+
### 5. Integrations
|
|
59
|
+
|
|
60
|
+
Recipes for using `pico-ioc` with popular frameworks.
|
|
61
|
+
|
|
62
|
+
* [Overview](./integrations/README.md)
|
|
63
|
+
* [FastAPI](./integrations/web-fastapi.md)
|
|
64
|
+
* [Flask](./integrations/web-flask.md)
|
|
65
|
+
* [Django](./integrations/web-django.md)
|
|
66
|
+
* [AI & LangChain](./integrations/ai-langchain.md)
|
|
67
|
+
|
|
68
|
+
### 6. Cookbook (Patterns)
|
|
69
|
+
|
|
70
|
+
Complete, copy-paste examples of common architectural patterns.
|
|
71
|
+
|
|
72
|
+
* [Overview](./cookbook/README.md)
|
|
73
|
+
* [Pattern: Multi-Tenant Applications](./cookbook/pattern-multi-tenant.md)
|
|
74
|
+
* [Pattern: Hot Reload (Dev Server)](./cookbook/pattern-hot-reload.md)
|
|
75
|
+
* [Pattern: CLI Applications](./cookbook/pattern-cli-app.md)
|
|
76
|
+
|
|
77
|
+
### 7. Architecture
|
|
78
|
+
|
|
79
|
+
The "Why" and "How" behind `pico-ioc`'s design.
|
|
80
|
+
|
|
81
|
+
* [Overview](./architecture/README.md)
|
|
82
|
+
* [Design Principles](./architecture/design-principles.md)
|
|
83
|
+
* [Comparison to Other Libraries](./architecture/comparison.md)
|
|
84
|
+
* [Internals Deep-Dive](./architecture/internals.md)
|
|
85
|
+
|
|
86
|
+
### 8. API Reference
|
|
87
|
+
|
|
88
|
+
A "cheatsheet" for all public APIs.
|
|
89
|
+
|
|
90
|
+
* [Overview](./api-reference/README.md)
|
|
91
|
+
* [Glossary](./api-reference/glossary.md)
|
|
92
|
+
* [Decorators Reference](./api-reference/decorators.md)
|
|
93
|
+
* [`PicoContainer` API](./api-reference/container.md)
|
|
94
|
+
* [Protocols (`MethodInterceptor`, etc.)](./api-reference/protocols.md)
|
|
95
|
+
```
|
|
96
|
+
|