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

Threading: TerraformCommand can be called from multiple Python threads, but Terraform CLI execution is serialized inside the shared library because Terraform uses process-wide state. Use TerraformPool (or separate processes) if you need truly parallel Terraform operations.

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 run Terraform commands in parallel across worker processes:

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, CDK for Terraform, and Pulumi.

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.2-py3-none-win_amd64.whl (64.2 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3manylinux: glibc 2.35+ x86-64

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

Uploaded Python 3macOS 14.0+ x86-64

libterraform-0.15.2-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.2-py3-none-win_amd64.whl.

File metadata

  • Download URL: libterraform-0.15.2-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.23 {"installer":{"name":"uv","version":"0.11.23","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.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 52b0aee16ca47ddfd2b3c214c43e8320991651582c52d0a9f7e22cf9996e45de
MD5 1e3bbbde3e563ed47749bd6d691af81a
BLAKE2b-256 319d2ec70d4f1f8de620c486ddce0e610cb07a29f32316d556ce4f482695ca72

See more details on using hashes here.

File details

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

File metadata

  • Download URL: libterraform-0.15.2-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.23 {"installer":{"name":"uv","version":"0.11.23","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.2-py3-none-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 797d4b0e147f29e4fde0fbe47afe11fa5283ccd7fce7e895bbc7fedac60fcacf
MD5 7207a55ef71d30db51025f43642e5506
BLAKE2b-256 ee6a64966338219ee6defef9e7f21fa1d9a3f08bf5e0fcafc2c4b88985f561cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: libterraform-0.15.2-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.23 {"installer":{"name":"uv","version":"0.11.23","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.2-py3-none-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 20df2dfe5d961acf3d629f772edbe17f180de2c75f78cd0a9180e4b90c2081b1
MD5 6d9d3981d693486f7a6eb64194557f54
BLAKE2b-256 6c63a259994b5839aa4a1119672062186487ade9cc7e4ec305077430f0acb2d1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: libterraform-0.15.2-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.23 {"installer":{"name":"uv","version":"0.11.23","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.2-py3-none-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 4f5f6598ff7ef1d2f48cf28adc683450bd3bef2d43ecbbd8488164dfcaa77963
MD5 3d12a509097814323b88dfadf4ba71a5
BLAKE2b-256 6343f675542e2dfe68a3e30566704f92402c49a6ec079493ec6b24f182beedad

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