Skip to main content

A small client library for the Terraform Enterprise REST API.

Project description


This is an object oriented client API for Terraform Enterprise written in Python. The methods included in this library generally map 1 to 1 in terms of function naming conventions to terraform enterprise documentation, so please review the available methods if you are uncertain on this library's usage.

Happy Terraforming!


This module can be installed via pip, this library is compatible with python3.7. Install it with pip for python3.

pip3 install --user pyterprise


Note: Some examples are covered here, but more are covered in the examples directory for more basic use-cases of this api.

First import the module and authenticate using the init method, you can retrieve a token from the terraform enterprise UI.

import pyterprise

tfe_token = 'TOKENHERE'
client = pyterprise.Client()

# Supply your token as a parameter and the url for the terraform enterprise server.
# If you are not self hosting, use the one provided by hashicorp.
client.init(token=tfe_token, url='')

After instantiating your client you need to set an organization to access workspaces and more. From the client base-level you can also create/destroy/list organizations:

# Set the organization
org = client.set_organization(id='my-organization')

# Base level Methods:
#organizations = client.list_organizations()
#client.create_organization(name='test', email='')

This organization object org has access to workspaces, ssh keys and other methods (Check source code/examples for more):

# Creating a workspace with VCS example:
vcs_options = {
    "identifier": "my-github-org/my-repo",
    "oauth-token-id": "ot-xxxxxxxxxxx",
    "branch": "master",
    "default-branch": False

# Or Delete a workspace at the organization level by name.

You can access workspace objects through your organization client object, which gives you access to runs, plans, statefiles, ssh-key additions and variables.

# Get a single workspace client object, 
# you can also list or search all workspace objects using the corresponding methods.
workspace = org.get_workspace('test-workspace')

# Get a list of all workspace objects in an organization.
for workspace in org.list_workspaces():

# Print some workspace attributes. Additionally you can access all attributes 
# as a dictionary by printing  the 'workspace' object at top level.                     
print(,, workspace.created_at)

# Run Workspace, you can destroy by changing the destroy flag.

# Plan and Apply in workspace with log output

# Update workspace, arguments identical to create function. Omit arguments to not alter.

# Create a variable in a workspace
workspace.create_variable(key='foo', value='bar', sensitive=False, category='env')

# Print all variables for a workspace. 
# Variables objects also have functions for updating and deleting.
for variable in workspace.list_variables():

# Apply latest unconfirmed plan in workspace. You can additionally print all attributes by print object at top level.
# or use other runs methods i.e. cancel, discard and get plan output etc.
for run in workspace.list_runs(page=1, page_size=20):
    if run.status == 'planned':
        run.apply(comment='Running latest plan.')

Please consult module contents, examples or terraform enterprise api documentation for more api client usage. This API does not currently cover administrative functions and teams, help is wanted for expanding functionality. Thank you.

API Coverage/Helper Methods

  • Method Coverage Complete.
  • Method Coverage Complete
  • Method Coverage Complete
  • Method Coverage Complete
  • Method Coverage Complete
  • Method Coverage Complete

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

pyterprise-0.0.15.tar.gz (10.7 kB view hashes)

Uploaded source

Built Distribution

pyterprise-0.0.15-py3-none-any.whl (11.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page