pico-ioc 2.0.0__py3-none-any.whl → 2.0.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 +1 -12
- pico_ioc/_version.py +1 -1
- pico_ioc/aop.py +55 -21
- pico_ioc/api.py +464 -108
- pico_ioc/container.py +161 -26
- pico_ioc/event_bus.py +3 -4
- pico_ioc/exceptions.py +9 -3
- pico_ioc/scope.py +47 -2
- pico_ioc-2.0.1.dist-info/METADATA +243 -0
- pico_ioc-2.0.1.dist-info/RECORD +17 -0
- pico_ioc-2.0.0.dist-info/METADATA +0 -230
- pico_ioc-2.0.0.dist-info/RECORD +0 -17
- {pico_ioc-2.0.0.dist-info → pico_ioc-2.0.1.dist-info}/WHEEL +0 -0
- {pico_ioc-2.0.0.dist-info → pico_ioc-2.0.1.dist-info}/licenses/LICENSE +0 -0
- {pico_ioc-2.0.0.dist-info → pico_ioc-2.0.1.dist-info}/top_level.txt +0 -0
|
@@ -1,230 +0,0 @@
|
|
|
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.dist-info/RECORD
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
pico_ioc/__init__.py,sha256=sfAtaueMwYKztdJOmU_0-lkMQ_1Lr196KOZE__mzQXI,2373
|
|
2
|
-
pico_ioc/_version.py,sha256=hwOJuFUEKtsgiOt4l6op9s-hviovM6TK1uCdtRNWY4E,22
|
|
3
|
-
pico_ioc/aop.py,sha256=YBvwPwSw8lbXxr_zGbJ8SyxSMh_1kwTFmaB9ezKIDrM,11602
|
|
4
|
-
pico_ioc/api.py,sha256=iu61f3RAqGZ6W4B8JtF3CVkGVukF708O41rx46Q29Ro,32685
|
|
5
|
-
pico_ioc/config_runtime.py,sha256=z1cHDb5PbM8PMLYRFf5c2dmze8V22xwEzpWcBhtmMpA,11950
|
|
6
|
-
pico_ioc/constants.py,sha256=AhIt0ieDZ9Turxb_YbNzj11wUbBbzjKfWh1BDlSx2Nw,183
|
|
7
|
-
pico_ioc/container.py,sha256=xNO1boVXuiMxjJGk8uZdFpLPGugQn1Hyvk1OO0ZcUBk,12509
|
|
8
|
-
pico_ioc/event_bus.py,sha256=0u-uAvniNWk22r3IRqONyeR74SH4Ekc6zb2ZlIJ4HFE,8348
|
|
9
|
-
pico_ioc/exceptions.py,sha256=IwhK7q28_cubG6yiD2mlBYwYPl5I4JAPyt4nss7WFJw,2254
|
|
10
|
-
pico_ioc/factory.py,sha256=Q3aLwZ-MWbXKjm8unr871vlWSeVUDmzFQZ1mXzPkY5I,1557
|
|
11
|
-
pico_ioc/locator.py,sha256=PBxZYO_xCOxG7aJZ0adDtINrJass_ZDNYmPD2O_oNqM,2401
|
|
12
|
-
pico_ioc/scope.py,sha256=BZVEklggnpiKBlE07Ec9NNhJQ6Wg5cnS7IYRAiDB3-E,4473
|
|
13
|
-
pico_ioc-2.0.0.dist-info/licenses/LICENSE,sha256=N1_nOvHTM6BobYnOTNXiQkroDqCEi6EzfGBv8lWtyZ0,1077
|
|
14
|
-
pico_ioc-2.0.0.dist-info/METADATA,sha256=ubMhg9j-hhpzo3Ok5ySrfRMudhgnJol-7SIDKgCbNsE,9624
|
|
15
|
-
pico_ioc-2.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
16
|
-
pico_ioc-2.0.0.dist-info/top_level.txt,sha256=_7_RLu616z_dtRw16impXn4Mw8IXe2J4BeX5912m5dQ,9
|
|
17
|
-
pico_ioc-2.0.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|