Skip to main content

Python binding for Terraform.

Project description

Python libterraform logo

Python libterraform

Python binding for Terraform. Bundles Terraform as a shared library so you can run Terraform commands and parse configurations from Python without a separate terraform binary.

Test PyPI Python Downloads

Language: English | 中文

Documentation: https://prodesire.github.io/py-libterraform/

Installation

pip install libterraform

Execution model: TerraformCommand and AsyncTerraformCommand use process-isolated execution by default, so Terraform's process-wide state does not leak into the caller process. Use backend="thread" only when you explicitly want the current-process backend. Use TerraformPool when you want to reuse worker processes or run independent Terraform operations in parallel.

Usage

from libterraform import TerraformCommand, TerraformConfig

# Run Terraform commands
cli = TerraformCommand("path/to/module")
cli.init(check=True)
cli.plan(check=True)

# Parse Terraform configuration
module, diagnostics = TerraformConfig.load_config_dir("path/to/module")

Asyncio applications can use AsyncTerraformCommand to await Terraform operations without blocking the event loop:

from libterraform import AsyncTerraformCommand

cli = AsyncTerraformCommand("path/to/module")
await cli.validate(check=True)

Use TerraformPool to reuse worker processes and run Terraform commands in parallel:

from libterraform import TerraformPool

with TerraformPool(max_workers=4) as pool:
    for result in pool.map("validate", ["modules/a", "modules/b"], check=True):
        print(result.value["valid"])

The pool starts worker processes, so this must run under an if __name__ == "__main__": guard. The Quick Start creates a runnable module in seconds, and Parallel Execution has a complete pool example.

If you are choosing between Python Terraform options, see Choosing a Python Terraform Integration for a comparison with python-terraform, TofuPy, direct subprocess, Pulumi, CDKTN, and deprecated CDK for Terraform.

Contributing

Install uv, then:

make install        # Install dependencies and Git hooks
make build          # Build the shared library
make test           # Run tests
make lint           # Run linters
make doc-serve      # Preview documentation site

See the Development Guide for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

libterraform-0.15.3-py3-none-win_amd64.whl (64.2 MB view details)

Uploaded Python 3Windows x86-64

libterraform-0.15.3-py3-none-manylinux_2_35_x86_64.whl (64.0 MB view details)

Uploaded Python 3manylinux: glibc 2.35+ x86-64

libterraform-0.15.3-py3-none-macosx_14_0_x86_64.whl (36.2 MB view details)

Uploaded Python 3macOS 14.0+ x86-64

libterraform-0.15.3-py3-none-macosx_10_15_universal2.whl (33.5 MB view details)

Uploaded Python 3macOS 10.15+ universal2 (ARM64, x86-64)

File details

Details for the file libterraform-0.15.3-py3-none-win_amd64.whl.

File metadata

  • Download URL: libterraform-0.15.3-py3-none-win_amd64.whl
  • Upload date:
  • Size: 64.2 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for libterraform-0.15.3-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 e21840dcaa5d44e2f273d63aa7be66ed751d78a7e429d933e67e522a2e447756
MD5 b131ceb50ff031b3dae9c262f7d97d65
BLAKE2b-256 5c44b1fa0653f97ad6512c084f418c8caa0df3a215f980b3f233133d3ed8d022

See more details on using hashes here.

File details

Details for the file libterraform-0.15.3-py3-none-manylinux_2_35_x86_64.whl.

File metadata

  • Download URL: libterraform-0.15.3-py3-none-manylinux_2_35_x86_64.whl
  • Upload date:
  • Size: 64.0 MB
  • Tags: Python 3, manylinux: glibc 2.35+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for libterraform-0.15.3-py3-none-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 d7dd30aef7bf2eaa440c564954b9aec43cfb163174fe36d9097c4192cf24a75c
MD5 ab7d65a4955d93b3b7cce4e34f2fbbe4
BLAKE2b-256 6173b3f2d13fb74ac9ef8a77b1baf732e29a3c38f05974a2487c77ecdbcd735d

See more details on using hashes here.

File details

Details for the file libterraform-0.15.3-py3-none-macosx_14_0_x86_64.whl.

File metadata

  • Download URL: libterraform-0.15.3-py3-none-macosx_14_0_x86_64.whl
  • Upload date:
  • Size: 36.2 MB
  • Tags: Python 3, macOS 14.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for libterraform-0.15.3-py3-none-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 f6396a5bcfd413bcfda19bdd1c2129150e4bd27e58cfc3363746c9f27a468f83
MD5 7693d27c592a5e8b270e43afa09fe34d
BLAKE2b-256 0c7f527f5236143be419306661e53a29ae3b325689572216dcad9154d25ad188

See more details on using hashes here.

File details

Details for the file libterraform-0.15.3-py3-none-macosx_10_15_universal2.whl.

File metadata

  • Download URL: libterraform-0.15.3-py3-none-macosx_10_15_universal2.whl
  • Upload date:
  • Size: 33.5 MB
  • Tags: Python 3, macOS 10.15+ universal2 (ARM64, x86-64)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for libterraform-0.15.3-py3-none-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 710358bdf72690a0c8e2114f99e52a9f344c7a4c672a73e92f0b8b485264d778
MD5 e22212685a492d20b4291abcc665ea2c
BLAKE2b-256 eab826f2023e69ff8ebe671ac25e62fb9291a1bf368c6f2e681ca32e143b2c92

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