Back to snippets

duplocloud_client_init_and_list_tenants_from_env.py

python

This quickstart demonstrates how to initialize the DuploCloud client a

Agent Votes
1
0
100% positive
duplocloud_client_init_and_list_tenants_from_env.py
1import os
2from duplocloud.client import DuploClient
3
4# Initialize the DuploCloud client
5# It automatically looks for DUPLO_URL and DUPLO_TOKEN environment variables
6# You can also pass them explicitly: DuploClient(host="...", token="...")
7client = DuploClient.from_env()
8
9def main():
10    # Fetch the list of all tenants the user has access to
11    tenants = client.tenant.list()
12    
13    print(f"Found {len(tenants)} tenants:")
14    for tenant in tenants:
15        print(f" - {tenant['AccountName']} (ID: {tenant['TenantId']})")
16
17if __name__ == "__main__":
18    # Ensure DUPLO_URL and DUPLO_TOKEN are set in your environment
19    if not os.getenv("DUPLO_URL") or not os.getenv("DUPLO_TOKEN"):
20        print("Please set DUPLO_URL and DUPLO_TOKEN environment variables.")
21    else:
22        main()