Skip to main content

wireme

wireme - tiny, typed dependency injection for Python

Tiny, typed dependency injection for Python. Resolve the graph. Touch nothing else.

Powered by FastDepends, Wireme keeps dependency injection explicit and small:

from wireme import Wired, override_dependency, wire, wired
  • @wire enables dependency resolution for a class constructor, function, or method.
  • wired(factory) declares how a dependency is created.
  • Wired() marks a reusable Annotated dependency as caller-optional.
  • override_dependency() temporarily replaces a dependency in tests.

Wireme only resolves dependencies. It never validates or coerces arguments, dependency results, or return values; application boundaries own those concerns.

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 dependency once, inject it anywhere. Injected parameters go after * and disappear from the public signature:

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")  # database is resolved automatically

Classes wire their constructors; tests swap factories:

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):
    UserService()  # built against the test database

With FastAPI, the same wired class plugs into endpoints while FastAPI keeps ownership of the request lifecycle:

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()

Documentation

Rendered documentation lives at wireme.mghalix.com, including recipes and the house style guide. The same pages are browsable in the repository; the guide covers one concept per page, in reading order:

Page What it covers
Getting started Install, wire a function, reusable dependencies
Wiring classes Constructor and method injection
The dependency graph Nesting, per-call caching, singletons
Resources Async factories and generator cleanup
Testing Overrides and explicit values
Side-effect dependencies Guards and auditing with requires
Protocol dependencies Depending on interfaces
FastAPI integration FromWeb, request-scoped resources, web overrides
Building integrations Wireme as your project's DI primitive

Every capability also has a small runnable example; see the example index.

Public API

Name Purpose
wire Decorate a class, function, or method and enable dependency resolution. Accepts side-effect dependencies through requires.
wired Declare a dependency factory and its per-call cache behavior.
Wired Mark an Annotated dependency as caller-optional.
override_dependency Temporarily replace a factory, with nested restoration.

The optional wireme.fastapi integration adds:

Name Purpose
FromWeb Annotate endpoint parameters with classes or wired aliases.
override_web_dependency Temporarily replace a web dependency, with nested restoration.

Why Wireme instead of importing FastDepends directly?

FastDepends provides the resolution engine. Wireme provides a deliberately small, opinionated facade with:

  • A cohesive wire, wired, and Wired vocabulary.
  • Strong return typing for sync, async, generator, and async-generator factories.
  • Reusable Annotated dependencies.
  • Injected parameters hidden from public runtime signatures.
  • Nested-safe dependency overrides.
  • A DI-only contract: values pass through unchanged.
  • A minimal backend-independent public namespace.

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, so the minor number is the breaking-change signal. Published artifacts are immutable; a broken release is fixed by publishing a new version.

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.0.tar.gz (11.2 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.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wireme-0.2.0.tar.gz
  • Upload date:
  • Size: 11.2 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.0.tar.gz
Algorithm Hash digest
SHA256 4680463a492377b59d1182edd08940662481da7ee45cd62f3e3c71514b32441b
MD5 1e1671ad78eafce754c39435b7cf2178
BLAKE2b-256 52da33e35ca071d108d636b25e0dcdc6eb5bafb31e395d94ec82393c3c09b5a6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wireme-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d69b120995322e2705519f938c31c4e12fa264cb124055a003b15228c648fd6
MD5 c11d20a43956f8338ea1945406665b44
BLAKE2b-256 d2059114302ea569ddffc5f0200ab616846a2243b5a201f8fbba5395b660bdd6

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.2

2 files

0.2.1

2 files

This release

0.2.0 This release

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