Skip to main content

wireme

wireme - tiny, typed dependency injection for Python

Tiny, typed dependency injection for Python.

CI Coverage: 100% PyPI version Supported Python versions License


Documentation: wireme.mghalix.com


Declare how a dependency is created once, then inject it into functions, methods, constructors, or FastAPI endpoints without turning the dependency container into an application framework.

Wireme resolves the graph and touches nothing else. It never validates, coerces, or serializes arguments, dependency results, or return values.

Installation

uv add wireme

With the optional FastAPI integration:

uv add 'wireme[fastapi]'

Wireme requires Python 3.12 or newer.

Sixty-second tour

Declare a factory, wire an entry point, and keep the dependency fully typed:

from typing import Annotated

from wireme import Wired, wire, wired


class Database:
    def write(self, value: str) -> None:
        print(f"writing: {value}")


def get_database() -> Database:
    return Database()


type DatabaseDep = Annotated[Database, wired(get_database)]


@wire
def create_user(username: str, *, database: DatabaseDep = Wired()) -> None:
    database.write(username)


create_user("mo")

Injected parameters are keyword-only and disappear from the public runtime signature. Callers see application inputs; Wireme resolves the rest.

Classes wire their constructors, and tests replace factories without monkeypatching consumers:

from wireme import override_dependency


@wire
class UserService:
    def __init__(self, *, database: DatabaseDep = Wired()) -> None:
        self._database = database

    def list_users(self) -> list[str]:
        return []


def get_test_database() -> Database:
    return Database()


with override_dependency(get_database, get_test_database):
    service = UserService()

The optional FastAPI integration lets FastAPI retain ownership of the request lifecycle while Wireme resolves the internal graph:

from fastapi import FastAPI

from wireme.fastapi import FromWeb


app = FastAPI()


@app.get("/users")
def list_users(*, service: FromWeb[UserService]) -> list[str]:
    return service.list_users()

Why Wireme

  • Four core names. wire, wired, Wired, and override_dependency.
  • Typed end to end. Reusable Annotated aliases keep declarations and static types together.
  • Hidden wiring. Injected parameters stay out of public signatures, editor call hints, and OpenAPI schemas.
  • Complete lifecycles. Sync, async, generator, and async-generator factories compose with deterministic cleanup.
  • Predictable values. Dependency injection never becomes implicit validation or coercion.
  • Clean tests. Overrides are nested-safe and restored after exceptions.

Learn more

The documentation contains the full guide, production recipes, and Wireme way. Every public capability also has a runnable entry in the example index.

Implementation

Wireme currently uses FastDepends internally for graph execution, caching, async dispatch, and resource lifecycles. That engine is an implementation detail: application code uses Wireme's API and does not need to learn or import FastDepends.

Versioning

Wireme follows SemVer with the strict 0.x mapping: below 1.0.0, a breaking change bumps minor and features or fixes bump patch. Published artifacts are immutable; a broken release is fixed by publishing a new version. See the release notes.

License

MIT

Download files

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

Source Distribution

wireme-0.2.2.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

wireme-0.2.2-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file wireme-0.2.2.tar.gz.

File metadata

  • Download URL: wireme-0.2.2.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for wireme-0.2.2.tar.gz
Algorithm Hash digest
SHA256 b954873d64b7c72040c01ae896c78b6c7eab643580d82f8a44d122ba0703aa42
MD5 e106af560d8c04cb639df5ba14040eb2
BLAKE2b-256 64595911018ca45879968dec980cefa57f341c2631a14e712e4e0832df20993e

See more details on using hashes here.

File details

Details for the file wireme-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: wireme-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for wireme-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0ae7c0fde15e31317ee79ecf23247b0768c8411674da4511921c44a8314e3e11
MD5 302a73121416aa0da385d9b0e39ab225
BLAKE2b-256 5193ad7374a06200ae5e930f1c39a63860417dabe6ae5ab07fa5e5afe40cf644

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page