A Python client library for interacting with the Pulumi Cloud API. This client provides a simple interface for managing Pulumi resources programmatically, including stacks, projects, organizations, and policies.
Install the package using pip:
pip install pulumi-cloud-client
Or with Poetry:
poetry add pulumi-cloud-client
Authentication is handled using a Pulumi access token:
from pulumi_cloud_client.client import PulumiClient
# Authenticate with token from environment variable
client = PulumiClient(
access_token="your-pulumi-access-token",
base_url="https://api.pulumi.com" # Optional, defaults to https://api.pulumi.com
)
# List all organizations you have access to
organizations = client.organizations.list()
for org in organizations:
print(f"Organization: {org.name}")
# List projects in an organization
projects = client.projects.list("my-organization")
for project in projects:
print(f"Project: {project.name}")
# Get a specific project
project = client.projects.get("my-organization", "my-project")
# List stacks in a project
stacks = client.stacks.list("my-organization", "my-project")
for stack in stacks:
print(f"Stack: {stack.full_name}, Resources: {stack.resource_count}")
# Get stack details
stack = client.stacks.get("my-organization", "my-project", "dev")
# Update stack tags
client.stacks.update_tags("my-organization", "my-project", "dev", {"environment": "development"})
# Transfer a stack to a different organization
transferred_stack = client.stacks.transfer_stack(
"source-org", "my-project", "dev", "destination-org"
)
print(f"Stack transferred to: {transferred_stack.full_name}")
- Stacks: Create, list, update, delete, and transfer stacks
- Projects: List and get project details
- Organizations: List organizations and manage team members
- Policies: List and get policy packs
The client raises PulumiAPIError
for API-related errors:
from pulumi_cloud_client.exceptions import PulumiAPIError
try:
client.stacks.get("org", "project", "non-existent-stack")
except PulumiAPIError as e:
print(f"API Error: {e.message} (Status code: {e.status_code})")
See the examples directory for more detailed examples of how to use the client.
Contributions are welcome! See CONTRIBUTING.md for development setup and guidelines.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.