pico-ioc 1.2.0__py3-none-any.whl → 1.4.0__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 +30 -4
- pico_ioc/_state.py +69 -4
- pico_ioc/_version.py +1 -1
- pico_ioc/api.py +183 -251
- pico_ioc/builder.py +294 -0
- pico_ioc/config.py +332 -0
- pico_ioc/container.py +73 -26
- pico_ioc/decorators.py +88 -9
- pico_ioc/interceptors.py +56 -0
- pico_ioc/plugins.py +17 -1
- pico_ioc/policy.py +245 -0
- pico_ioc/proxy.py +59 -7
- pico_ioc/resolver.py +54 -46
- pico_ioc/scanner.py +75 -102
- pico_ioc/scope.py +46 -0
- pico_ioc/utils.py +25 -0
- {pico_ioc-1.2.0.dist-info → pico_ioc-1.4.0.dist-info}/METADATA +65 -16
- pico_ioc-1.4.0.dist-info/RECORD +22 -0
- pico_ioc/typing_utils.py +0 -29
- pico_ioc-1.2.0.dist-info/RECORD +0 -17
- {pico_ioc-1.2.0.dist-info → pico_ioc-1.4.0.dist-info}/WHEEL +0 -0
- {pico_ioc-1.2.0.dist-info → pico_ioc-1.4.0.dist-info}/licenses/LICENSE +0 -0
- {pico_ioc-1.2.0.dist-info → pico_ioc-1.4.0.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pico-ioc
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.0
|
|
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
|
|
@@ -61,19 +61,55 @@ It helps you build loosely-coupled, testable apps without manual wiring. Inspire
|
|
|
61
61
|
|
|
62
62
|
---
|
|
63
63
|
|
|
64
|
-
##
|
|
64
|
+
## ⚖️ Principles
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
* **Focus & Simplicity**: A minimal core for one job: managing dependencies. It avoids accidental complexity by doing one thing well.
|
|
67
|
+
* **Predictable & Explicit**: No magic. Behavior is deterministic, relying on explicit decorators and a clear resolution order.
|
|
68
|
+
* **Unified Composition Root**: The application is assembled from a single entry point (`init`) which defines a clear, predictable boundary. This ensures a stable and understandable bootstrap process.
|
|
69
|
+
* **Fail-Fast Bootstrap**: Catches dependency graph errors at startup, not in production. If the application runs, it's wired correctly.
|
|
70
|
+
* **Testability First**: Features like `scope()` and `overrides` are first-class citizens, enabling fast and isolated testing.
|
|
71
|
+
* **Extensible by Design**: Lifecycle hooks and AOP are available through a clean Plugin and Interceptor API without altering the core.
|
|
72
|
+
* **Framework Agnostic**: Zero hard dependencies. It works with any Python application, from simple scripts to complex web servers.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## ✨ Why Pico-IoC?
|
|
77
|
+
|
|
78
|
+
`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. `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, but without the heavy boilerplate, allowing you to build complex, loosely-coupled applications that remain simple to manage.
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
| Feature | Manual Wiring | With Pico-IoC |
|
|
82
|
+
| :------------------ | :------------------------------------------------ | :------------------------------ |
|
|
83
|
+
| **Object Creation** | `service = Service(Repo(Config()))` | `svc = container.get(Service)` |
|
|
84
|
+
| **Testing** | Manual replacement or monkey-patching | `overrides={Repo: FakeRepo()}` |
|
|
85
|
+
| **Coupling** | High (code knows about constructors) | Low (code just asks for a type) |
|
|
86
|
+
| **Maintenance** | Brittle (changing a constructor breaks consumers) | Robust (changes are isolated) |
|
|
87
|
+
| **Learning Curve** | Ad-hoc, implicit patterns | Uniform, explicit, documented |
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## 🧩 Features
|
|
93
|
+
|
|
94
|
+
### Core
|
|
95
|
+
|
|
96
|
+
* **Zero dependencies** — pure Python, framework-agnostic.
|
|
97
|
+
* **Single Entry Point (`init`)** — Robustly bootstrap your entire application from a single root package, enforcing a clean "Composition Root" pattern.
|
|
98
|
+
* **Decorator API** — `@component`, `@factory_component`, `@provides`, `@plugin`.
|
|
99
|
+
* **Fail-fast bootstrap** — eager by default; missing deps surface at startup.
|
|
100
|
+
* **Opt-in lazy** — `lazy=True` wraps with `ComponentProxy`.
|
|
101
|
+
* **Smart resolution order** — parameter name → type annotation → MRO → string.
|
|
102
|
+
* **Overrides for testing** — inject mocks/fakes directly via `init(overrides={...})`.
|
|
103
|
+
* **Public API helper** — auto-export decorated symbols in `__init__.py`.
|
|
104
|
+
* **Thread/async safe** — isolation via `ContextVar`.
|
|
105
|
+
|
|
106
|
+
### Advanced
|
|
107
|
+
|
|
108
|
+
* **Qualifiers & collections** — `list[Annotated[T, Q]]` filters by qualifier.
|
|
109
|
+
* **Flexible Scopes (`scope`)** — Create lightweight, temporary containers from multiple modules, ideal for testing, scripting, or modular tasks.
|
|
110
|
+
* **Interceptors API** — observe/modify resolution, instantiation, invocation, errors.
|
|
111
|
+
* **Conditional providers** — activate components by env vars or predicates.
|
|
112
|
+
* **Plugins** — lifecycle hooks (`before_scan`, `after_ready`).
|
|
77
113
|
|
|
78
114
|
---
|
|
79
115
|
|
|
@@ -163,10 +199,17 @@ This way you don’t need to bootstrap your entire app (`controllers`, `http`,
|
|
|
163
199
|
---
|
|
164
200
|
## 📖 Documentation
|
|
165
201
|
|
|
166
|
-
*
|
|
167
|
-
* [
|
|
168
|
-
|
|
202
|
+
* **🚀 New to pico-ioc? Start with the User Guide.**
|
|
203
|
+
* [**GUIDE.md**](.llm/GUIDE.md) — Learn with practical examples: testing, configuration, collection injection, and web framework integration.
|
|
204
|
+
|
|
205
|
+
* **🏗️ Want to understand the internals? See the Architecture.**
|
|
206
|
+
* [**ARCHITECTURE.md**](.llm/ARCHITECTURE.md) — A deep dive into the algorithms, lifecycle, and internal diagrams. Perfect for contributors.
|
|
169
207
|
|
|
208
|
+
* **🤔 Want to know *why* it's designed this way? Read the Decisions.**
|
|
209
|
+
* [**DECISIONS.md**](.llm/DECISIONS.md) — The history and rationale behind key technical decisions.
|
|
210
|
+
|
|
211
|
+
* **💡 Just need a quick summary?**
|
|
212
|
+
* [**OVERVIEW.md**](.llm/OVERVIEW.md) — What pico-ioc is and why you should use it.
|
|
170
213
|
---
|
|
171
214
|
|
|
172
215
|
## 🧪 Development
|
|
@@ -178,6 +221,12 @@ tox
|
|
|
178
221
|
|
|
179
222
|
---
|
|
180
223
|
|
|
224
|
+
## 📜 Overview
|
|
225
|
+
|
|
226
|
+
See [OVERVIEW.md](.llm/OVERVIEW.md) Just need a quick summary?
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
181
230
|
## 📜 Changelog
|
|
182
231
|
|
|
183
232
|
See [CHANGELOG.md](./CHANGELOG.md) for version history.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
pico_ioc/__init__.py,sha256=s_9v-pMM5X7r5vhbzaOmQQEHBLOmZCV7o6QNtRcfMAU,1282
|
|
2
|
+
pico_ioc/_state.py,sha256=C98XQZIfKy98j8fzR730eUCoqSnCkRkxUS4bH7mp73c,2154
|
|
3
|
+
pico_ioc/_version.py,sha256=EyMGX1ADFzN6XVXHWbJUtKPONYKeFkvWoKIFPDDB2I8,22
|
|
4
|
+
pico_ioc/api.py,sha256=cc9c3db6_dIfeobP_VvFRpNV9qNIsIPbUct5X9mmW9w,8348
|
|
5
|
+
pico_ioc/builder.py,sha256=ZvIpOaAzBpByw-u5V52GM5cJAMH_E_5FMDLlgyqd-g4,11379
|
|
6
|
+
pico_ioc/config.py,sha256=J3k7_2vRB2HCpikzeMzT4Ut9COFM4kcydkwZorncqSk,12317
|
|
7
|
+
pico_ioc/container.py,sha256=V9X0qvNPZYU80C65X3Dqifek6RWt9kgEwG0CkX1Hpow,6461
|
|
8
|
+
pico_ioc/decorators.py,sha256=Jyq7PhSM3uFVfBEaCq6x_mFV9V3B5fTEK4o3I6ZvG5A,4492
|
|
9
|
+
pico_ioc/interceptors.py,sha256=rBdpI7ca5L30N-zR7LKroCIc5FgfNb9M5P7OEGw-TtY,1955
|
|
10
|
+
pico_ioc/plugins.py,sha256=GP7WEMshggQ-FEjiShkcuLrSMxfueUnhbY9I8PcIyPU,1039
|
|
11
|
+
pico_ioc/policy.py,sha256=p7maTHNfU-zoaz3j7CY4P3ry-bYfaGxAOklcTAuF6dY,8648
|
|
12
|
+
pico_ioc/proxy.py,sha256=VJA-QaO8yvejcHmX5mlXMHfyuyXFxD7cazONSzBGrf0,6308
|
|
13
|
+
pico_ioc/public_api.py,sha256=E3sArCoI1xxkIw7xQBvLYAWcIoVJjcq1s0kH-0qIVDE,2383
|
|
14
|
+
pico_ioc/resolver.py,sha256=clIS9wwhOKzIwzBQFXxCrmPX2gM2X2eVyS8P_VEeyDw,4798
|
|
15
|
+
pico_ioc/scanner.py,sha256=TmDLkklO-e2LBoVducQD4-uuZKFDg_dMwgwO9vM8-pU,7129
|
|
16
|
+
pico_ioc/scope.py,sha256=5oRCir1Dqu8Jlgl_R-q900my1u6_7zq5VUbq8ahV280,1754
|
|
17
|
+
pico_ioc/utils.py,sha256=OyhOKnyepwGQ_uQKlQLt-fymEV1bQ6hCq4Me7h3dfco,1002
|
|
18
|
+
pico_ioc-1.4.0.dist-info/licenses/LICENSE,sha256=N1_nOvHTM6BobYnOTNXiQkroDqCEi6EzfGBv8lWtyZ0,1077
|
|
19
|
+
pico_ioc-1.4.0.dist-info/METADATA,sha256=DdvaybzEQOnC-HD563NJZqMDL7zwY3SnEpLGwjPxVzU,10346
|
|
20
|
+
pico_ioc-1.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
21
|
+
pico_ioc-1.4.0.dist-info/top_level.txt,sha256=_7_RLu616z_dtRw16impXn4Mw8IXe2J4BeX5912m5dQ,9
|
|
22
|
+
pico_ioc-1.4.0.dist-info/RECORD,,
|
pico_ioc/typing_utils.py
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# pico_ioc/typing_utils.py
|
|
2
|
-
|
|
3
|
-
import sys
|
|
4
|
-
import typing
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def evaluated_hints(func, owner_cls=None) -> dict:
|
|
8
|
-
"""Return type hints; swallow any error and return {}."""
|
|
9
|
-
try:
|
|
10
|
-
module = sys.modules.get(func.__module__)
|
|
11
|
-
globalns = getattr(module, "__dict__", {})
|
|
12
|
-
localns = vars(owner_cls) if owner_cls is not None else None
|
|
13
|
-
return typing.get_type_hints(func, globalns=globalns, localns=localns, include_extras=True)
|
|
14
|
-
except Exception:
|
|
15
|
-
return {}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def resolve_annotation_to_type(ann, func, owner_cls=None):
|
|
19
|
-
"""Best-effort evaluation of a string annotation; return original on failure."""
|
|
20
|
-
if not isinstance(ann, str):
|
|
21
|
-
return ann
|
|
22
|
-
try:
|
|
23
|
-
module = sys.modules.get(func.__module__)
|
|
24
|
-
globalns = getattr(module, "__dict__", {})
|
|
25
|
-
localns = vars(owner_cls) if owner_cls is not None else None
|
|
26
|
-
return eval(ann, globalns, localns)
|
|
27
|
-
except Exception:
|
|
28
|
-
return ann
|
|
29
|
-
|
pico_ioc-1.2.0.dist-info/RECORD
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
pico_ioc/__init__.py,sha256=JTLiySlYUTAnWODEdilS2rUz4swaqMxrQw_p6IRu-S0,653
|
|
2
|
-
pico_ioc/_state.py,sha256=KHNtdPrv1s-uynfot2IsNkWotBPyORPCcM2xe9qMMPo,286
|
|
3
|
-
pico_ioc/_version.py,sha256=U3f_Jgr3zpgiYG2kLcvcT05TQsVzN9Kktg_f3Q9OZFA,22
|
|
4
|
-
pico_ioc/api.py,sha256=GD16DejaBW6pAH0djU8xCirvkgAla5Ags3sGuhkd7oo,9250
|
|
5
|
-
pico_ioc/container.py,sha256=akjtF9Qo09lsR65a5_8UDnEB6Vvsyuq2BloceJjWpnI,5281
|
|
6
|
-
pico_ioc/decorators.py,sha256=orVMdmGgMYCtNq6fjqEYGZxSuv5qdVqf8J6xoUiUQgs,2173
|
|
7
|
-
pico_ioc/plugins.py,sha256=JbI-28VLGJaik7ysXi3L-YGTGxhqwJH4W5QYuWSruDE,589
|
|
8
|
-
pico_ioc/proxy.py,sha256=-e3Z9z7Bc_2wxswwUJI_s8AfvCTps8f8RWUJ9RuEp7E,4606
|
|
9
|
-
pico_ioc/public_api.py,sha256=E3sArCoI1xxkIw7xQBvLYAWcIoVJjcq1s0kH-0qIVDE,2383
|
|
10
|
-
pico_ioc/resolver.py,sha256=RVVpqnp2UqcKwkKMYBzrTetnZW-ZTY7XwDOslBAWPxI,4911
|
|
11
|
-
pico_ioc/scanner.py,sha256=cSa33lE7dKwUpj2RNpH1SC4wjiaJ9MifS5ecORtW1xM,7645
|
|
12
|
-
pico_ioc/typing_utils.py,sha256=JQ4bkR60pKxFs3f8JlEz41ruKDsWj-SmkKv3DLJriec,950
|
|
13
|
-
pico_ioc-1.2.0.dist-info/licenses/LICENSE,sha256=N1_nOvHTM6BobYnOTNXiQkroDqCEi6EzfGBv8lWtyZ0,1077
|
|
14
|
-
pico_ioc-1.2.0.dist-info/METADATA,sha256=XmSjbjeocTk7V1TIHb2irV5tzJd37zepVKEfWIsDvFM,6719
|
|
15
|
-
pico_ioc-1.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
16
|
-
pico_ioc-1.2.0.dist-info/top_level.txt,sha256=_7_RLu616z_dtRw16impXn4Mw8IXe2J4BeX5912m5dQ,9
|
|
17
|
-
pico_ioc-1.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|