A Dependency Injection framework for Python.
Project description
spritze
A Dependency Injection framework for Python.
License
Apache 2.0 — see LICENSE
Features
- Modern, type-safe dependency injection for Python 3.11+
- Scopes: APP (singleton), REQUEST (per-request)
- Sync & async support, context managers
- No global state, explicit containers
- Decorator-based provider registration
- Easy integration with FastAPI, Flask, Litestar, etc.
Installation
uv add spritze
# or
pip install spritze
Usage
Here's a quick example of how to use Spritze:
from spritze.core.container import Container
from spritze.core.entities import Depends, Scope
from spritze.decorators import provide
class MyService:
def __init__(self, value: int):
self.value = value
class AppContainer(Container):
@provide(scope=Scope.APP)
def provide_config_value(self) -> int:
return 123
@provide(scope=Scope.REQUEST)
def provide_my_service(self, config_value: int) -> MyService:
return MyService(value=config_value)
app_container = AppContainer()
@app_container.injector()
def my_function(service: Depends[MyService]):
return f"Service value: {service.value}"
if __name__ == "__main__":
result = my_function()
print(result) # Output: Service value: 123
Examples
See the examples/ directory for real-world usage with Flask, Litestar, etc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spritze-0.1.0.tar.gz.
File metadata
- Download URL: spritze-0.1.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
965a4e5cdfaaaf8025b931603d27a5ee3851ef98ea259fb4e07ecd51afe835e5
|
|
| MD5 |
4176796389118a0338cfc8583923d3c6
|
|
| BLAKE2b-256 |
58023c9c4b8bf4c97a72601c50e925d9900f92d941fd869f26c0fa29f8eaeebf
|
Provenance
The following attestation bundles were made for spritze-0.1.0.tar.gz:
Publisher:
release.yml on aSel1x/spritze
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spritze-0.1.0.tar.gz -
Subject digest:
965a4e5cdfaaaf8025b931603d27a5ee3851ef98ea259fb4e07ecd51afe835e5 - Sigstore transparency entry: 324305739
- Sigstore integration time:
-
Permalink:
aSel1x/spritze@f40dfc4449a74a21356e82969b560e5f8f873163 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/aSel1x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f40dfc4449a74a21356e82969b560e5f8f873163 -
Trigger Event:
release
-
Statement type:
File details
Details for the file spritze-0.1.0-py3-none-any.whl.
File metadata
- Download URL: spritze-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c80e93c88bbe147af99bd55f56bdd021fc70ac9dd9559067b819cdd440889562
|
|
| MD5 |
8c117c7c9f44a2b60dfb067431d5207a
|
|
| BLAKE2b-256 |
ce531aaa13c0f2199460100c39f632f69e4fb2e8a4bd5160f025331eee9ecd65
|
Provenance
The following attestation bundles were made for spritze-0.1.0-py3-none-any.whl:
Publisher:
release.yml on aSel1x/spritze
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spritze-0.1.0-py3-none-any.whl -
Subject digest:
c80e93c88bbe147af99bd55f56bdd021fc70ac9dd9559067b819cdd440889562 - Sigstore transparency entry: 324305752
- Sigstore integration time:
-
Permalink:
aSel1x/spritze@f40dfc4449a74a21356e82969b560e5f8f873163 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/aSel1x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f40dfc4449a74a21356e82969b560e5f8f873163 -
Trigger Event:
release
-
Statement type: