Skip to main content

A Dependency Injection framework for Python.

Project description

spritze

CI Code Quality PyPI version License: Apache 2.0

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spritze-0.1.0.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spritze-0.1.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

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

Hashes for spritze-0.1.0.tar.gz
Algorithm Hash digest
SHA256 965a4e5cdfaaaf8025b931603d27a5ee3851ef98ea259fb4e07ecd51afe835e5
MD5 4176796389118a0338cfc8583923d3c6
BLAKE2b-256 58023c9c4b8bf4c97a72601c50e925d9900f92d941fd869f26c0fa29f8eaeebf

See more details on using hashes here.

Provenance

The following attestation bundles were made for spritze-0.1.0.tar.gz:

Publisher: release.yml on aSel1x/spritze

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for spritze-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c80e93c88bbe147af99bd55f56bdd021fc70ac9dd9559067b819cdd440889562
MD5 8c117c7c9f44a2b60dfb067431d5207a
BLAKE2b-256 ce531aaa13c0f2199460100c39f632f69e4fb2e8a4bd5160f025331eee9ecd65

See more details on using hashes here.

Provenance

The following attestation bundles were made for spritze-0.1.0-py3-none-any.whl:

Publisher: release.yml on aSel1x/spritze

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page