Modern Metric
Calculate code metrics and complexity in various languages
Purpose
This tool tries to calculate the following metrics for many, many programming languages
- Comment to Code percentage
- Cyclomatic complexity according to McCabe
- Difficulty according to Halstead
- Effort according to Halstead
- Fan-Out
- Lines of code
- Maintainability index
- Metric according to pylint
- Metric according to TIOBE
- Number of delivered bugs according to Halstead
- Time required to program according to Halstead
- Volume according to Halstead
This tool was heavily inspired by metrics
Requirements
Installation
PyPi
simply run
pip3 install modernmetric
From source
- git clone this repository
- cd to <clone folder>
- Install the needed requirements by running
pip3 install -r requirements.txt - run
python3 setup.py build
Usage
usage: modernmetric [-h] [--warn_compiler WARN_COMPILER]
[--warn_duplication WARN_DUPLICATION]
[--warn_functional WARN_FUNCTIONAL]
[--warn_standard WARN_STANDARD]
[--warn_security WARN_SECURITY] [--coverage COVERAGE]
[--bugpredict {old,new}]
[--maintindex {sei,classic,microsoft}]
[--file=path_to_filelist]
AND/OR
files [files ...]
Calculate code metrics in various languages
positional arguments:
files Files to parse
optional arguments:
-h, --help show this help message and exit
--file=path_to_filelist
Path to JSON filelist to scan. Format is:
[
{
"name": "test.c",
"path": "../testfiles/test.c"
}
]
--output_file=path to output, optional
--warn_compiler WARN_COMPILER
File(s) holding information about compiler warnings
--warn_duplication WARN_DUPLICATION
File(s) holding information about code duplications
--warn_functional WARN_FUNCTIONAL
File(s) holding information about static code analysis findings
--warn_standard WARN_STANDARD
File(s) holding information about language standard violations
--warn_security WARN_SECURITY
File(s) File(s) holding information about found security issue
--coverage COVERAGE File(s) with compiler warningsFile(s) holding information about testing coverage
--bugpredict {old,new}
Method how to calculate the bug prediction
--maintindex {sei,classic,microsoft}
Method how to calculate the maintainability index
Currently you could import files of the following types for --warn_* or --coverage
Following information can be read
<file> = full path to file
<content> = either a string
<severity> = optional severity
Note: you could also add a single line, then <content>
has to be a number reflecting to total number of findings
File formats
csv: CSV file of following line format
<file>,<content>,<severity>
json: JSON file
<file>: {
"content": <content>,
"severity": <severity>
}
By default tool guesses the content type by the filename, if that doesn't work for you please see below
Output
Output will be written to stdout as json.
Output structure
filescontains a list of each file passed by CLIoverallcontains the calculated values for all passed filesstatscontains the statistically calculated values over all files passed see Statistical additions
Item structure
| item | description | range | recommendation |
|---|---|---|---|
| comment_ratio | Comment to Code percentage | 0..100 | > 30.0 |
| cyclomatic_complexity | Cyclomatic complexity according to McCabe | 0..(inf) | < 10 |
| fanout_external | Number imports from out of tree modules | 0..(inf) | |
| fanout_internal | Number imports from same source tree modules | 0..(inf) | |
| halstead_bugprop | Number of delivered bugs according to Halstead | 0..(inf) | < 0.05 |
| halstead_difficulty | Difficulty according to Halstead | 0..(inf) | |
| halstead_effort | Effort according to Halstead | 0..(inf) | |
| halstead_timerequired | Time required to program according to Halstead | 0..(inf) | |
| halstead_volume | Volume according to Halstead | 0..(inf) | |
| lang | list of identified programming languages | list | |
| loc | Lines of code | 1..(inf) | |
| maintainability_index | Maintainability index | 0..100 | > 80.0 |
| operands_sum | Number of used operands | 1..(inf) | |
| operands_uniq | Number of unique used operands | 1..(inf) | |
| operators_sum | Number of used operators | 1..(inf) | |
| operators_uniq | Number of unique used operators | 1..(inf) | |
| pylint | General quality score according to pylint | 0..100 | > 80.0 |
| tiobe_compiler | Compiler warnings score according to TIOBE | 0..100 | > 90.0 |
| tiobe_complexity | Complexity according to TIOBE | 0..100 | > 80.0 |
| tiobe_coverage | Coverage according to TIOBE | 0..100 | > 80.0 |
| tiobe_duplication | Code duplications score according to TIOBE | 0..100 | > 80.0 |
| tiobe_fanout | Fan-Out score according to TIOBE | 0..100 | > 80.0 |
| tiobe_functional | Functional defect score according to TIOBE | 0..100 | > 90.0 |
| tiobe_security | Security score according to TIOBE | 0..100 | > 90.0 |
| tiobe_standard | Language standard score according to TIOBE | 0..100 | > 80.0 |
| tiobe | General quality score according to TIOBE | 0..100 | > 80.0 |
Statistics
The item stats contains in addition to the above mentioned the following items, which by themselves contain all the items mentioned at Item structure
max= the maximum value of all items of the metricmean= statistical mean over all items of the metricmedian= statistical median over all items of the metricmin= the minimum value of all items of the metricsd= standard deviation over all items of the metric
Further reading
Bugs & Contribution
Feel free to create issues or pull requests
Metadata
Release files for modernmetric 1.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| modernmetric-1.6.0.tar.gz | 18.0 MB | With provenance | Details for modernmetric-1.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| modernmetric-1.6.0-py3-none-any.whl | Python 3 | none | any | Details for modernmetric-1.6.0-py3-none-any.whl |
Total release size: 18.0 MB
Release files / modernmetric-1.6.0.tar.gz
| Download URL | modernmetric-1.6.0.tar.gz |
|---|---|
| Size | 18.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4128582d418cf94ceee2a2726ab97ac340ef285ca1cac133b46e10b4c6fc81fb
|
|
BLAKE2b-256 checksum How to use checksums |
80a3fc58e6d97a5a70aac83395f9d8df2811dd62b8846f2852718fc906c84eec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 20, 2026.
Transparency logRelease files / modernmetric-1.6.0-py3-none-any.whl
| Download URL | modernmetric-1.6.0-py3-none-any.whl |
|---|---|
| Size | 29.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af1265ef7b02aff79ebbc540d1811883bfb366c9c575bae635b5d9e22e1530a3
|
|
BLAKE2b-256 checksum How to use checksums |
d339a039d2c5c15e6c4234bcc6b33b7b9f159b07f18c327e62468684e40ecc04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 20, 2026.
Transparency logSecurity for modernmetric 1.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for modernmetric-1.6.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.