Skip to main content

Python port of TeraMetrics - IaC quality metrics for Terraform HCL files

Project description

PyTerametrics

PyPI version License: MIT Python Versions

Python port of TerraMetrics — IaC quality metrics for Terraform HCL files.

Computes 100+ quality metrics at the block level for Terraform .tf files, including:

  • Cyclomatic complexity (McCabe CC)
  • Lines of code / non-code lines
  • Function call counts and parameters
  • Conditional expressions, loops, binary operators
  • Nested blocks, dynamic blocks, heredocs
  • Implicit/explicit resource dependencies
  • Text entropy, token statistics
  • And many more...

Installation

pip install pyterametrics

Usage

Command Line

# Analyze a single file
pyterametrics --file main.tf -b --target output.json

# Analyze a directory
pyterametrics -l --repo ./terraform-project --target ./results --project my-project

# Pretty-print output
pyterametrics --file main.tf -b --pretty

Python API

from pyterametrics import analyze_file, analyze_directory

# Single file
result = analyze_file("main.tf")
for block in result["blocks"]:
    print(f"{block['block_identifiers']}: {block['numAttrs']} attrs, CC={block['sumMccabeCC']}")

# Directory
result = analyze_directory("./terraform-project", project_name="my-project")

Development

# Install with dev dependencies
uv sync

# Run tests
uv run pytest tests/ -v

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

pyterametrics-0.1.1.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

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

pyterametrics-0.1.1-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file pyterametrics-0.1.1.tar.gz.

File metadata

  • Download URL: pyterametrics-0.1.1.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for pyterametrics-0.1.1.tar.gz
Algorithm Hash digest
SHA256 570bd78176c2ea2fdbd2c7989bf8b6a3603f5cfd16a212d33767aa558afbe67a
MD5 4a6c637d4776610476ab687bce1c8385
BLAKE2b-256 aeb370c7d3a9f5cf286d8f89cd24537b8bc6581bc33834beffc8d7342c8f04c6

See more details on using hashes here.

File details

Details for the file pyterametrics-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pyterametrics-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7ec31a00e088f10c073a545baaca861ad94d6fa62e356622d0b370182631651b
MD5 11afaa744919efeb8cd1d47ec4429c6a
BLAKE2b-256 ce44aae8fc5cc456db0953e57f802a55fecb7efacf99ddf8d0ae3ea57157e84a

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