Skip to content

Python libterraform

libterraform is a Python binding for Terraform. It bundles Terraform as a shared library and exposes Python APIs for running Terraform CLI commands and parsing Terraform configuration directories.

What It Provides

  • TerraformCommand for invoking Terraform commands from Python.
  • AsyncTerraformCommand for awaiting Terraform commands in asyncio applications without blocking the event loop.
  • TerraformConfig for loading .tf and .tf.json files into Terraform's internal module representation.
  • Wheels that include the Terraform shared library, so callers do not need a separate terraform executable on PATH.

Start Here

Version Comparison

libterraform Terraform
0.15.0 1.15.5
0.14.0 1.14.9
0.13.0 1.13.5
0.12.0 1.12.2
0.11.0 1.11.4
0.10.0 1.10.5
0.9.0 1.9.8
0.8.2 1.8.4
0.7.0 1.6.6
0.6.0 1.5.7
0.5.0 1.3.0
0.4.0 1.2.2
0.3.1 1.1.7

Runtime Constraints

TerraformCommand is safe to call from multiple Python threads, but Terraform CLI execution is serialized inside the shared library. Terraform still uses process-wide state such as the current working directory, stdio, checkpoint state, and plugin client cleanup, so true parallel Terraform operations require separate processes.

AsyncTerraformCommand has the same Terraform execution constraint. It makes the synchronous API awaitable for asyncio applications, but it does not make Terraform CLI execution parallel inside one Python process.

Terraform operations can still affect real infrastructure, so use apply, destroy, state commands, imports, and tests with the same caution as the Terraform CLI.