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

Uploaded Python 3

File details

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

File metadata

  • Download URL: archtool-2.1.1.tar.gz
  • Upload date:
  • Size: 100.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.1.tar.gz
Algorithm Hash digest
SHA256 78470ce48fb17b06e09d574739794540733669ec1c964ceeec7ab5f5ff6b1a77
MD5 3c10f185f083e34ad4eb6e74309787b4
BLAKE2b-256 ef6f6efdc0ce2e33dfd3ede5813b197b41b5af294abfa6aa8dd3a1432ccfe3bc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: archtool-2.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1819ad81e180d5f89faac791bb3e2ab77ca015590175828c831087bd1ffd3184
MD5 9b7528b40a633e7b6980322f1b87f468
BLAKE2b-256 9080f7ef8caaf05c97468756db7d314f034359144731d4bbd70082b581347bdd

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