pico-ioc 2.0.5__py3-none-any.whl → 2.1.1__py3-none-any.whl
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/__init__.py +9 -12
- pico_ioc/_version.py +1 -1
- pico_ioc/analysis.py +92 -0
- pico_ioc/aop.py +20 -12
- pico_ioc/api.py +63 -1088
- pico_ioc/component_scanner.py +166 -0
- pico_ioc/config_builder.py +87 -0
- pico_ioc/config_registrar.py +236 -0
- pico_ioc/config_runtime.py +54 -13
- pico_ioc/container.py +208 -155
- pico_ioc/decorators.py +193 -0
- pico_ioc/dependency_validator.py +103 -0
- pico_ioc/event_bus.py +24 -25
- pico_ioc/exceptions.py +0 -16
- pico_ioc/factory.py +2 -1
- pico_ioc/locator.py +76 -2
- pico_ioc/provider_selector.py +35 -0
- pico_ioc/registrar.py +188 -0
- pico_ioc/scope.py +13 -4
- {pico_ioc-2.0.5.dist-info → pico_ioc-2.1.1.dist-info}/METADATA +94 -45
- pico_ioc-2.1.1.dist-info/RECORD +25 -0
- pico_ioc-2.0.5.dist-info/RECORD +0 -17
- {pico_ioc-2.0.5.dist-info → pico_ioc-2.1.1.dist-info}/WHEEL +0 -0
- {pico_ioc-2.0.5.dist-info → pico_ioc-2.1.1.dist-info}/licenses/LICENSE +0 -0
- {pico_ioc-2.0.5.dist-info → pico_ioc-2.1.1.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pico-ioc
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.1
|
|
4
4
|
Summary: A minimalist, zero-dependency Inversion of Control (IoC) container for Python.
|
|
5
5
|
Author-email: David Perez Cabrera <dperezcabrera@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -39,7 +39,7 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
39
39
|
Classifier: Programming Language :: Python :: 3.14
|
|
40
40
|
Classifier: License :: OSI Approved :: MIT License
|
|
41
41
|
Classifier: Operating System :: OS Independent
|
|
42
|
-
Requires-Python: >=3.
|
|
42
|
+
Requires-Python: >=3.10
|
|
43
43
|
Description-Content-Type: text/markdown
|
|
44
44
|
License-File: LICENSE
|
|
45
45
|
Provides-Extra: yaml
|
|
@@ -68,13 +68,13 @@ It brings *Inversion of Control* and *dependency injection* to Python in a deter
|
|
|
68
68
|
|
|
69
69
|
## ⚖️ Core Principles
|
|
70
70
|
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
-
|
|
77
|
-
-
|
|
71
|
+
- **Single Purpose** – Do one thing: dependency management.
|
|
72
|
+
- **Declarative** – Use simple decorators (`@component`, `@factory`, `@provides`, `@configured`) instead of complex config files.
|
|
73
|
+
- **Deterministic** – No hidden scanning or side-effects; everything flows from an explicit `init()`.
|
|
74
|
+
- **Async-Native** – Fully supports async providers, async lifecycle hooks (`__ainit__`), and async interceptors.
|
|
75
|
+
- **Fail-Fast** – Detects missing bindings and circular dependencies at bootstrap (`init()`).
|
|
76
|
+
- **Testable by Design** – Use `overrides` and `profiles` to swap components instantly.
|
|
77
|
+
- **Zero Core Dependencies** – Built entirely on the Python standard library. Optional features may require external packages (see Installation).
|
|
78
78
|
|
|
79
79
|
---
|
|
80
80
|
|
|
@@ -83,25 +83,24 @@ It brings *Inversion of Control* and *dependency injection* to Python in a deter
|
|
|
83
83
|
As Python systems evolve, wiring dependencies by hand becomes fragile and unmaintainable.
|
|
84
84
|
**Pico-IoC** eliminates that friction by letting you declare how components relate — not how they’re created.
|
|
85
85
|
|
|
86
|
-
| Feature
|
|
87
|
-
|
|
|
88
|
-
| Object creation| `svc = Service(Repo(Config()))` | `svc = container.get(Service)`
|
|
89
|
-
| Replacing deps
|
|
90
|
-
| Coupling
|
|
91
|
-
| Testing
|
|
92
|
-
| Async support
|
|
86
|
+
| Feature | Manual Wiring | With Pico-IoC |
|
|
87
|
+
| :-------------- | :------------------------- | :-------------------------------- |
|
|
88
|
+
| Object creation | `svc = Service(Repo(Config()))` | `svc = container.get(Service)` |
|
|
89
|
+
| Replacing deps | Monkey-patch | `overrides={Repo: FakeRepo()}` |
|
|
90
|
+
| Coupling | Tight | Loose |
|
|
91
|
+
| Testing | Painful | Instant |
|
|
92
|
+
| Async support | Manual | Built-in (`aget`, `__ainit__`, ...) |
|
|
93
93
|
|
|
94
94
|
---
|
|
95
95
|
|
|
96
|
-
## 🧩 Highlights (v2.0
|
|
96
|
+
## 🧩 Highlights (v2.0+)
|
|
97
97
|
|
|
98
|
-
-
|
|
99
|
-
-
|
|
100
|
-
-
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
- **Observable container context** with stats, health checks, and async cleanup.
|
|
98
|
+
- **Unified Configuration:** Use `@configured` to bind both **flat** (ENV-like) and **tree** (YAML/JSON) sources via the `configuration(...)` builder (ADR-0010).
|
|
99
|
+
- **Async-aware AOP system:** Method interceptors via `@intercepted_by`.
|
|
100
|
+
- **Scoped resolution:** singleton, prototype, request, session, transaction, and custom scopes.
|
|
101
|
+
- **`UnifiedComponentProxy`:** Transparent `lazy=True` and AOP proxy supporting serialization.
|
|
102
|
+
- **Tree-based configuration runtime:** Advanced mapping with reusable adapters and discriminators (`Annotated[Union[...], Discriminator(...)]`).
|
|
103
|
+
- **Observable container context:** Built-in stats, health checks (`@health`), observer hooks (`ContainerObserver`), dependency graph export (`export_graph`), and async cleanup.
|
|
105
104
|
|
|
106
105
|
---
|
|
107
106
|
|
|
@@ -109,7 +108,7 @@ As Python systems evolve, wiring dependencies by hand becomes fragile and unmain
|
|
|
109
108
|
|
|
110
109
|
```bash
|
|
111
110
|
pip install pico-ioc
|
|
112
|
-
|
|
111
|
+
````
|
|
113
112
|
|
|
114
113
|
For optional features, you can install extras:
|
|
115
114
|
|
|
@@ -121,50 +120,68 @@ For optional features, you can install extras:
|
|
|
121
120
|
|
|
122
121
|
(Requires `PyYAML`)
|
|
123
122
|
|
|
124
|
-
* **Dependency Graph Export:**
|
|
123
|
+
* **Dependency Graph Export (Rendering):**
|
|
125
124
|
|
|
126
125
|
```bash
|
|
127
|
-
|
|
126
|
+
# You still need Graphviz command-line tools installed separately
|
|
127
|
+
# This extra is currently not required by the code,
|
|
128
|
+
# as export_graph generates the .dot file content directly.
|
|
129
|
+
# pip install pico-ioc[graphviz] # Consider removing if not used by code
|
|
128
130
|
```
|
|
129
131
|
|
|
130
|
-
(Requires the `graphviz` Python package and the Graphviz command-line tools)
|
|
131
|
-
|
|
132
132
|
-----
|
|
133
133
|
|
|
134
|
-
## ⚙️ Quick Example
|
|
134
|
+
## ⚙️ Quick Example (Unified Configuration)
|
|
135
135
|
|
|
136
136
|
```python
|
|
137
|
+
import os
|
|
137
138
|
from dataclasses import dataclass
|
|
138
|
-
from pico_ioc import component, configuration, init
|
|
139
|
+
from pico_ioc import component, configured, configuration, init, EnvSource
|
|
139
140
|
|
|
140
|
-
@
|
|
141
|
+
# 1. Define configuration with @configured
|
|
142
|
+
@configured(prefix="APP_", mapping="auto") # Auto-detects flat mapping
|
|
141
143
|
@dataclass
|
|
142
144
|
class Config:
|
|
143
145
|
db_url: str = "sqlite:///demo.db"
|
|
144
146
|
|
|
147
|
+
# 2. Define components
|
|
145
148
|
@component
|
|
146
149
|
class Repo:
|
|
147
|
-
def __init__(self, cfg: Config):
|
|
150
|
+
def __init__(self, cfg: Config): # Inject config
|
|
148
151
|
self.cfg = cfg
|
|
149
152
|
def fetch(self):
|
|
150
153
|
return f"fetching from {self.cfg.db_url}"
|
|
151
154
|
|
|
152
155
|
@component
|
|
153
156
|
class Service:
|
|
154
|
-
def __init__(self, repo: Repo):
|
|
157
|
+
def __init__(self, repo: Repo): # Inject Repo
|
|
155
158
|
self.repo = repo
|
|
156
159
|
def run(self):
|
|
157
160
|
return self.repo.fetch()
|
|
158
161
|
|
|
159
|
-
|
|
162
|
+
# --- Example Setup ---
|
|
163
|
+
os.environ['APP_DB_URL'] = 'postgresql://user:pass@host/db'
|
|
164
|
+
|
|
165
|
+
# 3. Build configuration context
|
|
166
|
+
config_ctx = configuration(
|
|
167
|
+
EnvSource(prefix="") # Read APP_DB_URL from environment
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
# 4. Initialize container
|
|
171
|
+
container = init(modules=[__name__], config=config_ctx) # Pass context via 'config'
|
|
172
|
+
|
|
173
|
+
# 5. Get and use the service
|
|
160
174
|
svc = container.get(Service)
|
|
161
175
|
print(svc.run())
|
|
176
|
+
|
|
177
|
+
# --- Cleanup ---
|
|
178
|
+
del os.environ['APP_DB_URL']
|
|
162
179
|
```
|
|
163
180
|
|
|
164
181
|
**Output:**
|
|
165
182
|
|
|
166
183
|
```
|
|
167
|
-
fetching from
|
|
184
|
+
fetching from postgresql://user:pass@host/db
|
|
168
185
|
```
|
|
169
186
|
|
|
170
187
|
-----
|
|
@@ -175,7 +192,16 @@ fetching from sqlite:///demo.db
|
|
|
175
192
|
class FakeRepo:
|
|
176
193
|
def fetch(self): return "fake-data"
|
|
177
194
|
|
|
178
|
-
|
|
195
|
+
# Build configuration context (might be empty or specific for test)
|
|
196
|
+
test_config_ctx = configuration()
|
|
197
|
+
|
|
198
|
+
# Use overrides during init
|
|
199
|
+
container = init(
|
|
200
|
+
modules=[__name__],
|
|
201
|
+
config=test_config_ctx,
|
|
202
|
+
overrides={Repo: FakeRepo()} # Replace Repo with FakeRepo
|
|
203
|
+
)
|
|
204
|
+
|
|
179
205
|
svc = container.get(Service)
|
|
180
206
|
assert svc.run() == "fake-data"
|
|
181
207
|
```
|
|
@@ -185,23 +211,46 @@ assert svc.run() == "fake-data"
|
|
|
185
211
|
## 🩺 Lifecycle & AOP
|
|
186
212
|
|
|
187
213
|
```python
|
|
188
|
-
|
|
214
|
+
import time # For example
|
|
215
|
+
from pico_ioc import component, init, intercepted_by, MethodInterceptor, MethodCtx
|
|
189
216
|
|
|
217
|
+
# Define an interceptor component
|
|
218
|
+
@component
|
|
190
219
|
class LogInterceptor(MethodInterceptor):
|
|
191
220
|
def invoke(self, ctx: MethodCtx, call_next):
|
|
192
|
-
print(f"→ calling {ctx.name}")
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
221
|
+
print(f"→ calling {ctx.cls.__name__}.{ctx.name}")
|
|
222
|
+
start = time.perf_counter()
|
|
223
|
+
try:
|
|
224
|
+
res = call_next(ctx)
|
|
225
|
+
duration = (time.perf_counter() - start) * 1000
|
|
226
|
+
print(f"← {ctx.cls.__name__}.{ctx.name} done ({duration:.2f}ms)")
|
|
227
|
+
return res
|
|
228
|
+
except Exception as e:
|
|
229
|
+
duration = (time.perf_counter() - start) * 1000
|
|
230
|
+
print(f"← {ctx.cls.__name__}.{ctx.name} failed ({duration:.2f}ms): {e}")
|
|
231
|
+
raise
|
|
196
232
|
|
|
197
233
|
@component
|
|
198
234
|
class Demo:
|
|
199
|
-
@intercepted_by(LogInterceptor)
|
|
235
|
+
@intercepted_by(LogInterceptor) # Apply the interceptor
|
|
200
236
|
def work(self):
|
|
237
|
+
print(" Working...")
|
|
238
|
+
time.sleep(0.01)
|
|
201
239
|
return "ok"
|
|
202
240
|
|
|
241
|
+
# Initialize container (must scan module containing interceptor too)
|
|
203
242
|
c = init(modules=[__name__])
|
|
204
|
-
c.get(Demo).work()
|
|
243
|
+
result = c.get(Demo).work()
|
|
244
|
+
print(f"Result: {result}")
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
**Output:**
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
→ calling Demo.work
|
|
251
|
+
Working...
|
|
252
|
+
← Demo.work done (10.xxms)
|
|
253
|
+
Result: ok
|
|
205
254
|
```
|
|
206
255
|
|
|
207
256
|
-----
|
|
@@ -233,7 +282,7 @@ tox
|
|
|
233
282
|
|
|
234
283
|
## 🧾 Changelog
|
|
235
284
|
|
|
236
|
-
See [CHANGELOG.md](./CHANGELOG.md) — *
|
|
285
|
+
See [CHANGELOG.md](./CHANGELOG.md) — *Significant redesigns and features in v2.0+.*
|
|
237
286
|
|
|
238
287
|
-----
|
|
239
288
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
pico_ioc/__init__.py,sha256=i25Obx7aH_Oy5b6yjjnCswDgni7InIjrGEcG6vLAw6I,2414
|
|
2
|
+
pico_ioc/_version.py,sha256=Aht2295j8FswZ-nPYofCYr3fBZ6Uyf0thTfl5Oc2mWA,22
|
|
3
|
+
pico_ioc/analysis.py,sha256=k49R-HcDyvpSNid8mxv7Fc6fPHnDu1C_b4HxrGLNF2g,2780
|
|
4
|
+
pico_ioc/aop.py,sha256=XcyzsuKPrVPk1_Jad7Mn-qwoL1y0ZuVWwRZBA-CslJk,13301
|
|
5
|
+
pico_ioc/api.py,sha256=0pcRFHzhDcX8ijd67xAsVrTejwXuJKz7kTKRUrIuX2s,6161
|
|
6
|
+
pico_ioc/component_scanner.py,sha256=S-9XNxrgyq_JFdc4Uqn2bEb-HxafSgIWylIurxyN_UA,7955
|
|
7
|
+
pico_ioc/config_builder.py,sha256=7kcYIq1Yrb46Tic7uLeaCDvLA-Sa_p1PIoGF00mivso,2848
|
|
8
|
+
pico_ioc/config_registrar.py,sha256=34iNQY1TUEPTXbb-QV1T-c5VKAn18hBcNt5MLhzDSfY,8456
|
|
9
|
+
pico_ioc/config_runtime.py,sha256=hiL1kCxhpjbfOdUaH71jMGNESDpWsaJkQXh7q1T71bg,12781
|
|
10
|
+
pico_ioc/constants.py,sha256=AhIt0ieDZ9Turxb_YbNzj11wUbBbzjKfWh1BDlSx2Nw,183
|
|
11
|
+
pico_ioc/container.py,sha256=gXgQT12ChpexbZALUfb0YYohlcRbUUeJ8-ltdR7xitc,18956
|
|
12
|
+
pico_ioc/decorators.py,sha256=ru_YeqyJ3gbfb6M8WeJZlBxfcBBEuGDvxpHJGzU6FIs,6412
|
|
13
|
+
pico_ioc/dependency_validator.py,sha256=BIR6pKntACiabF6CjNZ3m00RMnet9BPK1_9y1iCJ5KQ,4144
|
|
14
|
+
pico_ioc/event_bus.py,sha256=nOL91JLYxap9kbb-HBGEhOVwtXN_bfI4q0mtSRZFlHk,8434
|
|
15
|
+
pico_ioc/exceptions.py,sha256=FBuajj5g29hAGODt2tAWuy2sG5mQojdSddaqFzim-aY,2383
|
|
16
|
+
pico_ioc/factory.py,sha256=oJXx_BYJuvV8oxYzs5I3gx9WM6uLYZ8GCc43gukNanc,1671
|
|
17
|
+
pico_ioc/locator.py,sha256=4WN1qvXXW_LRInB2XJR8pTgIuJ8RyWBSpVo28HwtlL0,4737
|
|
18
|
+
pico_ioc/provider_selector.py,sha256=pU7NbI5vifvUlJEjlRJmvveQUZVD47T24QmiP0CHRw0,1213
|
|
19
|
+
pico_ioc/registrar.py,sha256=hIk48nXghTdA3WBljCbw2q8J_6F_hCk1ljSi4Pb8P3A,8368
|
|
20
|
+
pico_ioc/scope.py,sha256=hOdTmjjfrRt8APXoS3lbTbSPxILi7flBXz_qpIkpoKw,6137
|
|
21
|
+
pico_ioc-2.1.1.dist-info/licenses/LICENSE,sha256=N1_nOvHTM6BobYnOTNXiQkroDqCEi6EzfGBv8lWtyZ0,1077
|
|
22
|
+
pico_ioc-2.1.1.dist-info/METADATA,sha256=deaBUX6MOzClrMVDDhk5siAh2W0QrtQI-w4n2ZI-gGI,10673
|
|
23
|
+
pico_ioc-2.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
24
|
+
pico_ioc-2.1.1.dist-info/top_level.txt,sha256=_7_RLu616z_dtRw16impXn4Mw8IXe2J4BeX5912m5dQ,9
|
|
25
|
+
pico_ioc-2.1.1.dist-info/RECORD,,
|
pico_ioc-2.0.5.dist-info/RECORD
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
pico_ioc/__init__.py,sha256=x7Sg0i4P0aXN3L5WH9IoTkyELPk-NQBdaRq8GuoZqO4,2294
|
|
2
|
-
pico_ioc/_version.py,sha256=dVcGCZ5wUWMpOJgTrQrOvt6L6HdIhykCRMVFZFr-q20,22
|
|
3
|
-
pico_ioc/aop.py,sha256=prFSlZC6vJYUfTbkMvlSc1T9UvvdEHr94Z0HAvjZ1fg,12985
|
|
4
|
-
pico_ioc/api.py,sha256=t0-49OB7EJklZ3MqOJN8JZe7M6qCyqEL4qC4s73KBSw,47471
|
|
5
|
-
pico_ioc/config_runtime.py,sha256=z1cHDb5PbM8PMLYRFf5c2dmze8V22xwEzpWcBhtmMpA,11950
|
|
6
|
-
pico_ioc/constants.py,sha256=AhIt0ieDZ9Turxb_YbNzj11wUbBbzjKfWh1BDlSx2Nw,183
|
|
7
|
-
pico_ioc/container.py,sha256=-0o3T2uiKCnYVHTXP4MnUnA-atNeITjz0CtvUc_rY_E,17237
|
|
8
|
-
pico_ioc/event_bus.py,sha256=E8Qb8KZ6K1CuXSbMlG0MNPHkGoWlssLLPzHq1QYdADQ,8346
|
|
9
|
-
pico_ioc/exceptions.py,sha256=PnIY60r8O-eYXEVk7XPghz-hHNx_012ZLw9ikDwQhqQ,3019
|
|
10
|
-
pico_ioc/factory.py,sha256=RMJJrD91HJdb7R3C6y48Fnia7YRQnQuMuYTC2cIAm34,1579
|
|
11
|
-
pico_ioc/locator.py,sha256=PBxZYO_xCOxG7aJZ0adDtINrJass_ZDNYmPD2O_oNqM,2401
|
|
12
|
-
pico_ioc/scope.py,sha256=GDsDJWw7e5Vpiys-M4vQfKMJWSCiorRsT5cPo6z34Mk,5924
|
|
13
|
-
pico_ioc-2.0.5.dist-info/licenses/LICENSE,sha256=N1_nOvHTM6BobYnOTNXiQkroDqCEi6EzfGBv8lWtyZ0,1077
|
|
14
|
-
pico_ioc-2.0.5.dist-info/METADATA,sha256=MrjsEJCvfDc001raU_teJHK0rWzHgjugG6jgR-eigC8,8741
|
|
15
|
-
pico_ioc-2.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
16
|
-
pico_ioc-2.0.5.dist-info/top_level.txt,sha256=_7_RLu616z_dtRw16impXn4Mw8IXe2J4BeX5912m5dQ,9
|
|
17
|
-
pico_ioc-2.0.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|