Skip to main content

A blazing-fast, parallel Lines of Code counter with Rich terminal UI

Project description

codelines โšก

PyPI version Python 3.9+ Downloads License: MIT PRs Welcome

"How many lines of code is this thing, anyway?"

The question that keeps tech leads up at night. The question that fuels endless Slack debates about "what counts as a line." The question that codelines answers in milliseconds while your coworkers are still arguing about whether blank lines should be included.


๐ŸŽญ The Problem

You just inherited a monorepo. The README says "lightweight microservice architecture" but node_modules has 87,000 files and there's a backup-final-v2-old (copy).py somewhere. You need numbers. Cold, hard, undeniable numbers.

You try wc -l. It counts package-lock.json. It counts dist/. It doesn't know what a .gitignore is. It stares back at you with the blank expression of a tool that peaked in 1971.

Enter codelines.


โšก What It Does

$ codelines .

                    Summary
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Metric                  โ”‚ Value   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Total Files (counted)   โ”‚ 847     โ”‚
โ”‚ Total Lines (real code) โ”‚ 124,532 โ”‚
โ”‚ Workers                 โ”‚ 16      โ”‚
โ”‚ Skipped Directories     โ”‚ 23      โ”‚
โ”‚ Skipped Files           โ”‚ 156     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

             Top File Types (Actual Code)
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Extension โ”‚ Lines   โ”‚      % โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ .py       โ”‚ 52,341  โ”‚  42.0  โ”‚
โ”‚ .js       โ”‚ 28,912  โ”‚  23.2  โ”‚
โ”‚ .ts       โ”‚ 18,234  โ”‚  14.6  โ”‚
โ”‚ .css      โ”‚ 12,567  โ”‚  10.1  โ”‚
โ”‚ .html     โ”‚  8,901  โ”‚   7.1  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

It's fast. Multi-threaded. Uses all your cores. Respects .gitignore. Gives you beautiful tables, JSON, or CSV. And it makes you look like you know exactly what's going on โ€” even when you don't.


๐Ÿ“ฆ Installation

pip install codelines

That's it. No system dependencies. No Docker. No "just clone and run these 47 scripts." One command. You're counting.

$ codelines --version
codelines 0.1.0

๐Ÿš€ Quick Start

# The basics
codelines .                              # Count current directory
codelines ~/projects/monorepo            # Point it anywhere

# Get nerdy
codelines . --format json                # Machine-readable output
codelines . --format csv                 # Spreadsheet-ready
codelines . --include .py .rs .go        # Only the languages you care about
codelines . --exclude .json .lock        # Skip the noise
codelines . --max-depth 3                # Don't go too deep, man
codelines . --sort-by ext --top 10       # Top 10 extensions, sorted
codelines . --workers 16                 # Unleash the cores
codelines . --quiet                      # I don't need the show, just the numbers

๐ŸŽฎ Full Command Reference

Usage: codelines [OPTIONS] [DIRECTORY]

Arguments:
  directory                Directory to scan (default: current directory)

Options:
  --format, -f   [table|json|csv]     Output format (default: table)
  --include, -i  EXT [EXT ...]        Only count these extensions
  --exclude, -e  EXT [EXT ...]        Skip these extensions
  --max-depth, -d N                   Maximum directory depth
  --workers, -w  N                   Worker threads (default: CPU ร— 2)
  --ignore-file  PATH                Additional ignore file
  --sort-by, -s  [ext|dir|lines]     Sort criterion (default: lines)
  --top, -t      N                   Show top N results (default: 5)
  --quiet, -q                        Suppress progress display
  --version, -V                      Show version and exit
  --help, -h                         Show this message

๐Ÿง  The Philosophy

What counts as a "line"?

A line is a \n character. If your file has newlines, we count them. No opinions. No debates. No "but what about docstrings?" Just the raw, unfiltered truth your files are telling you.

What files get counted?

By default, we recognize 40+ code file extensions โ€” Python, JavaScript, TypeScript, Go, Rust, Java, C/C++, HTML, CSS, JSON, YAML, Markdown, Shell, SQL, and more. You can add or remove extensions with --include and --exclude.

What gets ignored?

We automatically read your .gitignore and .ignore files. Got node_modules? Skipped. .venv? Skipped. __pycache__? Skipped. We also eat our own dog food โ€” the scanner itself is lightning fast because it skips boring directories before even looking at files.


๐Ÿ— Architecture (for the curious)

Ask for a directory
        โ”‚
        โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚   Scanner   โ”‚  โ† Walks the tree, applies .gitignore, respect depth limits
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚ list of Path objects
         โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚  Thread Pool โ”‚ โ† min(32, CPUร—2) workers, chunked binary reads (1 MiB)
  โ”‚  Dispatcher  โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚ per-file line counts
         โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚  Aggregator  โ”‚ โ† Groups by extension, directory, computes percentages
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
         โ–ผ
  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚  Reporter    โ”‚ โ† table (Rich), JSON, or CSV โ€” your choice
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

No temporary files. No database. No config file to manage. Just a pure pipeline from filesystem to your eyeballs.


๐Ÿ”ฅ Real-World Speed

Scenario Files Lines Time
Small project (codelines itself) 11 1,230 <0.1s
Medium monorepo 2,500 180,000 ~0.5s
Large repo (Hermes Agent) 87,000 17,000,000 ~3s

Benchmarked on a 4-core VPS. Your speeds may vary โ€” usually faster on real hardware.


๐Ÿค But Why?

Because wc -l doesn't know what a gitignore is. Because counting lines shouldn't require a shell pipeline that looks like a cat walked across your keyboard. Because developers deserve tools that are fast, pretty, and don't make them think about edge cases.

And honestly? Because it was fun to build.


๐Ÿ›  Built With

  • Rich โ€” the terminal UI library that makes CLI apps feel like magic
  • Python's ThreadPoolExecutor โ€” because blocking I/O is for people with infinite patience
  • pathlib โ€” because string concatenation for file paths is a crime
  • Pure Python โ€” zero native dependencies, installs anywhere

๐Ÿ“„ License

MIT ยฉ Muneer Alam


built with excessive coffee and mild obsession with counting things

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codelines-0.1.1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codelines-0.1.1-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file codelines-0.1.1.tar.gz.

File metadata

  • Download URL: codelines-0.1.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for codelines-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2686269939083b2609ad99e2e2e3a55edc192d590d75f053744e6d446b696548
MD5 c970ee7cea1bc08a75ee416ba2b0a8a0
BLAKE2b-256 e725c9753b912b5830a3d1afba7b8194e2db8bdaf42aea185bf6ab2028fa3812

See more details on using hashes here.

File details

Details for the file codelines-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: codelines-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for codelines-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3d6bed7c5c3fabcc2265194d49d3f91e1e5eea85b2cbcec986f042da20ea5659
MD5 02621488831c44301a01b17ccf53f7b0
BLAKE2b-256 c9bb1859741e41d9235069405b49bb58178ae1f603a474c949531ec63cd75d65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page