Skip to main content

Auto-wiring DI + layer enforcement for Python. Define interfaces, write implementations — archtool assembles everything.

Project description

archtool

Auto-wiring dependency injection and layer enforcement for Python.
Define interfaces. Write implementations. archtool assembles everything at startup — zero registration code, zero wiring boilerplate.

PyPI CI Python MIT


The problem

Every Python backend eventually grows into this:

# entrypoints/run.py
user_repo = UserRepo()
order_repo = OrderRepo()
user_service = UserService()
user_service.repo = user_repo          # don't forget this
order_service = OrderService()
order_service.repo = order_repo
order_service.user_service = user_service  # or this
# ... 40 more lines

Manual wiring doesn't scale. Every new dependency means touching the entrypoint. Every new dev breaks it.

The solution

from pathlib import Path
from archtool.dependency_injector import DependencyInjector
from archtool.global_types import AppModule

injector = DependencyInjector(
    modules_list=[
        AppModule("app.users"),
        AppModule("app.orders"),
        AppModule("app.payments"),
    ],
    project_root=Path(__file__).parent.parent,
)
injector.inject()

archtool scans your modules, discovers every interface–implementation pair, instantiates them in dependency order, and wires everything together.


How it works

Declare the dependency as a class annotation on the concrete class:

# app/orders/services.py
from app.users.interfaces import UserServiceABC   # cross-module dep
from .interfaces import OrderServiceABC, OrderRepoABC

class OrderService(OrderServiceABC):
    repo: OrderRepoABC        # archtool sets this
    user_svc: UserServiceABC  # and this — from another module

    def place(self, user_id: str, items: list) -> dict:
        user = self.user_svc.get(user_id)
        return {"user": user, "items": items}

Two-pass injection algorithm:

  1. Pass 1 — scans interfaces.py in each module, finds abstract/concrete pairs, instantiates concretions, builds the registry
  2. Pass 2 — reads class-level annotations from each instance, looks up the registry, calls setattr

No container class. No decorator. No __init__ parameters. If the class is in the right file and inherits the right base — it's wired.


Layer enforcement

Declare your layers and archtool enforces boundaries at startup:

injector = DependencyInjector(
    modules_list=[...],
    layers=default_layers,  # Infrastructure → Domain → Application → Presentation
)
injector.inject()  # raises TopLevelLayerUsingException if a boundary is crossed

A service depending on a controller, a domain class importing infrastructure directly — caught before they reach production.


Install

pip install archtool

Supports Python 3.10 · 3.11 · 3.12 · 3.13.


Quickstart

archtool init myapp
cd myapp
pip install -e ".[dev]"
archtool add-module orders
archtool add-module payments
python entrypoints/run.py

archtool init scaffolds a full layered-architecture project. archtool add-module creates the module files and auto-registers it — no manual edits required.


Documentation

0nliner.github.io/archtool


License

MIT — Чудайкин Александр · Бюро автоматизации процессов

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

archtool-2.1.0.tar.gz (99.3 kB view details)

Uploaded Source

Built Distribution

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

archtool-2.1.0-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

Details for the file archtool-2.1.0.tar.gz.

File metadata

  • Download URL: archtool-2.1.0.tar.gz
  • Upload date:
  • Size: 99.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for archtool-2.1.0.tar.gz
Algorithm Hash digest
SHA256 9c72e29b06a5a2b9100efd4bf00373c7cffc89b71ab2c22e2f23c3c9d73b208f
MD5 60a2bfa4929a6a6ecc3711ee3fd4fd66
BLAKE2b-256 95f1e25e0b5eabfffa063e927be18dccbd449f6fb45a671d4bf5a7a78a4849b3

See more details on using hashes here.

File details

Details for the file archtool-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: archtool-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for archtool-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fca881885869241638b42130740b66c8393041a246c20bf0521fb87e369dea6
MD5 57e48c4d813be4ea463770c961c735e8
BLAKE2b-256 6fa11ab0fea13413f82d7fe166d7299a0e1c57c3f7f84415f3a7c166dbe8e65c

See more details on using hashes here.

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