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, 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}
# setup_tunnel: subdomain
tid, token = c.setup_tunnel('sankalpa.sh', 'app')   # → app.sankalpa.sh
tid, token
('b59c4690-7c89-4ab7-9421-176afa6e2dfa',
 'eyJhIjoiOTg3ODZiMGRlMTM5OTE0YmVkNGMyYjdmNGYwYzg4YjkiLCJ0IjoiYjU5YzQ2OTAtN2M4OS00YWI3LTk0MjEtMTc2YWZhNmUyZGZhIiwicyI6ImVJN1RyWE1RK1BvU09nQUp2UG5uWHdzT0h0TFRlU1FMd1ZwU1lXSW1PVXhJWWxseWhnL21DeW1DRTJialRIcEM1QW90aGRkaXZzc3VCQ0RUSEdVZ3dnPT0ifQ==')
# setup_tunnel: apex domain (no name → CNAME-flattened at root)
tid_apex, token_apex = c.setup_tunnel('sankalpa.sh')   # → example.com
tid_apex, token_apex
('6791fbaf-e848-422b-8fc7-35afc3e435d0',
 'eyJhIjoiOTg3ODZiMGRlMTM5OTE0YmVkNGMyYjdmNGYwYzg4YjkiLCJ0IjoiNjc5MWZiYWYtZTg0OC00MjJiLThmYzctMzVhZmMzZTQzNWQwIiwicyI6IjNNOVhaQm1IWkJPdDl3a28rRUxza3dmaWZ3ZUpqcmpSV0lxdDNRcExwTHFEZVJxaFRyeGRWZnR3M082TzJ1cFNOc0FYSXNRMGx0UjdhaE1SbVFxNDNnPT0ifQ==')
# tunnel_id: look up by name; delete_tunnel: clean up by name
c.tunnel_id('app')                          # → UUID
c.delete_tunnel(c.tunnel_id('app'))
c.delete_tunnel(c.tunnel_id('sankalpa.sh'))

Helpers

repo_root finds the nearest .git ancestor. mv_skill_md copies the bundled SKILL.md into a project’s agent skill directories so coding agents pick it up automatically.


source

mv_skill_md


def mv_skill_md(
    dry_run:bool=True, dir:NoneType=None
)->None:

Copy bundled SKILL.md to .agents/skills/cfeasy/ and .claude/skills/cfeasy/ at project root.


source

repo_root


def repo_root(
    
)->Path:

Find the root of the current git repository, or None if not in a repo.