Skip to main content

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 — Чудайкин Александр · Бюро автоматизации процессов

Metadata

Release files for archtool 2.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for archtool 2.1.1
File Size Uploaded Provenance Actions
archtool-2.1.1.tar.gz 100.3 kB Without provenance Details for archtool-2.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for archtool 2.1.1
File Interpreter ABI Platform Actions
archtool-2.1.1-py3-none-any.whl Python 3 none any Details for archtool-2.1.1-py3-none-any.whl

Total release size: 131.0 kB

Release files / archtool-2.1.1.tar.gz

Download URL archtool-2.1.1.tar.gz
Size 100.3 kB
Tags Source
SHA-256 checksum
How to use checksums
78470ce48fb17b06e09d574739794540733669ec1c964ceeec7ab5f5ff6b1a77
BLAKE2b-256 checksum
How to use checksums
ef6f6efdc0ce2e33dfd3ede5813b197b41b5af294abfa6aa8dd3a1432ccfe3bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / archtool-2.1.1-py3-none-any.whl

Download URL archtool-2.1.1-py3-none-any.whl
Size 30.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1819ad81e180d5f89faac791bb3e2ab77ca015590175828c831087bd1ffd3184
BLAKE2b-256 checksum
How to use checksums
9080f7ef8caaf05c97468756db7d314f034359144731d4bbd70082b581347bdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for archtool 2.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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