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
Release history Release notifications | RSS feed
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)
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80b5b746c7bbf475f3aef0a1310a423e38c3e514aebb194a90bbe84a4e1c9fce
|
|
| MD5 |
656f47dc094b2050a8b409a1859468a7
|
|
| BLAKE2b-256 |
7b7a020231dba3164ac5533fa5358fca68f297c106b09fc0fff2082b2a414e86
|
File details
Details for the file pyterametrics-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyterametrics-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7eb239660aecf63b0d166019686217987cf609776e87faecb59354070d4537e
|
|
| MD5 |
2ac9f0f1f93f2f118eeaaa8ed88e4a2e
|
|
| BLAKE2b-256 |
ccd3528303acff47c8a06ba2462d4042956a4f21464e73b3f46d95ac063e6481
|