No description
  • Python 99.5%
  • Shell 0.3%
  • Makefile 0.2%
Find a file
Ritik Rajdev 30fcdafdeb
Merge pull request #112 from hashicorp/compliance/add-headers
[COMPLIANCE] Add Copyright and License Headers
2026-04-02 08:16:01 +05:30
.github [COMPLIANCE] Add Copyright and License Headers 2026-03-10 08:50:17 +00:00
.hooks Initial Client and Config class for tfe (#5) 2025-08-27 15:16:45 +05:30
bin [COMPLIANCE] Add Copyright and License Headers 2026-03-10 08:50:17 +00:00
docs Release 0.1.1 (#59) 2026-01-08 14:10:34 +05:30
examples [COMPLIANCE] Add Copyright and License Headers 2026-03-10 08:50:17 +00:00
src/pytfe [COMPLIANCE] Add Copyright and License Headers 2026-03-10 08:50:17 +00:00
tests [COMPLIANCE] Add Copyright and License Headers 2026-03-10 08:50:17 +00:00
.gitignore add pypi push script 2025-10-28 15:01:06 +05:30
CHANGELOG.md Release 0.1.2 (#82) 2026-02-16 12:55:32 +05:30
LICENSE Add CI/CD actions (#3) 2025-08-26 11:56:17 +05:30
Makefile lint fixes 2025-10-09 16:12:52 +05:30
pyproject.toml Release 0.1.2 (#82) 2026-02-16 12:55:32 +05:30
README.md Release 0.1.1 (#59) 2026-01-08 14:10:34 +05:30

HCP Terraform and Terraform Enterprise Python Client (pyTFE)

PyPI Python Versions Test License Issues

The official Python API client for HCP Terraform and Terraform Enterprise.

This client targets the HCP Terraform V2 API. As Terraform Enterprise is the self-hosted distribution of HCP Terraform, this client supports both HCP Terraform and Terraform Enterprise use cases. In this repository and API, we refer to the platform generically as Terraform Enterprise unless a feature is explicitly called out as only supported in one or the other (rare).

Version Information

We follow Semantic Versioning. During the initial alpha period we use 0.y.z:

  • Minor (0.y.z → 0.(y+1).z): new, backwards-compatible features and enhancements.
  • Patch (0.y.z → 0.y.(z+1)): bug fixes and performance improvements.
  • Occasionally, a function signature change that fixes incorrect behavior may appear in a minor version.

Example Usage

Construct a new pyTFE client, then use the resource services on the client to access different parts of the Terraform Enterprise API. The following example lists all organizations.

from pytfe import TFEClient, TFEConfig

config = TFEConfig(
    address="https://tfe.local",
    token="insert-your-token-here",
    timeout=30.0,
    user_agent_suffix="example-app/0.1 pytfe/0.1",
)

client = TFEClient(config)

orgs = client.organizations.list()
for org in orgs.items:
    print(org.name)

Using the default config with environment variables

The default configuration reads the TFE_ADDRESS and TFE_TOKEN environment variables.

  1. TFE_ADDRESS — URL of an HCP Terraform or Terraform Enterprise instance. Example: https://tfe.local
  2. TFE_TOKEN — An API token for the HCP Terraform or Terraform Enterprise instance.

Environment variables are used as a fallback when address or token are not provided explicitly:

Using the default configuration

from pytfe import TFEClient, TFEConfig

# Equivalent to providing no values; falls back to env vars if set.
client = TFEClient(TFEConfig())
orgs = client.organizations.list()
for org in orgs.items:
    print(org.name)

When host or token is empty

from pytfe import TFEClient, TFEConfig

config = TFEConfig(address="", token="")
client = TFEClient(config)

orgs = client.organizations.list()
for org in orgs.items:
    print(org.name)

Documentation

Examples

See the examples/ directory for runnable snippets covering common workflows (workspaces, variables, configuration versions, runs/plans/applies, state, agents).

Running tests

See TESTS.md. Typical flow:

pip install -e .[dev]
make test

Issues and Contributing

See CONTRIBUTING.md. We welcome issues and pull requests.

Releases

See RELEASES.md.

License

This project is licensed under the MPL-2.0. See LICENSE.