cloudflare

Cloudflare DNS and tunnel management via the official Python SDK

CF

Thin wrapper around the official cloudflare Python SDK. Token is read from the CLOUDFLARE_API_TOKEN environment variable by default.


source

CF


def CF(
    token:NoneType=None
):

Cloudflare API wrapper using the official cloudflare Python SDK

# Instantiation test: object created without raising when given a mock token
import os as _os

cf = CF(token='fake-token-for-testing')
assert cf._c is not None
print('CF instantiation OK')

# Real API calls gated on CF_TEST=1
if _os.environ.get('CF_TEST') == '1':
    cf = CF()  # uses CLOUDFLARE_API_TOKEN from env
    zs = cf.zones()
    names = [z['name'] for z in zs]
    print(f'zones: {names}')
    print('CF.zones() OK')
else:
    print('Skipping real API tests (set CF_TEST=1 to enable)')
CF instantiation OK
Skipping real API tests (set CF_TEST=1 to enable)

source

dns_record


def dns_record(
    domain, name, content, type:str='A', proxied:bool=False, token:NoneType=None
)->dict:

Upsert a DNS record. Reads CLOUDFLARE_API_TOKEN from env if token not given.