Deply is a static code analysis tool for Python that helps you communicate, visualize and enforce architectural decisions in your projects. You can freely define your architectural layers over classes and which rules should apply to them.
For example, you can use Deply to ensure that modules/packages in your project are truly independent of each other to make them easier to reuse.
Deply can be used in a CI pipeline to make sure a pull request does not violate any of the architectural rules you defined. With the optional Mermaid formatter you can visualize your layers, rules and violations.
You can find the documentation in the /doc directory or visit the doc page: https://vashkatsi.github.io/deply
You can install Deply via pip:
pip install deplyOnce you have installed Deply, you will need to create a configuration file, where you define your layers and communication ruleset. This configuration file is written in YAML and, by default, is stored with the name deply.yaml in your project's root directory.
When you have this file, you can analyse your code by running the analyze command:
deply analyze
# which is equivalent to
deply analyze --config-file=deply.yamlIn order to run Deply you need at least Python 3.8.
Here's a simple example of a deply.yaml configuration file:
deply:
paths:
- /path/to/your/project
exclude_files:
- ".*\\.venv/.*"
layers:
- name: models
collectors:
- type: class_inherits
base_class: "django.db.models.Model"
- name: views
collectors:
- type: file_regex
regex: ".*/views_api.py"
- name: services
collectors:
- type: class_name_regex
class_name_regex: ".*Service$"
ruleset:
views:
disallow_layer_dependencies:
- models# Basic usage
deply analyze
# With a specific config file
deply analyze --config=custom_config.yaml
# Generate a Mermaid diagram
deply analyze --mermaid
# Get help
deply --help- Layer-Based Analysis: Define project layers and restrict their dependencies to enforce modularity.
- Dynamic Layer Configuration: Easily configure collectors for each layer using file patterns, class inheritance, and logical conditions.
- Cross-Layer Dependency Rules: Specify rules to disallow certain layers from accessing others.
- Extensible and Configurable: Customize layers and rules for any Python project setup.
- Mermaid Diagrams: Visualize your architecture and dependencies with Mermaid diagrams.
- Error Suppression: Suppress specific rule violations with inline comments.
Deply provides options to suppress rule violations using comments in your code:
# Line-level suppression
user.get() # deply:ignore:DISALLOW_LAYER_DEPENDENCIES
# File-level suppression (at the top of the file)
# deply:ignore-file:ENFORCE_INHERITANCEFeel free to contribute to this project by opening an issue or submitting a pull request! Together, we can make Deply a powerful tool for the Python community.
To test the tool, use unittest:
python -m unittest discover testsA plan to evolve Deply into a must-have architectural guardian for Python projects:
🔲 Skip violations skip_violations
🔲 Interactive config setup (deply init wizard)
🔲 GitHub Actions/GitLab CI templates
✅ # deply:ignore suppression comments
🔲 Config validation command (deply validate)
✅ Parallel file analysis
✅ Custom collectors system
🔲 Dependency graph caching
🔲 Custom rules system
🔲 FastAPI/Django/Flask presets
🔲 Third-party import restrictions (disallow_external_imports)
- Core Concepts - Explains layers, rules and violations in more details.
- Configuration - Reference for all available settings in a depfile
- Collectors - Reference for which collectors are available in Deply to define your layers.
- Rules - Lists the different rule types supported by Deply
- Mermaid Diagrams - Overview of the diagram generation capabilities
- Command Line Interface - Advice for using the CLI
See the LICENSE file for details.