Skip to main content

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.

PyPI version PyPI Stats CI Python versions

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. Deply reads it from deply.yaml in your project's root directory, or from a [tool.deply] table in pyproject.toml (Python 3.11+, available starting with Deply v1.3.2).

Starting with Deply v1.3.2, write a validated starter file from a packaged preset instead of hand-writing it:

deply init --list-presets
deply init --preset fastapi

Available presets: layered, django, fastapi, and flask. The command never overwrites an existing file unless you pass --force. Adjust the layer directories to your project, then validate with deply validate.

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

Without --config, Deply uses deply.yaml if it exists, otherwise pyproject.toml when it contains a [tool.deply] table. An explicit --config=pyproject.toml works as well. See the configuration guide for details.

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

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

The same configuration as a [tool.deply] table in pyproject.toml:

[tool.deply]
paths = ["/path/to/your/project"]
exclude_files = ['.*\.venv/.*']

[[tool.deply.layers]]
name = "models"

[[tool.deply.layers.collectors]]
type = "class_inherits"
base_class = "django.db.models.Model"

[[tool.deply.layers]]
name = "views"

[[tool.deply.layers.collectors]]
type = "file_regex"
regex = ".*/views_api.py"

[[tool.deply.layers]]
name = "services"

[[tool.deply.layers.collectors]]
type = "class_name_regex"
class_name_regex = ".*Service$"

[tool.deply.ruleset.views]
disallow_layer_dependencies = ["models"]

[tool.deply.ruleset.services]
disallow_external_imports = ["django", "requests"]

Code elements may belong to multiple layers. Deply checks every unique source and target layer pair, so layer and collector order does not change dependency or external-import results.

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

deply analyze validates the configuration before scanning project files and exits with status 1 when the configuration is invalid or analysis is incomplete because files cannot be read or parsed, no Python files are found, no code elements map to configured layers, or an import resolves to ambiguous internal module paths.

Every completed analysis report includes completeness metrics for discovered, excluded, parsed, mapped, and unmapped files; mapped and overlapping elements; and detected dependencies. Incomplete analysis prints the available metrics to standard error before exiting. With --report-format=json, invalid configuration and incomplete analysis also produce a structured error report. JSON schema v1 includes analysis status, configured rule IDs, source/target identities, layer pairs, and stable violation fingerprints for agent integrations. See the JSON contract for fields and identity guarantees. Distinct dependencies and configured rules at the same location are now preserved in every report, so totals may increase compared with previously collapsed findings.

CI Integration

Run Deply from pre-commit when Python files change:

repos:
  - repo: https://github.com/Vashkatsi/deply
    rev: v1.3.3
    hooks:
      - id: deply
        args: [--config=deply.yaml]

Run Deply in GitHub Actions with violations reported as annotations:

- uses: actions/checkout@v4
- uses: Vashkatsi/deply@v1
  with:
    config: deply.yaml

Other CI systems can install and run the CLI directly:

pip install deply
deply analyze --config=deply.yaml

The pre-commit hooks and GitHub Action are available starting with Deply v1.3.2. See CI integration for hook ids, action inputs, and version tags.

Violation Baseline

Accept reviewed architecture debt once and fail only on new relationships:

deply analyze --write-baseline=deply-baseline.json
deply analyze --baseline=deply-baseline.json --report-format=json

Creation requires complete analysis and never overwrites a file. Comparison adds new, existing, and resolved categories to JSON and fails on new violations or errors. Other formats show only new findings. Fingerprints identify relationships, so additional call sites for accepted relationships are also accepted. See baseline semantics and safe refresh. Baseline support is available starting with Deply v1.2.2.

Architecture Context

On a checkout/install that supports deply context --help, inspect one file before changing it:

deply context --file src/orders/service.py --config deply.yaml --report-format=json

The command analyzes the full configured project, then returns collected elements and all their layers, applicable rules with stable IDs, direct incoming/outgoing dependencies, related violations, and analysis/file status. JSON is the default and only format. Complete context for a mapped file exits 0 even with violations; unavailable or incomplete context exits 1. Static edges do not prove runtime impact, and uncollected elements are outside this graph.

After editing, run deply analyze (with the reviewed --baseline when available). See the context contract. Context is available starting with Deply v1.3.0.

Agent Skill

Deply v1.3.0 includes a portable Agent Skill at skills/deply-config/ for Codex, Claude Code, and other Agent Skills-compatible assistants. It helps an assistant inspect a Python project, generate deply.yaml using light, medium, or strict guidance, validate it with deply validate, run analysis, and add Makefile/CI/docs integration. These profiles belong to the Agent Skill; they are not built-in Deply CLI presets.

Use it with:

Use $deply-config to create and validate a Deply architecture config for this Python project.

See Agent Skill for installation instructions.

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: Resolve internal dependencies through modules, absolute and relative imports, aliases, and lexical bindings before checking layer boundaries.
  • External Import Restrictions: Prevent selected layers from importing framework, persistence, or SDK package roots through absolute imports. Relative imports are ignored.
  • Extensible and Configurable: Customize layers with built-in or custom collectors and supported rules.
  • Mermaid Diagrams: Visualize your architecture and dependencies with Mermaid diagrams.
  • Error Suppression: Suppress specific rule violations with inline comments.
  • Config Validation: Validate deply.yaml or pyproject.toml [tool.deply] explicitly or automatically before analysis.
  • CI Integration: Run Deply through the provided pre-commit hooks or GitHub Action.
  • SARIF Reports: Export findings for GitHub Code Scanning with deply analyze --report-format=sarif --output=deply.sarif. See the CLI guide for upload instructions and limitations.
  • Architecture Recipes: Copy and adapt documented configurations for 21 architecture and application patterns. The layered recipe and the Django, FastAPI, and Flask framework recipes also ship as deply init presets.

Existing v1 YAML configurations remain supported. Module-aware resolution removes unrelated same-name matches and can reveal previously missed violations. A known symbol prefix such as models.Project in models.Project.objects.all() resolves to the collected Project class without inferring Django runtime types. Wildcard imports, dynamic instance types, and general control-flow analysis remain unsupported. See Features for the resolution boundaries.

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 architecture
make mutation
make lint
make typing
make security
make pre-commit

Or run unittest directly:

python -m unittest discover tests

Roadmap

See the verified technical roadmap for current priorities, evidence, and implementation conditions.

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
  • Agent Skill - Install and use the Deply Config Agent Skill
  • Architecture Styles - Compare 21 architecture and application pattern recipes
  • FastAPI - Configure layered FastAPI boundaries
  • Full Stack FastAPI Template - Verified baseline for FastAPI's official template
  • Django - Configure Django model, view, and domain boundaries
  • Flask - Configure Flask route, blueprint, and persistence boundaries

Author

Archil Abuladze

License

See the LICENSE file for details.

Metadata

Release files for deply 1.3.3

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

Source distribution (sdist)

Source distribution for deply 1.3.3
File Size Uploaded Provenance Actions
deply-1.3.3.tar.gz 110.0 kB Without provenance Details for deply-1.3.3.tar.gz

Built distribution (wheel)

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

Total release size: 237.1 kB

Release files / deply-1.3.3.tar.gz

Download URL deply-1.3.3.tar.gz
Size 110.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e0fc8d5406aa027123e7dcbc34553626ed9c50817a72f648f5f11c5052bb6f53
BLAKE2b-256 checksum
How to use checksums
58725d8b8d8ce3df171fbe48797c990c0a05778e3f3740bc140c573b7d330b7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / deply-1.3.3-py3-none-any.whl

Download URL deply-1.3.3-py3-none-any.whl
Size 127.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ccc7ebcf0e98deb3baf83f419581d0fe8e3491134cf33d3e685c21398656e07
BLAKE2b-256 checksum
How to use checksums
3558ce15e741799f591309a7618de00136202f1f3a7e627f3bb444e5e8b73a03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for deply 1.3.3

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.

Release history Release notifications | RSS feed

This release

1.3.3 This release

2 release files No provenance

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