PHCL
PHCL provides an authoring and generation layer for HCL-based tools such as Terraform, OpenTofu, and Packer.
PHCL does not assume a full project rewrite.
You can keep your existing Terraform/OpenTofu codebase and use PHCL only for a single .tf file that needs to be parameterized or generated from external data.
PHCL code is not an application framework or runtime model. There is no entry point.
PHCL .py files are rendered directly and independently into the corresponding .tf files, so they can be mixed with regular HCL files inside the same project:
src/network.py → src/network.tf
HCL declarations are written as Python classes. The source stays close to the shape of HCL while adding composition, dynamic generation, and integration with Python data and logic.
Example
class Logs(Resource["aws_s3_bucket"]):
bucket = "app-logs"
force_destroy = True
tags = {
"Name": "logs",
"ManagedBy": "PHCL",
}
class BucketId(Output):
value = Logs._.id
renders as native HCL:
resource "aws_s3_bucket" "logs" {
bucket = "app-logs"
force_destroy = true
tags = {
Name = "logs"
ManagedBy = "PHCL"
}
}
output "bucket_id" {
value = aws_s3_bucket.logs.id
}
Use Cases
PHCL is useful when HCL is derived from project data rather than written directly: RBAC rules, users, roles, regions, environments, inventories, service definitions, or other source-of-truth records. When used alongside an existing Python project, PHCL can share data, constants, validation, and project logic, adapting generated configuration to the application it belongs to.
For example, repeated declarations can be generated from normal Python data:
BUCKETS = {
"logs": {"bucket": "app-logs"},
"assets": {"bucket": "app-assets"},
}
@generate(BUCKETS)
class Bucket(Resource["aws_s3_bucket"]):
bucket = this.value["bucket"]
tags = {"Name": this.key}
PHCL also fits incremental adoption in existing HCL projects: generate one file, one subtree, or one environment at a time, while the output remains plain HCL that can live next to hand-written configuration.
CLI
Install PHCL:
pip install phcl
Install PHCL with the Terraform dialect:
pip install 'phcl[terraform]'
Build one file or a source tree:
ENV=dev phcl build src --out-dir envs/dev/
Example output:
==> build src
write src/backend.py -> envs/dev/backend.tf
write src/database.py -> envs/dev/database.tf
write src/network.py -> envs/dev/network.tf
write src/security.py -> envs/dev/security.tf
==> done in 0.06s
13 written, 0 skipped, 0 failed
Documentation
Metadata
Release files for phcl 0.5.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| phcl-0.5.3.tar.gz | 26.3 kB | Without provenance | Details for phcl-0.5.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| phcl-0.5.3-py3-none-any.whl | Python 3 | none | any | Details for phcl-0.5.3-py3-none-any.whl |
Total release size: 56.7 kB
Release files / phcl-0.5.3.tar.gz
| Download URL | phcl-0.5.3.tar.gz |
|---|---|
| Size | 26.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e560f20b3be031740dae51b610ccd5a3c7aeb3ae7138f8c48b9f66350f554994
|
|
BLAKE2b-256 checksum How to use checksums |
c2fb0e0785f6a3dffc76fe41e8f98ec77284bbe20e4ac77ee20de2ce69ada10a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / phcl-0.5.3-py3-none-any.whl
| Download URL | phcl-0.5.3-py3-none-any.whl |
|---|---|
| Size | 30.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a5a681136aa2e0ae10a3249bf6a4b67f0df621f95a72a5dedd54afc7dac6157
|
|
BLAKE2b-256 checksum How to use checksums |
10f80cebc475e9a4a8f89876d0cadf72fd566e25e0d93c9dd65de7e8766f0a7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for phcl 0.5.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.