Python-powered structural DSL for authoring native HCL2.
Project description
PHCL
PHCL is a Python DSL that compiles to native HCL2 and enables dynamic infrastructure generation.
Idea
In Terraform, HCL is great for describing infrastructure, but not for generating it dynamically. As complexity grows, configuration turns into a combinatorial explosion and becomes hard to maintain.
It also struggles when infrastructure depends on external data — YAML, JSON, databases, APIs — where data needs to be loaded, transformed, and combined before turning into resources.
PHCL moves generation, composition, and data processing into Python while keeping the output as clean, readable HCL2.
At the same time, PHCL keeps declaration code highly recognizable and as close as possible to native HCL2: you gain Python's expressive power without giving up the familiar shape of HCL-style authoring.
Architecture
PHCL is built around a small declarative core that treats Python classes as reusable HCL declaration shapes.
Classes as declarations— class bodies describe HCL structures directly instead of building an intermediate runtime config format.Inheritance as refinement— subclasses extend and override existing declaration shapes, making reuse and specialization native to the model.Registry and rendering— concrete top-level declarations are collected and emitted as plain HCL2.Shared core, thin dialects— Terraform-, Packer-, and other HCL2-oriented layers can stay thin on top of the same PHCL foundation.
For example, instead of writing Terraform like this:
resource "aws_instance" "web" {
ami = "ami-123"
instance_type = "t3.small"
}
PHCL aims to let you express the same declaration shape like this:
class Web(Resource["aws_instance"]):
ami = "ami-123"
instance_type = "t3.small"
See also: Documentation
CLI
The CLI supports:
- compile a single Python file into HCL output
- walk a directory and compile each file independently
- emit generated files next to sources, into another directory, or to stdout
- read per-file output settings from a module-level
PHCLconfig, defaulting output to.hcl
This makes PHCL easy to adopt incrementally:
- generate one file beside existing HCL
- generate one subtree into a separate output directory
- generate an entire repository in place
- generate an entire repository into another target tree
See also: CLI docs
Installation
The package exposes a phcl CLI entrypoint:
pip install phcl
To install the Terraform dialect layer together with PHCL:
pip install 'phcl[terraform]'
Then:
phcl build <target>
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
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 phcl-0.3.0.tar.gz.
File metadata
- Download URL: phcl-0.3.0.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e197c52dbd1d175c5f30b178da7a44ba608f0f98f15e9c0048ad7e95e4c10373
|
|
| MD5 |
d49b1d10f6c6e5ac9db14ec9c55f3e62
|
|
| BLAKE2b-256 |
040d1846c2ac94132c6923716132f5a9d683f076bf4b69d9264143f07293c79b
|
File details
Details for the file phcl-0.3.0-py3-none-any.whl.
File metadata
- Download URL: phcl-0.3.0-py3-none-any.whl
- Upload date:
- Size: 25.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2652cbb3456306bba5f853ace2599101863ce551790fca8f95839f562c92737c
|
|
| MD5 |
c0dad93d605b554e8fc0007a8469aaa0
|
|
| BLAKE2b-256 |
38bcb3921032deba9d5320656b8bed63fab286fe299d417aae6c32f3b07635dd
|