Skip to main content

pylint-tyrant

Pylint plugin with documentation and architecture rules inspired by eslint-plugin-tyrant.

In rule names, doc means Python docstrings.

The plugin currently ships these rules:

  • enforce-doc-tag-order
  • enforce-project-layer-dependencies
  • enforce-package-layer-dependencies
  • no-direct-error-instantiation
  • no-test-only-exports
  • require-doc-for-public-api
  • require-file-doc
  • require-empty-line-after-file-doc
  • prefer-single-line-doc
  • prefer-directory-modules-for-siblings
  • restrict-relative-imports-to-base-module

no-test-only-exports

Reports public module-level identifiers that have no imports from production files. Imports from test files and uses within the declaring module do not make an identifier part of the production API.

Names beginning with _ or __ are private and are not checked. Prefer an _ prefix for implementation details that do not need to be imported by production code. If a public identifier is complex enough to require direct tests, suppress the message for that declaration with a Pylint disable comment.

enforce-project-layer-dependencies

Keeps each project layer coupled only to itself and the layers its ordered hierarchy or explicit dependency graph allows.

This rule uses --tyrant-layers:

pylint \
  --load-plugins=pylint_tyrant \
  --enable=enforce-project-layer-dependencies \
  --tyrant-layers=lib,services,app \
  path/to/your_package

The same graph configuration can be placed in pyproject.toml:

[tool.pylint.main]
load-plugins = ["pylint_tyrant"]

[tool.pylint."messages control"]
enable = ["enforce-project-layer-dependencies"]

[tool.pylint.tyrant-project-layer-dependencies]
tyrant-layer-dependencies = '{"lib": [], "api": ["lib"], "worker": ["lib"], "app": ["api", "worker"]}'

For sibling applications or other branches, use --tyrant-layer-dependencies with a JSON object. Each key is a layer, and its array lists only the layers it may import directly. Dependencies are explicit, not transitive; same-layer imports are always allowed, and sibling branches do not gain an implicit dependency on one another:

pylint \
  --load-plugins=pylint_tyrant \
  --enable=enforce-project-layer-dependencies \
  '--tyrant-layer-dependencies={"lib":[],"services":["lib"],"workers":["lib","services"],"app":["lib","services"]}' \
  path/to/your_package

The graph option takes precedence when both options are configured. Imports involving unconfigured layers are ignored.

enforce-package-layer-dependencies

Organizes same-package modules into shared, feature, and entry layers declared in the entry-file docstring, allowing only downward coupling.

This rule uses --tyrant-shared-modules. __init__.py is treated as the exact entry file automatically, configured same-directory module names such as base or types.py are treated as shared low-level modules, and every other source file or importable directory in the directory is treated as a feature module.

Prefix inheritance is disabled by default. Set --tyrant-inherit-layers-from-module-prefixes=y to let dotted-qualified modules inherit the layer of their first-component base module. For example, bbb.unit.test.py and bbb.integration.test.py then inherit the layer declared by @module bbb.py, so they do not need to be listed separately and must not be listed separately. They cannot import higher layers. Qualified configured shared modules such as types.unit.test.py inherit the shared layer from --tyrant-shared-modules=types.py. The entry layer is always the exact __init__.py entry file.

Use @module for one ordered module layer and @module-group for one ordered flat peer layer:

"""Package docs.

@module materials.py - Core data.
@module-group paragraphs.py, lexicons.py - Peer modules derived from the same inputs.
@module metrics.py - Aggregates.
"""

Every feature module must be listed exactly once. Missing modules, extra listed modules, repeated modules, and upward imports are violations. Every @module and @module-group tag must also include a non-empty relationship description. When declaring feature modules or configuring --tyrant-shared-modules, names with .py are source file modules; names without extensions are directory modules. A package may not contain both a source file and an importable directory with the same basename.

pylint \
  --load-plugins=pylint_tyrant \
  --enable=enforce-package-layer-dependencies \
  --tyrant-shared-modules=base,types.py \
  path/to/your_package

Add --tyrant-inherit-layers-from-module-prefixes=y to that command only when prefix inheritance is wanted.

require-doc-for-public-api

Makes public classes, functions, and methods self-describing with docstrings, so consumers need not read the implementation.

This rule currently treats names that do not start with _ as public. It checks:

  • top-level public classes
  • top-level public functions
  • public methods on public classes

Valid:

class UserService:
    """Load users."""

    def load_user(self) -> None:
        """Load one user."""

Also valid:

def load_user() -> None:
    """Load one user."""

Invalid:

def load_user() -> None:
    pass

enforce-doc-tag-order

Makes recognized docstring tags follow one configured order, so the order stays the single source of truth for tag sequence.

This rule reads tags written as @tag - value from module, class, and function docstrings. It only checks tags listed in tyrant-doc-tag-order.

Configure it in pyproject.toml like this:

[tool.pylint.main]
load-plugins = ["pylint_tyrant"]

[tool.pylint."messages control"]
enable = ["enforce-doc-tag-order"]

[tool.pylint.tyrant-doc-tag-order]
tyrant-doc-tag-order = ["@remarks", "@param", "@returns"]

Command-line equivalent:

pylint \
  --load-plugins=pylint_tyrant \
  --enable=enforce-doc-tag-order \
  --tyrant-doc-tag-order=@remarks,@param,@returns \
  path/to/your_package

Valid:

def load_user() -> User:
    """Load one user.

    @remarks - Used by the public API.
    @param - User id.
    @returns - Loaded user.
    """

Invalid:

def load_user() -> User:
    """Load one user.

    @returns - Loaded user.
    @param - User id.
    """

Metadata

Release files for pylint-tyrant 0.8.0

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

Source distribution (sdist)

Source distribution for pylint-tyrant 0.8.0
File Size Uploaded Provenance Actions
pylint_tyrant-0.8.0.tar.gz 21.8 kB With provenance Details for pylint_tyrant-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pylint-tyrant 0.8.0
File Interpreter ABI Platform Actions
pylint_tyrant-0.8.0-py3-none-any.whl Python 3 none any Details for pylint_tyrant-0.8.0-py3-none-any.whl

Total release size: 42.9 kB

Release files / pylint_tyrant-0.8.0.tar.gz

Download URL pylint_tyrant-0.8.0.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2622c21d3fd087678bccd07a26b1fb91ce16d2638a23b4ea8412a5bea8e774be
BLAKE2b-256 checksum
How to use checksums
e0b3b86bd67831daa28383db2e6d4a29dafde84f97944066989417968e809107
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Release files / pylint_tyrant-0.8.0-py3-none-any.whl

Download URL pylint_tyrant-0.8.0-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb2781b2a35690824ee1b4d78b8469335ef07fc7b197fb2ce7a02e2f584e1715
BLAKE2b-256 checksum
How to use checksums
725cfce1871078545d53c98dd041aac996a69bf963459ab8523e14194f9a8963
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

Security for pylint-tyrant 0.8.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pylint_tyrant-0.8.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.

Transparency log

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.

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