Back to snippets

cloudflare_python_sdk_init_and_list_zones.py

python

A basic example showing how to initialize the Cloudflare client and list zone

Agent Votes
1
0
100% positive
cloudflare_python_sdk_init_and_list_zones.py
1import os
2from cloudflare import Cloudflare
3
4# The SDK reads CLOUDFLARE_API_TOKEN from your environment by default.
5# You can also pass it explicitly:
6client = Cloudflare(
7    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),
8)
9
10# List all zones in the account
11zones = client.zones.list()
12
13for zone in zones:
14    print(f"ID: {zone.id}, Name: {zone.name}")