Skip to main content

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

Project description

PyTerametrics

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 .

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.0.tar.gz (19.2 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.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyterametrics-0.1.0.tar.gz
Algorithm Hash digest
SHA256 80b5b746c7bbf475f3aef0a1310a423e38c3e514aebb194a90bbe84a4e1c9fce
MD5 656f47dc094b2050a8b409a1859468a7
BLAKE2b-256 7b7a020231dba3164ac5533fa5358fca68f297c106b09fc0fff2082b2a414e86

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyterametrics-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7eb239660aecf63b0d166019686217987cf609776e87faecb59354070d4537e
MD5 2ac9f0f1f93f2f118eeaaa8ed88e4a2e
BLAKE2b-256 ccd3528303acff47c8a06ba2462d4042956a4f21464e73b3f46d95ac063e6481

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