Skip to main content

Python-powered structural DSL for authoring native HCL2 configuration.

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 PHCL config, 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

phcl-0.5.1.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phcl-0.5.1-py3-none-any.whl (34.6 kB view details)

Uploaded Python 3

File details

Details for the file phcl-0.5.1.tar.gz.

File metadata

  • Download URL: phcl-0.5.1.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for phcl-0.5.1.tar.gz
Algorithm Hash digest
SHA256 1b579d5631a6585d08773dec0b68663bfba6856816a87c8e8ab951511f815afc
MD5 e5a3c5dc99c45aa78d8048a2f2f6197a
BLAKE2b-256 b7bb03fae9f2bb832088bf0247654cce653d0469384ec42faf21deb31d23cb29

See more details on using hashes here.

File details

Details for the file phcl-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: phcl-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 34.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for phcl-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ea5cb52a0561e19df44aeb4091704cb85b437abff3a8f509076fafd6abbb125a
MD5 119c4a296332c0c01d19dcdcfaf2388b
BLAKE2b-256 ae0509aeef6a247f00c4e6a413ee154e86a913f3c918e4c9d7610130a575c2d4

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