Skip to main content

dlen

Check how long your functions and classes are.

A long function is the cheapest smell to detect and the most reliable one to act on. dlen tells you which ones crossed the line, and where.

$ dlen src/
src/importer.py:42:1: DL001 function 'process_batch' is 34 lines (max 20)
src/importer.py:88:5: DL001 function 'validate' is 14 lines (warn 12)
src/models.py:7:1: DL002 class 'LegacyRecord' is 812 lines (max 500)

Install

uv tool install dlen     # or: pipx install dlen, pip install dlen

Python 3.10 or newer. No dependencies.

Use

dlen src/ tests/                 # files, directories, or both
dlen . --max-function 30         # your project, your thresholds
dlen . --output-format=json      # for other tools
Flag Default Meaning
--warn-function N 12 report a function above N lines, without failing
--max-function N 20 fail on a function above N lines
--max-class N 500 fail on a class above N lines
--output-format full full, github or json

A function's length includes its decorators — they are part of what you read before you understand it.

Exit codes

Code When
0 nothing found, or only warnings
1 something was over a max, or a file could not be parsed
2 bad arguments

Warnings never fail the build. That is the point of having two thresholds: one to nudge, one to stop.

Rules

Code Rule
DL001 function is too long
DL002 class is too long
DL900 file could not be read or parsed

In CI

--output-format=github puts each finding on the diff of the pull request instead of burying it in a log:

- run: uvx dlen src --output-format=github

As a library

The core returns data and prints nothing, so you can build your own reporting on it:

from pathlib import Path
from dlen import Limits, check_paths

findings = check_paths([Path("src")], Limits(max_function=30))
for finding in findings:
    print(finding.code, finding.path, finding.line, finding.message)

Every call returns a fresh list. Two runs never see each other's findings.

How it measures

dlen parses your code with Python's own ast module, so it agrees with Python about what a function is. It sees async def, decorators, nested functions and methods, and it is not fooled by the word def inside a string or a comment.

Versions before 0.1.0 matched text with regular expressions and had been broken on Python 3 since 2017. 0.1.0 is a rewrite: the counts are now correct rather than compatible, and the output carries file, line and column.

Licence

MIT.

Metadata

Release files for dlen 0.1.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 dlen 0.1.0
File Size Uploaded Provenance Actions
dlen-0.1.0.tar.gz 8.9 kB With provenance Details for dlen-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 15.9 kB

Release files / dlen-0.1.0.tar.gz

Download URL dlen-0.1.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d0232d9434afce5e05b5ca04904ed5f3ad2ffc99b5bfa7bba527bc4b6b460634
BLAKE2b-256 checksum
How to use checksums
47b60a45d14ab9665979984948e133b40bcaeed3a141be77473931537fcf442a
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 17, 2026.

Transparency log

Release files / dlen-0.1.0-py3-none-any.whl

Download URL dlen-0.1.0-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b15a0f81e2e018c6ff961087f7ceb90868205cd059ee8dbb7026991d3b74de94
BLAKE2b-256 checksum
How to use checksums
4883df8c80642bf8cb5adc935e4f2752bbf093d49a3043247742755a42706731
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 17, 2026.

Transparency log

Security for dlen 0.1.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 dlen-0.1.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 17, 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