Pyflared wraps the official cloudflared binary and the Cloudflare API to provide a seamless CLI experience for
creating and managing Cloudflare Tunnels. No more manual token juggling or complex configurations—just simple commands
to expose your local services to the internet.
- 🚀 Quick Tunnels — Spin up instant, temporary public URLs for local services with a single command
- 🔗 DNS-Mapped Tunnels — Create persistent tunnels with automatic DNS record management
- 🧹 Automatic Cleanup — Orphan tunnel and stale DNS record detection & removal
- 📦 Batteries Included — Bundles the
cloudflaredbinary, no separate installation required - 🐳 Docker Ready — Run as a container with minimal setup
- 🔐 Secure by Design — API tokens are never logged or exposed; uses Pydantic's
SecretStr
uv tool install pyflaredpip install pyflareddocker pull ghcr.io/azmainmahatab/pyflared:latest
docker run --rm ghcr.io/azmainmahatab/pyflared --helpExpose a local service instantly with a temporary trycloudflare.com URL:
pyflared tunnel quick 8000This creates a public URL (e.g., https://random-name.trycloudflare.com) pointing to localhost:8000.
Create a persistent tunnel with your own domain:
pyflared tunnel mapped api.example.com=localhost:8000 web.example.com=localhost:3000This will:
- Create a new Cloudflare Tunnel
- Configure DNS records for your domains
- Route traffic to your local services
Note: Requires a Cloudflare API token with tunnel and DNS permissions. Set via
CLOUDFLARE_API_TOKENenvironment variable or enter when prompted.
Remove stale tunnels and DNS records created by pyflared:
pyflared tunnel cleanuppyflared --help
| Command | Description |
|---|---|
pyflared version |
Show the bundled cloudflared version |
pyflared tunnel quick <service> |
Create a quick tunnel to a local service |
pyflared tunnel mapped <pairs...> |
Create DNS-mapped tunnel(s) |
pyflared tunnel cleanup |
Remove orphan tunnels and DNS records |
| Option | Description |
|---|---|
--keep-orphans, -k |
Preserve orphan tunnels (prevents default removal) |
--tunnel-name, -n |
Specify a custom tunnel name (default: hostname_YYYY-MM-DD_...) |
--verbose, -v |
Show detailed cloudflared logs |
| Variable | Description |
|---|---|
CLOUDFLARE_API_TOKEN |
Your Cloudflare API token for tunnel management |
For DNS-mapped tunnels, your API token needs the following permissions:
- Account > Cloudflare Tunnel > Edit
- Zone > DNS > Edit
- Zone > Zone > Read
If you see an Error 525 page ("SSL handshake failed") immediately after creating a tunnel, don't worry—this is a temporary issue. Cloudflare's edge network may take a few moments to fully propagate the tunnel configuration.
What to do: Simply wait 1-2 minutes and refresh the page. The error will resolve automatically once the tunnel is fully established.
- Python 3.12+
- Hatch
git clone https://github.com/AzmainMahatab/pyflared.git
cd pyflared
hatch env createhatch testhatch run types:checkhatch buildPyflared is distributed under the terms of the MIT license.
- cloudflared — The official Cloudflare Tunnel client
- Typer — CLI framework
Made with ❤️ by Azmain Mahatab