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.0.1.tar.gz (93.4 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.0.1-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for archtool-2.0.1.tar.gz
Algorithm Hash digest
SHA256 43a44ff2b076fb7b694de5aad628c2da5c7a968d99171fb927f8137f3ba29403
MD5 fa2b4bb2321076cc96ede989d22f8536
BLAKE2b-256 060c17c7188b9bfd4cdd616570bfa090ab27f80093a2d323601fbb721f622e7c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: archtool-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 29.3 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.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bd7b1b81f72d5c548600ac98c35930d301cba9a3865374a5bd2ba1fb1b32840d
MD5 48ba2f3d6fdb65838f13dc40bed8adec
BLAKE2b-256 e169e836719490422d2d173c905e53371b7599528dc2733eabd68dac1c9aeaed

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