Skip to main content

Metripy

Install with pip install metripy.

A multilanguage, multi project code metrics analysis tool.

PyPI version Python 3.11 Python 3.12 Tests Coverage License Downloads

Languages

Supported languages

  • Python
  • Php
  • Typescript
  • TBD

Analysis types

Code analysis

Analyses code with cyclomatic complexity, maintainability index, halstead metrics.

Git analysis

Analyses git stats of the past months

Dependeny analysis

Analyzses composer, npm or pip dependencies

More dependencies TBD

Report formats

Html

Generates an easy to read dashboard for each project.

Dashboard Overview

Project Index Page

When analyzing multiple projects, you can generate a central index page that provides an overview of all projects at a glance.

HTML Index Overview

Configure with:

{
    "configs": { /* multiple project configs */ },
    "html_index": "./build/index.html"
}

The index page displays:

  • Aggregate statistics across all projects (total LOC, files, avg complexity, etc.)
  • Project cards with individual metrics and health status
  • Links to each project's detailed HTML report
Project Cards

Files Analysis

Files Analysis

Top Offenders

Top Offenders

Csv

Exports simple csv

Json

Dumps full result into json

Cli

Prints comprehensive overview directly to the terminal with color-coded visualizations:

  • Stacked bar charts for all key metrics
  • Top offenders tables (worst files and functions)
  • Coupling and instability metrics
  • Code smells summary
  • Git and dependency metrics (when enabled)

Metrics

Lines of code

The total number of lines in your source code, including comments and blank lines.

Cyclomatic Complexity

A measure of the number of independent paths through your code.

Cognitive Complexity

A measure of how difficult code is to understand based on its control flow and nesting.

Maintainability Index

A composite metric that estimates how easy it is to maintain code, based on LOC, complexity, and comments.

Average Method Size

The average number of lines per method or function in your codebase.

Instability

A metric that measures how likely a module is to change based on its dependencies (ratio of efferent to afferent couplings).

LCOM4

A metric that measures how well the methods of a class are related to each other. It checks if methods share common attributes, indicating cohesion.

Configuration

Configuration is for the moment only possible with the --config=<file>.json option. More TBD

Sample configuraiton:

{
    "configs": {
        "metripy": {
            "base_path": "./", // base path to look at
            "includes": [
                "metripy/" // paths to include from the base path on
            ],
            "excludes": [
                "__pycache__" // exclude patterns of paths / files
            ],
            "extensions": [
                "py" // file extensions to look at
            ],
            "git": { // if git is set, analyzes git history
                "branch": "main" // git branch to look at
            },
            "composer": true, // looks for base_path/composer.json and analyzes dependencies - for php projects
            "npm": true, // looks for base_path/package.json and analyzes dependencies - for ts/js projects
            "pip": true,
            // looks for base_path/requirements.txt or base_path/pyproject.toml and analyzes dependencies - for python projects
            "reports": {
                "html": "./build/report/metripy", // report should be put into this directory
                "json-git": "./build/json-report/metripy-git.json" // file where to put git json report
                // more types of reports TBA
            }
        },
        // next project name: { next config... } 
    },
    "html_index": "./build/index.html" // optional: generates a central overview page for all projects
}

Configuration for only git stats

{
    "configs": {
        "metripy-git": {
            "base_path": "./",
            "git": {
                "branch": "main"
            },
            "reports": {
                "json-git": "./build/json-report/metripy-git.json"
            }
        }
    }
}

Exit Conditions (Quality Gates)

Define conditions to fail the analysis with specific exit codes. Useful for CI/CD pipelines.

{
    "configs": { ... },
    "failure": {
        "1": [
            {
                "value": "function_cyclomatic_complexity",
                "severity": "critical",
                "amount": 10
            }
        ]
    }
}

This example exits with code 1 if there are 10 or more functions with critical cyclomatic complexity.

Available metrics

  • File level: file_loc, file_cyclomatic_complexity, file_maintainability_index, file_cognitive_complexity
  • Class level: class_loc, class_cyclomatic_complexity, class_lcom4
  • Function level: function_loc, function_cyclomatic_complexity, function_maintainability_index, function_cognitive_complexity

Severity levels

good, ok, warning, critical

See the Configuration Guide for more details.

Metadata

Release files for metripy 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for metripy 1.0.1
File Size Uploaded
metripy-1.0.1.tar.gz 123.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for metripy 1.0.1
File Interpreter ABI Platform
metripy-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 306.7 kB

Release files / metripy-1.0.1.tar.gz

Download URL metripy-1.0.1.tar.gz
Size 123.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d3bda4b65cab4ceedf847eb55a1ac34e52183c14d315b5c79e2844a5b65464ef
BLAKE2b-256 checksum
How to use checksums
6a83dad393934651771959d7cb223da6a08f31bdd0cc50b3e5bfbadc1d2e2a59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / metripy-1.0.1-py3-none-any.whl

Download URL metripy-1.0.1-py3-none-any.whl
Size 183.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9aa596c4b5050cde07ce6b1e62c9d173234e78be1b62b2d5f8fd04579dcfa7b2
BLAKE2b-256 checksum
How to use checksums
17191a97305004c12c57e77c7c6379c44276b4b045a228a0b3bebd0cbab52b34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.10

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page