Skip to main content

A tool to count lines of code in a Python project

Project description

pycodestats

pycodestats is a tool to count lines of code, classes, and methods in a Python project. It can scan directories recursively and provides summary statistics for each file or directory.

Features

  • Counts lines of code (excluding comments and docstrings)
  • Counts number of classes and methods
  • Outputs results in table, JSON, or XML format

Installation

You can install pycodestats using pip:

pip install pycodestats

Usage

To scan a directory and output results in table format:

pycodestats path/to/your/project

To output results in JSON format:

pycodestats path/to/your/project --json

To output results in XML format:

pycodestats path/to/your/project --xml

Example

pycodestats src --by-file

This will output the statistics for each Python file in the src directory.

Output Format

When using the default table format, the output includes the following columns:

  • Directory/File: The name of the directory or file. If --by-file is used, this column lists each individual file. Otherwise, it lists each directory.
  • Lines: The total number of lines in the file or directory. This includes all lines, regardless of content.
  • LOC: The number of lines of code (LOC), excluding comments and docstrings.
  • Classes: The number of classes defined in the file or directory.
  • Methods: The number of methods defined in the file or directory.
  • M/C: The average number of methods per class. This is calculated as the number of methods divided by the number of classes. If there are no classes, this value is 0.
  • LOC/M: The average number of lines of code per method. This is calculated as the number of lines of code divided by the number of methods. If there are no methods, this value is 0.

Example Output

File                        Lines    LOC  Classes  Methods   M/C   LOC/M
-------------------------------------------------------------------------
src/main.py                  120     100       2        10     5      13
src/utils.py                  80      50       1         5     5      18
src/models.py                100      80       3        15     5       8
-------------------------------------------------------------------------
SUM:                         300     230       6        30     5      11

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

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

pycodestats-0.5.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

pycodestats-0.5.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file pycodestats-0.5.0.tar.gz.

File metadata

  • Download URL: pycodestats-0.5.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pycodestats-0.5.0.tar.gz
Algorithm Hash digest
SHA256 b5ae52e8dcec3634a53cd064e29ac869418964d5cb76c9afb4552c50eb356556
MD5 4a13e01a6b44d51f919c2e470ca09aca
BLAKE2b-256 3ea1075f2fa9af862f158156726b2d7a3be87f8ea36c3fd2261b5d6537930f69

See more details on using hashes here.

File details

Details for the file pycodestats-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pycodestats-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pycodestats-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fa8a306731ae6f097897e2cdef68308694cdce1faa9408e90d4955b22feea56
MD5 f0cd40b24902006a3c03e227415c85be
BLAKE2b-256 7169e26ef9ab8e4c9da35258a98e288941580459e5d253c2392b61b2485198f4

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