cloudflare made easy
Project description
cfeasy
cfeasy is a thin wrapper around the official Cloudflare Python SDK. It lets you create DNS records and set up Zero Trust tunnels from Python with minimal boilerplate — ideal for VPS automation and self-hosting.
verify() is a safe, read-only check — it lists your zones and tunnels
and confirms the token can reach both. If it returns
{'result': False}, your token is missing permissions. Set those up
first.
API Token Setup
cfeasy needs a Custom Token — not a Global API Key. Go to dash.cloudflare.com/profile/api-tokens → Create Token → Custom Token and add these three permissions:
| Capability | Resource | Permission |
|---|---|---|
| DNS read/write | Zone → DNS | Edit (scope to your zone) |
| Account info | Account → Account Settings | Read |
| Tunnel management | Account → Cloudflare Tunnel | Edit |
DNS Records
upsert_record is the main DNS method — it creates a record if it
doesn’t exist, or replaces it if one already exists with the same name
and type. No stale duplicates.
You can use cfeasy in any Python environment — a Jupyter notebook, a
script, or an interactive shell. Just import
CF and initialize
it with your API token (or set the CLOUDFLARE_API_TOKEN environment
variable and skip the argument). just go from cfeasy import * and
you’re ready to manage your DNS and tunnels.
from cfeasy import *
c = CF() # set CLOUDFLARE_API_TOKEN env var and just do CF() or pass a token directly CF('your-token-here')
# Confirm your token has the right permissions before doing anything
c.verify() # → {'result': True}
{'result': True}
# A record pointing "app.angalama.com" at an IP
dom, nm = 'angalama.com', 'app'
c.upsert_record(dom, nm, "1.2.3.4")
{'name': 'app.angalama.com',
'type': 'A',
'comment': None,
'content': '1.2.3.4',
'proxied': False,
'settings': {'ipv4_only': None, 'ipv6_only': None},
'tags': [],
'ttl': 1,
'id': '3819309b81252192134793a601f43737',
'created_on': datetime.datetime(2026, 3, 22, 20, 3, 29, 872980, tzinfo=TzInfo(0)),
'meta': {},
'modified_on': datetime.datetime(2026, 3, 22, 20, 3, 29, 872980, tzinfo=TzInfo(0)),
'proxiable': True,
'comment_modified_on': None,
'tags_modified_on': None}
Tunnels
A Cloudflare
Tunnel
creates an outbound-only connection from your server to Cloudflare’s
edge — no open firewall ports, no public IP needed. Traffic hits
app.example.com, Cloudflare routes it through the tunnel to your
cloudflared process, which forwards it to your local service.
The three pieces you need: 1. A tunnel — a named tunnel registered
with your Cloudflare account 2. A DNS CNAME — pointing your
subdomain at <tunnel-id>.cfargotunnel.com 3. A token — passed to
cloudflared so it knows which tunnel to connect to
# Step 1: create the tunnel
tname = 'my-app'
exists = L.filter(lambda x: x.get('name') == tname)
tid = first(t)['id'] if (t:=exists(c.tunnels())) else c.create_tunnel(tname)['id']
# Step 2: point the subdomain at it (CNAME → <tid>.cfargotunnel.com)
c.tunnel_cname(dom, nm, tid)
# Step 3: get the token for cloudflared
token = c.tunnel_token(tid)
setup_tunnel — Everything in One Call
All three steps above collapse into a single method. If a tunnel with that name already exists, it reuses it rather than creating a duplicate.
| What it does | Result |
|---|---|
Creates (or reuses) a tunnel named "app" |
Idempotent — safe to call repeatedly |
Wires up app.example.com as a proxied CNAME |
Points at <tid>.cfargotunnel.com |
Returns (tunnel_id, token) |
Pass token as CF_TUNNEL_TOKEN to cloudflared |
Pass name to point a subdomain, or omit it to point the apex domain
directly (Cloudflare flattens the CNAME automatically).
# Subdomain tunnel: app.example.com
tid, token = c.setup_tunnel(dom, nm)
tid, token
# Apex tunnel: example.com itself (no subdomain)
tid_apex, token_apex = c.setup_tunnel(dom)
tid_apex, token_apex
# Look up a tunnel ID by name — useful when you only have the name, not the ID
c.tunnel_id(nm) # → UUID for the "app" tunnel
c.tunnel_id(dom) # → UUID for the apex tunnel
# Cleanup — delete by name instead of needing to track the ID
c.delete_tunnel(c.tunnel_id(nm))
c.delete_tunnel(c.tunnel_id(dom))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cfeasy-0.0.4.tar.gz.
File metadata
- Download URL: cfeasy-0.0.4.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87805b985333f286b0745d65da0235aa078b75396ea1c798cda1de259a38e22f
|
|
| MD5 |
89e56f73813c756e61080152d4d53862
|
|
| BLAKE2b-256 |
02b08f0e82a6b2224efe239ebd91cfe50d9f5db9fa88d3daff848ea357d4ec3f
|
File details
Details for the file cfeasy-0.0.4-py3-none-any.whl.
File metadata
- Download URL: cfeasy-0.0.4-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe0fd6a60737935008a9d1b2d2720b9f12d72ec91e496ffe651c0210c516cebf
|
|
| MD5 |
3831f3de73a3e97857575141bde43aa4
|
|
| BLAKE2b-256 |
5dcf44e49c29009f3aa9bac94ec2d7bb1f3eddaeae14244e28dcfa71e1434acb
|