Skip to main content

A tool to enforce architectural patterns in python projects

Project description

Deply

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.

Static Badge Static Badge Static Badge Static Badge Static Badge

Documentation

You can find the documentation in the /doc directory or visit the doc page: https://vashkatsi.github.io/deply

Getting Started

You can install Deply via pip:

pip install deply

Once 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=deply.yaml

In order to run Deply you need at least Python 3.8. Supported and tested versions: Python 3.8 to 3.14.

Example Configuration

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

    services:
      disallow_external_imports:
        - django
        - requests

Command-Line Usage

# Basic usage
deply analyze

# With a specific config file
deply analyze --config=custom_config.yaml

# Validate configuration only
deply validate --config=custom_config.yaml

# Generate a Mermaid diagram
deply analyze --mermaid

# Get help
deply --help

Features

  • 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.
  • External Import Restrictions: Prevent selected layers from importing framework, persistence, or SDK packages.
  • 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.
  • Config Validation: Validate deply.yaml without running project analysis.

Error Suppression

Deply provides options to suppress rule violations using comments in your code:

# Line-level suppression
user.get()  # deply:ignore:DISALLOW_LAYER_DEPENDENCIES
import requests  # deply:ignore:DISALLOWED_EXTERNAL_IMPORT

# File-level suppression (at the top of the file)
# deply:ignore-file:ENFORCE_INHERITANCE

How to Contribute

Feel 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.

Running Tests

Use the following commands for local quality checks:

make check
make test
make mutation
make lint
make typing
make security
make pre-commit

Or run unittest directly:

python -m unittest discover tests

Roadmap 🚀

A 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
🔲 LLM skill creation helpers ✅ Third-party import restrictions (disallow_external_imports)

Further Documentation

  • 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

Author

Archil Abuladze

License

See the LICENSE file for details.

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

deply-0.9.1.tar.gz (54.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deply-0.9.1-py3-none-any.whl (78.2 kB view details)

Uploaded Python 3

File details

Details for the file deply-0.9.1.tar.gz.

File metadata

  • Download URL: deply-0.9.1.tar.gz
  • Upload date:
  • Size: 54.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for deply-0.9.1.tar.gz
Algorithm Hash digest
SHA256 8095dbb4bb5827a12601a56c938b42e9c0a5e11cb290238d9764b48519265e1f
MD5 505b4a33de309203daf7d5ade1bd9fee
BLAKE2b-256 6abad7a6746cedb594651e8c757673cebf2d89a20838cbaf012e429295ccedd0

See more details on using hashes here.

File details

Details for the file deply-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: deply-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 78.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for deply-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8676f83631c795be472f997bb7a2e16c3b436843fed92a37597dc8229b89b3b6
MD5 412b8a64447e5b0c5f119e3189ab9be7
BLAKE2b-256 e7cf7f6de5a7d0c795305a385a64f64551144fd10823400ea6e5ceaa6955ffde

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