anydi 0.65.0__tar.gz → 0.67.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.
- {anydi-0.65.0 → anydi-0.67.0}/PKG-INFO +29 -29
- {anydi-0.65.0 → anydi-0.67.0}/README.md +28 -28
- {anydi-0.65.0 → anydi-0.67.0}/anydi/_container.py +22 -13
- {anydi-0.65.0 → anydi-0.67.0}/anydi/_resolver.py +1 -1
- {anydi-0.65.0 → anydi-0.67.0}/pyproject.toml +1 -1
- {anydi-0.65.0 → anydi-0.67.0}/anydi/__init__.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/_async_lock.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/_context.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/_decorators.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/_injector.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/_marker.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/_module.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/_provider.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/_scanner.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/_types.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/ext/__init__.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/ext/django/__init__.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/ext/fastapi.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/ext/faststream.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/ext/pydantic_settings.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/ext/pytest_plugin.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/ext/starlette/__init__.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/ext/starlette/middleware.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/ext/typer.py +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/py.typed +0 -0
- {anydi-0.65.0 → anydi-0.67.0}/anydi/testing.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: anydi
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.67.0
|
|
4
4
|
Summary: Dependency Injection library
|
|
5
5
|
Keywords: dependency injection,dependencies,di,async,asyncio,application
|
|
6
6
|
Author: Anton Ruhlov
|
|
@@ -37,11 +37,11 @@ Description-Content-Type: text/markdown
|
|
|
37
37
|
|
|
38
38
|
<div style="text-align: center;">
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
Simple Dependency Injection library that uses Python type annotations.
|
|
41
41
|
|
|
42
42
|
[](https://github.com/antonrh/anydi/actions/workflows/ci.yml)
|
|
43
43
|
[](https://codecov.io/gh/antonrh/anydi)
|
|
44
|
-
[](https://anydi.readthedocs.io/en/
|
|
44
|
+
[](https://anydi.readthedocs.io/en/stable/)
|
|
45
45
|
[](https://codspeed.io/antonrh/anydi?utm_source=badge)
|
|
46
46
|
|
|
47
47
|
</div>
|
|
@@ -53,21 +53,21 @@ http://anydi.readthedocs.io/
|
|
|
53
53
|
|
|
54
54
|
---
|
|
55
55
|
|
|
56
|
-
`AnyDI` is a
|
|
56
|
+
`AnyDI` is a simple Dependency Injection library for Python 3.10+. It works with sync and async applications and uses type annotations ([PEP 484](https://peps.python.org/pep-0484/)).
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
Main features:
|
|
59
59
|
|
|
60
|
-
* **Type-safe**:
|
|
61
|
-
* **Async
|
|
62
|
-
* **
|
|
63
|
-
* **Simple**:
|
|
64
|
-
* **Fast**:
|
|
65
|
-
* **Named**: `Annotated[...]`
|
|
66
|
-
* **
|
|
67
|
-
* **Modular**:
|
|
68
|
-
* **
|
|
69
|
-
* **
|
|
70
|
-
* **
|
|
60
|
+
* **Type-safe**: Uses type hints for dependency resolution.
|
|
61
|
+
* **Async support**: Works with both sync and async code.
|
|
62
|
+
* **Scopes**: Provides singleton, transient, and request scopes. Supports custom scope definitions.
|
|
63
|
+
* **Simple**: Minimal boilerplate with straightforward API.
|
|
64
|
+
* **Fast**: Low overhead dependency resolution.
|
|
65
|
+
* **Named providers**: Use `Annotated[...]` for multiple providers per type.
|
|
66
|
+
* **Resource management**: Context manager protocol support for lifecycle management.
|
|
67
|
+
* **Modular**: Container and module composition for large applications.
|
|
68
|
+
* **Auto-scan**: Automatic discovery of injectable callables.
|
|
69
|
+
* **Framework integrations**: Extensions for popular frameworks.
|
|
70
|
+
* **Testing**: Provider override mechanism for test isolation.
|
|
71
71
|
|
|
72
72
|
## Installation
|
|
73
73
|
|
|
@@ -266,23 +266,23 @@ urlpatterns = [
|
|
|
266
266
|
]
|
|
267
267
|
```
|
|
268
268
|
|
|
269
|
-
##
|
|
269
|
+
## Learn More
|
|
270
270
|
|
|
271
|
-
|
|
271
|
+
Want to know more? Here are helpful resources:
|
|
272
272
|
|
|
273
273
|
**Core Documentation:**
|
|
274
|
-
- [Core Concepts](https://anydi.readthedocs.io/en/
|
|
275
|
-
- [Providers](https://anydi.readthedocs.io/en/
|
|
276
|
-
- [Scopes](https://anydi.readthedocs.io/en/
|
|
277
|
-
- [Dependency Injection](https://anydi.readthedocs.io/en/
|
|
278
|
-
- [Testing](https://anydi.readthedocs.io/en/
|
|
274
|
+
- [Core Concepts](https://anydi.readthedocs.io/en/stable/concepts/) - Learn about containers, providers, scopes, and dependency injection
|
|
275
|
+
- [Providers](https://anydi.readthedocs.io/en/stable/usage/providers/) - How to register providers and manage resources
|
|
276
|
+
- [Scopes](https://anydi.readthedocs.io/en/stable/usage/scopes/) - How to use built-in and custom scopes
|
|
277
|
+
- [Dependency Injection](https://anydi.readthedocs.io/en/stable/usage/injection/) - Different ways to inject dependencies
|
|
278
|
+
- [Testing](https://anydi.readthedocs.io/en/stable/usage/testing/) - How to test your code with provider overrides
|
|
279
279
|
|
|
280
280
|
**Framework Integrations:**
|
|
281
|
-
- [FastAPI](https://anydi.readthedocs.io/en/
|
|
282
|
-
- [Django](https://anydi.readthedocs.io/en/
|
|
283
|
-
- [FastStream](https://anydi.readthedocs.io/en/
|
|
284
|
-
- [Typer](https://anydi.readthedocs.io/en/
|
|
285
|
-
- [Pydantic Settings](https://anydi.readthedocs.io/en/
|
|
281
|
+
- [FastAPI](https://anydi.readthedocs.io/en/stable/extensions/fastapi/) - How to use with FastAPI
|
|
282
|
+
- [Django](https://anydi.readthedocs.io/en/stable/extensions/django/) - How to use with Django and Django Ninja
|
|
283
|
+
- [FastStream](https://anydi.readthedocs.io/en/stable/extensions/faststream/) - How to use with message brokers
|
|
284
|
+
- [Typer](https://anydi.readthedocs.io/en/stable/extensions/typer/) - How to use in CLI applications
|
|
285
|
+
- [Pydantic Settings](https://anydi.readthedocs.io/en/stable/extensions/pydantic_settings/) - How to manage configuration
|
|
286
286
|
|
|
287
287
|
**Full Documentation:**
|
|
288
|
-
- [Read the Docs](https://anydi.readthedocs.io/) -
|
|
288
|
+
- [Read the Docs](https://anydi.readthedocs.io/) - All documentation with examples and guides
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
<div style="text-align: center;">
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Simple Dependency Injection library that uses Python type annotations.
|
|
6
6
|
|
|
7
7
|
[](https://github.com/antonrh/anydi/actions/workflows/ci.yml)
|
|
8
8
|
[](https://codecov.io/gh/antonrh/anydi)
|
|
9
|
-
[](https://anydi.readthedocs.io/en/
|
|
9
|
+
[](https://anydi.readthedocs.io/en/stable/)
|
|
10
10
|
[](https://codspeed.io/antonrh/anydi?utm_source=badge)
|
|
11
11
|
|
|
12
12
|
</div>
|
|
@@ -18,21 +18,21 @@ http://anydi.readthedocs.io/
|
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
21
|
-
`AnyDI` is a
|
|
21
|
+
`AnyDI` is a simple Dependency Injection library for Python 3.10+. It works with sync and async applications and uses type annotations ([PEP 484](https://peps.python.org/pep-0484/)).
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Main features:
|
|
24
24
|
|
|
25
|
-
* **Type-safe**:
|
|
26
|
-
* **Async
|
|
27
|
-
* **
|
|
28
|
-
* **Simple**:
|
|
29
|
-
* **Fast**:
|
|
30
|
-
* **Named**: `Annotated[...]`
|
|
31
|
-
* **
|
|
32
|
-
* **Modular**:
|
|
33
|
-
* **
|
|
34
|
-
* **
|
|
35
|
-
* **
|
|
25
|
+
* **Type-safe**: Uses type hints for dependency resolution.
|
|
26
|
+
* **Async support**: Works with both sync and async code.
|
|
27
|
+
* **Scopes**: Provides singleton, transient, and request scopes. Supports custom scope definitions.
|
|
28
|
+
* **Simple**: Minimal boilerplate with straightforward API.
|
|
29
|
+
* **Fast**: Low overhead dependency resolution.
|
|
30
|
+
* **Named providers**: Use `Annotated[...]` for multiple providers per type.
|
|
31
|
+
* **Resource management**: Context manager protocol support for lifecycle management.
|
|
32
|
+
* **Modular**: Container and module composition for large applications.
|
|
33
|
+
* **Auto-scan**: Automatic discovery of injectable callables.
|
|
34
|
+
* **Framework integrations**: Extensions for popular frameworks.
|
|
35
|
+
* **Testing**: Provider override mechanism for test isolation.
|
|
36
36
|
|
|
37
37
|
## Installation
|
|
38
38
|
|
|
@@ -231,23 +231,23 @@ urlpatterns = [
|
|
|
231
231
|
]
|
|
232
232
|
```
|
|
233
233
|
|
|
234
|
-
##
|
|
234
|
+
## Learn More
|
|
235
235
|
|
|
236
|
-
|
|
236
|
+
Want to know more? Here are helpful resources:
|
|
237
237
|
|
|
238
238
|
**Core Documentation:**
|
|
239
|
-
- [Core Concepts](https://anydi.readthedocs.io/en/
|
|
240
|
-
- [Providers](https://anydi.readthedocs.io/en/
|
|
241
|
-
- [Scopes](https://anydi.readthedocs.io/en/
|
|
242
|
-
- [Dependency Injection](https://anydi.readthedocs.io/en/
|
|
243
|
-
- [Testing](https://anydi.readthedocs.io/en/
|
|
239
|
+
- [Core Concepts](https://anydi.readthedocs.io/en/stable/concepts/) - Learn about containers, providers, scopes, and dependency injection
|
|
240
|
+
- [Providers](https://anydi.readthedocs.io/en/stable/usage/providers/) - How to register providers and manage resources
|
|
241
|
+
- [Scopes](https://anydi.readthedocs.io/en/stable/usage/scopes/) - How to use built-in and custom scopes
|
|
242
|
+
- [Dependency Injection](https://anydi.readthedocs.io/en/stable/usage/injection/) - Different ways to inject dependencies
|
|
243
|
+
- [Testing](https://anydi.readthedocs.io/en/stable/usage/testing/) - How to test your code with provider overrides
|
|
244
244
|
|
|
245
245
|
**Framework Integrations:**
|
|
246
|
-
- [FastAPI](https://anydi.readthedocs.io/en/
|
|
247
|
-
- [Django](https://anydi.readthedocs.io/en/
|
|
248
|
-
- [FastStream](https://anydi.readthedocs.io/en/
|
|
249
|
-
- [Typer](https://anydi.readthedocs.io/en/
|
|
250
|
-
- [Pydantic Settings](https://anydi.readthedocs.io/en/
|
|
246
|
+
- [FastAPI](https://anydi.readthedocs.io/en/stable/extensions/fastapi/) - How to use with FastAPI
|
|
247
|
+
- [Django](https://anydi.readthedocs.io/en/stable/extensions/django/) - How to use with Django and Django Ninja
|
|
248
|
+
- [FastStream](https://anydi.readthedocs.io/en/stable/extensions/faststream/) - How to use with message brokers
|
|
249
|
+
- [Typer](https://anydi.readthedocs.io/en/stable/extensions/typer/) - How to use in CLI applications
|
|
250
|
+
- [Pydantic Settings](https://anydi.readthedocs.io/en/stable/extensions/pydantic_settings/) - How to manage configuration
|
|
251
251
|
|
|
252
252
|
**Full Documentation:**
|
|
253
|
-
- [Read the Docs](https://anydi.readthedocs.io/) -
|
|
253
|
+
- [Read the Docs](https://anydi.readthedocs.io/) - All documentation with examples and guides
|
|
@@ -458,21 +458,14 @@ class Container:
|
|
|
458
458
|
)
|
|
459
459
|
has_default = default is not NOT_SET
|
|
460
460
|
|
|
461
|
-
# Check if provider exists before attempting to register (for scoped only)
|
|
462
|
-
was_auto_registered = (
|
|
463
|
-
is_scoped and parameter.annotation not in self._providers
|
|
464
|
-
)
|
|
465
|
-
|
|
466
461
|
try:
|
|
467
462
|
sub_provider = self._get_or_register_provider(parameter.annotation)
|
|
468
463
|
except LookupError as exc:
|
|
469
464
|
if (has_defaults and parameter.name in defaults) or has_default:
|
|
470
465
|
continue
|
|
471
|
-
# For request/custom
|
|
472
|
-
#
|
|
466
|
+
# For scoped (request/custom) dependencies, allow unresolved parameters
|
|
467
|
+
# that will be provided via context.set()
|
|
473
468
|
if is_scoped:
|
|
474
|
-
# Add to unresolved list to provide better error messages
|
|
475
|
-
# and prevent infinite recursion
|
|
476
469
|
self._resolver.add_unresolved(parameter.annotation)
|
|
477
470
|
parameters.append(
|
|
478
471
|
ProviderParameter(
|
|
@@ -480,8 +473,8 @@ class Container:
|
|
|
480
473
|
annotation=parameter.annotation,
|
|
481
474
|
default=default,
|
|
482
475
|
has_default=has_default,
|
|
483
|
-
provider=None,
|
|
484
|
-
shared_scope=True,
|
|
476
|
+
provider=None,
|
|
477
|
+
shared_scope=True,
|
|
485
478
|
)
|
|
486
479
|
)
|
|
487
480
|
continue
|
|
@@ -493,9 +486,25 @@ class Container:
|
|
|
493
486
|
if sub_provider.scope not in scope_provider:
|
|
494
487
|
scope_provider[sub_provider.scope] = sub_provider
|
|
495
488
|
|
|
496
|
-
#
|
|
497
|
-
|
|
489
|
+
# For scoped dependencies with same scope: if auto-registered provider
|
|
490
|
+
# has unresolved parameters, defer to context.set() instead
|
|
491
|
+
if (
|
|
492
|
+
is_scoped
|
|
493
|
+
and sub_provider.scope == scope
|
|
494
|
+
and any(p.provider is None for p in sub_provider.parameters)
|
|
495
|
+
):
|
|
498
496
|
self._resolver.add_unresolved(parameter.annotation)
|
|
497
|
+
parameters.append(
|
|
498
|
+
ProviderParameter(
|
|
499
|
+
name=parameter.name,
|
|
500
|
+
annotation=parameter.annotation,
|
|
501
|
+
default=default,
|
|
502
|
+
has_default=has_default,
|
|
503
|
+
provider=None,
|
|
504
|
+
shared_scope=True,
|
|
505
|
+
)
|
|
506
|
+
)
|
|
507
|
+
continue
|
|
499
508
|
|
|
500
509
|
parameters.append(
|
|
501
510
|
ProviderParameter(
|
|
@@ -299,7 +299,7 @@ class Resolver:
|
|
|
299
299
|
create_lines.append(" if compiled is None:")
|
|
300
300
|
create_lines.append(
|
|
301
301
|
" provider = "
|
|
302
|
-
"container._get_or_register_provider(_param_annotations[{idx}])"
|
|
302
|
+
f"container._get_or_register_provider(_param_annotations[{idx}])"
|
|
303
303
|
)
|
|
304
304
|
create_lines.append(
|
|
305
305
|
" compiled = "
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|