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.setup_tunnel


def setup_tunnel(
    domain:str, name:str, tunnel_name:str | None=None, proxied:bool=True
):

One-liner for VPS hosting. Creates (or reuses) a tunnel, sets up the CNAME subdomain, and returns (tunnel_id, token) ready for cloudflared_svc() in your docker-compose.

Usage in fastops: tid, token = setup_tunnel(“example.com”, “app”) # → app.example.com # then in Compose: # .svc(“cloudflared”, **cloudflared_svc(token_env=…)) with CF_TUNNEL_TOKEN=token


source

CF


def CF(
    token:NoneType=None, timeout:int=10, kw:VAR_KEYWORD
):

Cloudflare API wrapper using the official cloudflare Python SDK

Least-privilege token setup

Create a Custom Token in the Cloudflare dashboard (My Profile → API Tokens → Create Token):

Capability Required permission
dns_read / DNS ops Zone → DNS → Edit (scope to specific zone)
account_read / tunnel ops Account → Account Settings → Read
tunnel_read / tunnel ops Account → Cloudflare Tunnel → Edit

Use CF().verify() to confirm your token has the permissions it needs before running ops.

c = CF()
c.verify()
{'result': True}