Skip to main content

Official Python SDK for HashiCorp Terraform Cloud / Terraform Enterprise (TFE) API v2

Project description

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.

(Recommended) Using explicit config

import os
from pytfe import TFEClient, TFEConfig

config = TFEConfig(
    host="https://tfe.local",
    token="insert-your-token-here",
    retry_server_errors=True,
    timeout=30.0,
    user_agent="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 host 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.

Project details


Download files

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

Source Distribution

pytfe-0.0.1.tar.gz (84.4 kB view details)

Uploaded Source

Built Distribution

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

pytfe-0.0.1-py3-none-any.whl (122.3 kB view details)

Uploaded Python 3

File details

Details for the file pytfe-0.0.1.tar.gz.

File metadata

  • Download URL: pytfe-0.0.1.tar.gz
  • Upload date:
  • Size: 84.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for pytfe-0.0.1.tar.gz
Algorithm Hash digest
SHA256 43b97828b3423f4695a9145bc04b981dfc3db988adf95ba64707c5b0c653a276
MD5 5f10dad5c11d5178f9d47ebf0b4e7342
BLAKE2b-256 b0507750f362c37b39d29d5958310c8da24d5a296ccfbe73cdfad8273477546b

See more details on using hashes here.

File details

Details for the file pytfe-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pytfe-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 122.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for pytfe-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c86d89b1d4f1512ba1481dad9625b5218f67592e1fba895cbbba6e4528133e4f
MD5 f9969ce46496ce5d91e20f99ce248760
BLAKE2b-256 5e827c1e26457665f13764bf64eba4802bae721792f644171449b153fb4ecbf8

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