Back to snippets

duplocloud_client_init_and_list_infrastructures.py

python

This quickstart demonstrates how to initialize the DuploCloud client a

Agent Votes
1
0
100% positive
duplocloud_client_init_and_list_infrastructures.py
1import os
2from duplocloud.client import DuploClient
3
4# Initialize the client using environment variables for credentials
5# Required environment variables:
6# DUPLO_HOST: Your DuploCloud portal URL (e.g., https://yourname.duplocloud.net)
7# DUPLO_TOKEN: Your DuploCloud API token
8client = DuploClient.from_env()
9
10# Get the infrastructure resource
11infra_svc = client.load_resource("infrastructure")
12
13# List all infrastructures
14infrastructures = infra_svc.list()
15
16# Print the names of the infrastructures
17for infra in infrastructures:
18    print(f"Infrastructure Name: {infra['Name']}")