PyCodeStats
PyCodeStats is a small Python library for collecting basic statistics from Python files.
Features
- Total lines
- Blank lines
- Comment lines
- Code lines
- Variables
- Functions
- Classes
- Imports
if/elif/elseforloopswhileloopsreturnstatements
Install
pip install codestats-py
Usage
import codestats as cs
stats = cs.analyze("main.py")
print(stats)
Access individual stats
import codestats as cs
stats = cs.analyze("main.py")
print(stats.total_lines)
print(stats.functions)
print(stats.classes)
print(stats.variables)
print(stats.for_loops)
print(stats.while_loops)
Pretty report
import codestats as cs
cs.report("main.py")
Example output
==============================
PYCODESTATS
==============================
Total Lines : 120
Blank Lines : 18
Comment Lines : 9
Code Lines : 102
Variables : 15
Functions : 4
Classes : 2
Imports : 3
If : 6
Elif : 2
Else : 3
For Loops : 5
While Loops : 1
Returns : 7
==============================
API
analyze(file_path)
Returns one CodeStats object containing all counts.
report(file_path)
Prints a formatted report and also returns it as a string.
Planned future versions
- Directory analysis
- JSON export
- CSV export
- CLI
- More metrics
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
codestats_py-1.0.0.tar.gz
(5.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codestats_py-1.0.0.tar.gz.
File metadata
- Download URL: codestats_py-1.0.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fad44061ed158e7c68996011e5267e13d6e071c853f6ef2e332ad20a307be22
|
|
| MD5 |
1f5421378d90223e508d649cae3cadb5
|
|
| BLAKE2b-256 |
4c5116113ffb4d3ab024fd2f30a930bbd94f8a87e0b6696a7f2575307a7d06de
|
File details
Details for the file codestats_py-1.0.0-py3-none-any.whl.
File metadata
- Download URL: codestats_py-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03a05749adbc467236bdef575c1a65102f8321c2138d606f31d38a722cf2ffba
|
|
| MD5 |
2d9aff06d59eeb60a600b4cc5ab6c342
|
|
| BLAKE2b-256 |
0409b321de0c7638a4cec70dedeb219d27db7fec5a876c041667f91a881798a4
|