Registry / devops / pygount

pygount

JSON →
library3.2.0pypypi✓ verified 87d ago

Pygount is a command line tool designed to scan folders for source code files and accurately count the number of source lines of code (SLOC). It leverages the robust `pygments` package to parse source code, allowing it to analyze hundreds of programming languages. Pygount, currently at version 3.2.0, is an actively maintained library with regular updates.

pip install pygount
INSTALL
IMPORT
SIG · PYGOUNT
P
pygount
devopspythonv3.2.0
Install
3.1s avg
Import
Disk
33MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 34.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.1s · import 0.000s · 35MB
33MB installed
● package 33MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SourceAnalysis
from pygount import SourceAnalysis
ProjectSummary
from pygount import ProjectSummary
import pygount; pygount.source_analysis(...)
While `pygount.source_analysis` is still available, the object-oriented API (`SourceAnalysis` and `ProjectSummary`) is the recommended approach for programmatic use, though still considered 'work in progress' and subject to change.

This quickstart demonstrates how to use `pygount`'s API to programmatically analyze source code files within a directory and summarize the results. It creates dummy files, analyzes them using `SourceAnalysis` and aggregates the results with `ProjectSummary`, then prints the language-specific counts.

import os from pathlib import Path from pygount import SourceAnalysis, ProjectSummary # Create dummy files for demonstration dummy_dir = Path('./my_project') dummy_dir.mkdir(exist_ok=True) (dummy_dir / 'main.py').write_text( """# This is a Python file import sys def hello(): # Code line print('Hello, world!') # Code line # Another comment """ ) (dummy_dir / 'README.md').write_text( """# My Project This is a test project. """ ) (dummy_dir / '.hidden_file.txt').write_text("should not be counted") project_summary = ProjectSummary() # Analyze files in the dummy project directory for source_path in dummy_dir.rglob('*'): if source_path.is_file(): try: source_analysis = SourceAnalysis.from_file(source_path, 'my_project') project_summary.add(source_analysis) except UnicodeDecodeError as e: print(f"Warning: Could not decode {source_path}: {e}") print("\n--- Analysis Results ---") for language_summary in project_summary.language_to_language_summary_map.values(): print(language_summary) # Clean up dummy files import shutil shutil.rmtree(dummy_dir)
pygount --version
Debug
Known issues
breakingPygount versions 3.x have removed support for older Python versions. Specifically, Python 3.7 and 3.8 are no longer supported. Ensure your environment uses Python 3.10 or newer.
fix
Upgrade your Python interpreter to version 3.10 or higher.
affects: >=3.0.0
gotchaThe programmatic API (e.g., `SourceAnalysis`, `ProjectSummary`) is explicitly stated as 'work in progress and subject to change'. Breaking changes to the API might occur in future versions.
fix
Refer to the official documentation and 'Changes' log for each new release before upgrading when using the API programmatically. Pin `pygount` to a specific version if API stability is critical.
affects: All versions
gotchaPygount automatically excludes certain files and folders from analysis by default. This includes files starting with a dot (`.`), files ending with a tilde (`~`), and folders named `.svn` or starting with a dot (`.`).
fix
Use the `--folders-to-skip` and `--names-to-skip` command-line options to override or extend the default exclusion patterns if you need to include such files/folders in your analysis.
affects: All versions
gotchaWhile robust, pygount can be notably slower than other command-line SLOC counting tools due to its detailed `pygments`-based parsing.
fix
Consider `pygount` for accuracy and language coverage rather than raw speed. For very large codebases where performance is critical, profile `pygount`'s execution or consider alternative tools if its speed is insufficient.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pygount'
The 'pygount' package is not installed in the currently active Python environment.
fix
Install pygount using pip: `pip install pygount`
ImportError: No module named pygments
The 'pygments' package, a fundamental dependency for pygount's code parsing, is not installed or accessible in your Python environment.
fix
Install pygments using pip: `pip install pygments`
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x... in position ...: invalid start byte
Pygount attempted to read a source code file using UTF-8 encoding, but the file contains characters encoded differently, leading to a decoding failure.
fix
Specify the correct encoding for the file using the `--encoding` command-line option (e.g., `pygount --encoding=iso-8859-15 .`). You can also try `automatic;iso-8859-15` or `chardet` (requires `pip install chardet`) for heuristic detection.
Could not find a version that satisfies the requirement pygount (from versions: ) No matching distribution found for pygount.
This usually indicates that the Python version in use is too old for the latest pygount release (e.g., pygount 3.x requires Python 3.10 or newer), or pip cannot find a compatible distribution for your system.
fix
Upgrade your Python interpreter to version 3.10 or higher. Alternatively, ensure pip is updated (`python -m pip install --upgrade pip`) and try installing within a clean virtual environment.
Upgrade
Version history
3.2.0latest on PyPI · released Apr 8, 2026
Audit
Dependencies
pygmentsrequiredCore dependency for source code parsing and language detection.
chardetoptionalOptional dependency for automatic character encoding detection when using `--encoding=chardet`.
Agent activity
25 hits · last 30 days
node
22
Amazon
1
Resources
pygount — pip install pygount · libregistry