
Research
SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.
pygount
Advanced tools
Pygount is a command line tool to scan folders for source code files and count the number of source code lines in it. It is similar to tools like sloccount and cloc but uses the pygments package to analyze the source code and consequently can analyze any programming language supported by pygments.
The name is a combination of pygments and count.
Pygount is open source and distributed under the BSD license. The source code is available from https://github.com/roskakori/pygount.
For installation run
$ pip install pygount
or use uv to run it directly, for example:
$ uvx pygount --version
To get a list of line counts for a projects stored in a certain folder:
$ pygount ~/projects/example
To limit the analysis to certain file types identified by their suffix:
$ pygount --suffix=cfg,py,yml ~/projects/example
To get a summary of each programming language with sum counts and percentage:
$ pygount --format=summary ~/projects/example
To analyze a remote git repository directly without having to clone it first:
$ pygount --format=summary https://github.com/roskakori/pygount.git
You can pass a specific revision at the end of the remote URL:
$ pygount --format=summary https://github.com/roskakori/pygount.git/v1.5.1
This example results in the following summary output:
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━━━━┳━━━━━━┓
┃ Language ┃ Files ┃ % ┃ Code ┃ % ┃ Comment ┃ % ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━╇━━━━━━╇━━━━━━━━━╇━━━━━━┩
│ Python │ 18 │ 47.4 │ 2132 │ 63.6 │ 418 │ 12.5 │
│ TOML │ 2 │ 5.3 │ 1204 │ 82.7 │ 1 │ 0.1 │
│ Batchfile │ 1 │ 2.6 │ 24 │ 68.6 │ 1 │ 2.9 │
│ Bash │ 2 │ 5.3 │ 12 │ 80.0 │ 3 │ 20.0 │
│ Makefile │ 1 │ 2.6 │ 9 │ 45.0 │ 7 │ 35.0 │
│ reStructuredText │ 9 │ 23.7 │ 0 │ 0.0 │ 438 │ 50.2 │
│ Markdown │ 3 │ 7.9 │ 0 │ 0.0 │ 53 │ 49.1 │
│ Text only │ 2 │ 5.3 │ 0 │ 0.0 │ 24 │ 82.8 │
├──────────────────┼───────┼───────┼──────┼──────┼─────────┼──────┤
│ Sum │ 38 │ 100.0 │ 3381 │ 57.4 │ 945 │ 16.1 │
└──────────────────┴───────┴───────┴──────┴──────┴─────────┴──────┘
Plenty of tools can post process SLOC information, for example the SLOCCount plug-in for the Jenkins continuous integration server.
A popular format for such tools is the XML format used by cloc, which pygount also supports and can store in an output file:
$ pygount --format=cloc-xml --out=cloc.xml ~/projects/example
To get a short description of all available command line options use:
$ pygount --help
For more information and examples read the documentation chapter on Usage.
To report bugs, visit the issue tracker.
In case you want to play with the source code or contribute improvements, see CONTRIBUTING.
See CHANGES.
FAQs
count source lines of code (SLOC) using pygments
We found that pygount demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.