codelines
Count physical lines in recognized source and text files, grouped by extension and directory. The count includes blank lines and comments. Files without a final newline still count their last line; files containing NUL bytes are treated as binary and contribute zero lines.
Install
Python 3.9 or newer is required.
python -m pip install codelines
codelines --version
Use
codelines .
codelines . --format json > count.json
codelines . --format csv > count.csv
codelines . --include .py .rs --max-depth 2
codelines . --sort-by ext --top 10
codelines . --no-default-ignores
The table is for terminal reading. JSON and CSV contain every extension and directory, regardless of --top, and write only the result to stdout. --quiet suppresses status and progress while keeping the report. Errors go to stderr.
--max-depth 0 scans root files; depth 1 also scans direct child directories. --sort-by lines orders each group by descending line count. --sort-by ext orders extensions alphabetically; --sort-by dir orders directories alphabetically. --top limits only table rows.
The scanner reads .gitignore and .ignore in the root and nested directories, with Git-style negation and anchored patterns. It skips common dependency, cache, build and VCS directories by default, including node_modules, .venv, __pycache__, dist and .git. Use --no-default-ignores to disable that built-in list; ignore files still apply. --ignore-file PATH adds another ignore file.
Known extensions include Python, JavaScript, TypeScript, Rust, Go, Java, HTML, CSS, JSON, Markdown and YAML. Files named Dockerfile, Makefile and CMakeLists.txt are also counted. --include and --exclude filter by extension; --include can also name a recognized filename.
Library use
from pathlib import Path
from codelines.ignore import IgnoreMatcher
from codelines.scanner import collect_files
from codelines.counter import count_lines
root = Path(".").resolve()
files, skipped_dirs, skipped_files = collect_files(root, IgnoreMatcher(root))
total, by_extension, by_directory = count_lines(files)
Library functions do not print progress unless verbose=True is passed.
Development
python -m pip install -e ".[dev]"
python -m pytest
License
MIT. See LICENSE.
Metadata
Release files for codelines 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| codelines-0.2.0.tar.gz | 13.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| codelines-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.0 kB
Release files / codelines-0.2.0.tar.gz
| Download URL | codelines-0.2.0.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ace684baf6e041ceef6afe879283da20226778f9ad2f4439cefa9730395b104
|
|
BLAKE2b-256 checksum How to use checksums |
5054da7cebbdf6961a79c596b22e3acc57569dc21bfd71644695fe75097531e4
|
| 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 Oct 2, 2026.
Transparency logRelease files / codelines-0.2.0-py3-none-any.whl
| Download URL | codelines-0.2.0-py3-none-any.whl |
|---|---|
| Size | 12.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c6bb4fbf56a014fcef9884c0daf3989dd189f9a0b87931fc9c210c0e946a70ff
|
|
BLAKE2b-256 checksum How to use checksums |
ba9ef3221859c5260d8bd8a7cbfe5078b0d07a40700b5b76d1e09f54d768635f
|
| 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 Oct 2, 2026.
Transparency log