--- id: python-terraform version: "0.10.1" license: MIT license_treatment: permissive maintenance: aging --- # python-terraform — This is a python module provide a wrapper of terraform command line tool License: permissive · Maintenance: aging · Downloads: 236.9K/mo ## What it is and what it does python-terraform is a thin wrapper around the Terraform CLI that lets you run Terraform commands from Python code instead of shell scripts. It handles argument and option mapping (converting Python method calls and keyword arguments into Terraform CLI syntax) and captures stdout, stderr, and return codes for programmatic inspection. The wrapper supports all Terraform commands and provides special handling for flag-style options, boolean values, and multi-value parameters like `-target` and `-var`. You instantiate a Terraform object, optionally specifying a working directory and default variables, then call methods named after Terraform commands (e.g., `.apply()`, `.plan()`, `.destroy()`). The package handles the syntactic quirks of Terraform's option design—distinguishing between flag-style options (like `-no-color`) and value options (like `-refresh=true`)—so you don't have to construct command strings manually. By default it captures output; you can disable capture to see real-time output in the terminal. Use it for: - Automate infrastructure provisioning workflows in Python applications without shelling out to Terraform directly. - Build CI/CD pipelines that apply or plan Terraform configurations and parse the results programmatically. - Wrap Terraform operations in Python error handling and logging for better observability. - Generate Terraform commands dynamically based on runtime configuration and pass them through the wrapper. - Test Terraform configurations by running plan/validate commands and inspecting their output from Python. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Wraps the Terraform command-line tool, allowing you to invoke Terraform operations (apply, plan, destroy, import, etc.) directly from Python code and capture their output. Yes, if you need to invoke Terraform from Python and can tolerate aging maintenance. The package is stable and has no known vulnerabilities, but the last release was 2019-06-21. It works for basic Terraform automation, but verify compatibility with your Terraform version and Python environment before production use. High install friction (requires Terraform on PATH) is expected for this use case. ## Install pip install python-terraform uv add python-terraform poetry add python-terraform ## Installing python-terraform Before you install: High install friction: no runtime dependencies but requires Terraform itself to be installed and available on the system PATH. Maintenance is aging—last release was 2019-06-21, though the repository remains active with recent commits (2025-09-04). Beta-status package with modest adoption. License in practice: MIT license is permissive, imposing no significant restrictions on use or redistribution. You can use this package freely in commercial and private projects. Quickstart: from python_terraform import Terraform, IsFlagged tf = Terraform(working_dir='/path/to/terraform') return_code, stdout, stderr = tf.apply(no_color=IsFlagged, refresh=False, var={'key': 'value'}) Terraform must be installed and available on the system PATH for this wrapper to function. Verify before relying: - Whether the package works reliably with modern Terraform versions (last release 2019-06-21). - Python version compatibility beyond classifiers (Python 2 and 3 listed, but Python 2 is end-of-life). - Whether real-time output capture (capture_output parameter) works as documented across all platforms. ## Package facts - License: MIT (permissive) - Python support: unspecified - Install friction: high - Maintenance: aging - Downloads: 236.9K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags terraform python wrapper, call terraform from python, infrastructure as code automation, terraform cli python interface, invoke terraform commands programmatically, terraform output capture, python terraform integration, infrastructure-as-code, terraform-wrapper, cli-automation [View on SkillFed](https://skillfed.io/packages/python-terraform) · [View on PyPI](https://pypi.org/project/python-terraform/)