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 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
Release files for pyterametrics 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyterametrics-0.1.1.tar.gz | 19.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyterametrics-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.8 kB
Release files / pyterametrics-0.1.1.tar.gz
| Download URL | pyterametrics-0.1.1.tar.gz |
|---|---|
| Size | 19.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
570bd78176c2ea2fdbd2c7989bf8b6a3603f5cfd16a212d33767aa558afbe67a
|
|
BLAKE2b-256 checksum How to use checksums |
aeb370c7d3a9f5cf286d8f89cd24537b8bc6581bc33834beffc8d7342c8f04c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.22
|
Release files / pyterametrics-0.1.1-py3-none-any.whl
| Download URL | pyterametrics-0.1.1-py3-none-any.whl |
|---|---|
| Size | 18.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7ec31a00e088f10c073a545baaca861ad94d6fa62e356622d0b370182631651b
|
|
BLAKE2b-256 checksum How to use checksums |
ce44aae8fc5cc456db0953e57f802a55fecb7efacf99ddf8d0ae3ea57157e84a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.22
|