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.1.tar.gz (11.0 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.1-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wireme-0.2.1.tar.gz
  • Upload date:
  • Size: 11.0 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.1.tar.gz
Algorithm Hash digest
SHA256 e9e476d9e23f7f31ff6cead7f9b0841f324924bd4ac00db86d9e7d52d8c63442
MD5 4e58e3a09289cc39ea64ed4454b90aaa
BLAKE2b-256 886f23fccea2a82e5055a75cef0eed9392c5e39590767f898819916a48c9e197

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wireme-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b3c478d7a03b1751d8ec520410cfee1f73b4802bb8c8d4a757d035f3c18c5ffa
MD5 b8892a4744c23b06fdeec4b5d03d6a39
BLAKE2b-256 d09151ca9a1e4b7b095d4c3bc106d5c322aba1f720cc088a16a550503eeb6d14

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.2

2 files

This release

0.2.1 This release

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