Get pdl running in your project in three steps.
Step 1: Create a Config File¶
Create .python-dependency-linter.yaml in your project root and define your dependency rules:
rules:
- name: domain-isolation
modules: contexts.*.domain
allow:
standard_library: [dataclasses, typing]
third_party: [pydantic]
local: [contexts.*.domain]
- name: application-dependency
modules: contexts.*.application
allow:
standard_library: ["*"]
third_party: [pydantic]
local:
- contexts.*.application
- contexts.*.domain
This config defines two rules:
domain-isolation— modules undercontexts.*.domaincan only importdataclasses,typing,pydantic, and other domain modules.application-dependency— modules undercontexts.*.applicationcan import any standard library,pydantic, and application or domain modules.
You can also use pyproject.toml. See Configuration for details.
Step 2: Run the Linter¶
From your project root, run:
pdl check
pdl automatically discovers the config file by searching upward from the current working directory.
Step 3: Review the Output¶
Violations are reported with the file path, line number, rule name, and the dependency direction:
contexts/boards/domain/models.py:6
[domain-isolation] contexts.boards.domain.models → contexts.boards.application.service (local)
contexts/boards/domain/models.py:9
[domain-isolation] contexts.boards.domain.models → sqlalchemy (third_party)
Found 2 violation(s).
Fix the reported imports and re-run pdl check until no violations remain.
Next Steps¶
- Learn all available config options in Configuration.
- See rule details and pattern options in the Guide.