A Python tool to visualize + enforce dependencies, using modular architecture π Open source π Installable via pip π§ Able to be adopted incrementally - β‘ Implemented with no runtime impact βΎοΈ Interoperable with your existing systems π¦ Written in rust
Tach is a Python tool to enforce dependencies and interfaces, written in Rust.
Tach is inspired by the modular monolith architecture.
https://github.com/user-attachments/assets/11eec4a1-f80a-4f13-9ff3-91a9760133b6
Tach can enforce:
Tach is:
pip install tach
Tach will guide you through initial project setup.
Run:
tach init
After an introductory message, you will see a file tree interface allowing you to interactively configure your project.
Use the arrow keys to navigate, and mark each module boundary with βEnterβ. You can mark all of your top-level Python packages, or just a few that you want to track.
FAQ: What is a module?
If your Python code lives below your project root, or if you are working in a monorepo with multiple Python packages, mark your Python source roots using the βsβ key.
Tach comes with a cli command to enforce the boundaries that you just set up! From the root of your Python project, run:
tach check
You will see:
β
All modules validated!
You can validate that Tach is working by:
depends_on
key in tach.toml
, or marking it as deprecatedGive both a try and run tach check
again. This will generate an error:
β tach/check.py[L8]: Cannot use 'tach.filesystem'. Module 'tach' cannot depend on 'tach.filesystem'.
Each error indicates an import which violates your dependencies. If your terminal supports hyperlinks, click on the file path to go directly to the error.
When an error is detected, tach check
will exit with a non-zero code. It can be easily integrated with CI/CD, Pre-commit hooks, and VS Code, and more!
Visualize your dependency graph.
tach show [--web]
Tach will generate a graph of your dependencies. Hereβs what this looks like for Tach:
Note that this graph is generated remotely with the contents of your tach.toml
when running tach show --web
.
If you would like to use the GraphViz DOT format locally, simply running tach show
will generate tach_module_graph.dot
in your working directory.
You can view the dependencies and usages for a given path:
tach report my_package/
# OR
tach report my_module.py
e.g.:
> tach report python/tach/filesystem
[Dependencies of 'python/tach/filesystem']
python/tach/filesystem/install.py[L6]: Import 'tach.hooks.build_pre_commit_hook_content'
python/tach/filesystem/project.py[L5]: Import 'tach.constants.CONFIG_FILE_NAME'
...
-------------------------------
[Usages of 'python/tach/filesystem']
python/tach/cache/access.py[L8]: Import 'tach.filesystem.find_project_config_root'
python/tach/cache/setup.py[L7]: Import 'tach.filesystem.find_project_config_root'
...
Tach also supports:
More info in the docs. Tach logs anonymized usage statistics which can be opted out of.
If you have any feedback, weβd love to talk!
If you have any questions or run into any issues, let us know by either reaching out on Discord or submitting a Github Issue!