Skip to main content

Pyflared

A Python CLI tool for effortless Cloudflare Tunnel management

PyPI - Version PyPI - Python Version Pepy Downloads Cloudflared Version License


Pyflared is a CLI tool 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. It also works as a Python library!

✨ Features

  • 🚀 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
  • 🔑 SSH over Cloudflare — Expose and connect to SSH servers through Cloudflare Tunnels
  • 🗝️ Token Management — Store and manage multiple Cloudflare API tokens locally
  • 📦 Batteries Included — Bundles the cloudflared binary, no separate installation required
  • 🐳 Docker Ready — Run as a container with minimal setup

📦 Installation

Using uv (Recommended)

uv tool install pyflared

Using pip

pip install pyflared

Using Docker

docker pull ghcr.io/azmainmahatab/pyflared:latest
docker run --rm ghcr.io/azmainmahatab/pyflared --help

🚀 Quick Start

Create a Quick Tunnel

Expose a local service instantly with a temporary trycloudflare.com URL:

pyflared tunnel quick 8000

This creates a public URL (e.g., https://random-name.trycloudflare.com) pointing to localhost:8000.

Create a DNS-Mapped Tunnel

Create a persistent tunnel with your own domain:

pyflared tunnel mapped api.example.com=localhost:8000 web.example.com=localhost:3000

This will:

  1. Create a new Cloudflare Tunnel
  2. Configure DNS records for your domains
  3. Route traffic to your local services

Note: Requires a Cloudflare API token with tunnel and DNS permissions. Set via CLOUDFLARE_API_TOKEN environment variable or enter when prompted.

Clean Up Orphan Tunnels

Remove stale tunnels and DNS records left behind by pyflared:

pyflared tunnel cleanup

Expose SSH via Cloudflare

Serve your local SSH daemon through a Cloudflare Tunnel:

pyflared ssh serve ssh.example.com

Connect to it from another machine:

pyflared ssh connect user@ssh.example.com

📖 Usage

pyflared --help

pyflared version

Show the bundled cloudflared version.

pyflared tunnel quick <service>

Create a quick tunnel to a local service with a temporary trycloudflare.com URL.

Option Description
--verbose -v Show detailed cloudflared logs

pyflared tunnel mapped <DOMAIN=SERVICE..>

Create DNS-mapped tunnel(s). See Mapping Format for all supported DOMAIN=SERVICE syntaxes.

Option Description
--tunnel-name -n Custom tunnel name (default: auto-generated). See Tunnel Naming Behavior
--force -f Take over DNS from other tunnels even if named
--verbose -v Show detailed cloudflared logs

pyflared tunnel cleanup

Remove orphan tunnels and DNS records.

Option Description
--all -a Delete ALL tunnels and DNS records, not just orphans
--force -f Bypass confirmation prompt when deleting all resources
--verbose -v Show detailed cloudflared logs

pyflared ssh serve <domain>

Expose local SSH server through a Cloudflare Tunnel.

Option Description
--tunnel-name -n Custom tunnel name. See Tunnel Naming Behavior
--force -f Take over DNS from other tunnels even if named
--verbose -v Show detailed cloudflared logs

pyflared ssh add <hostname>

Add a Cloudflare SSH host entry to your ~/.ssh/config.

pyflared ssh remove <alias>

Remove a previously added SSH config entry.

pyflared ssh connect <user@host> [args]

Connect to a remote host using SSH through Cloudflare. Extra SSH arguments are passed through.

pyflared ssh proxy <hostname>

ProxyCommand helper for use in ~/.ssh/config:

Host myhost
    ProxyCommand pyflared ssh proxy %h

pyflared token list

List all stored Cloudflare API tokens.

pyflared token add <name>

Add a new API token (prompts securely for the token value).

pyflared token remove <name>

Remove a stored token by its friendly name.

pyflared token nuke

Remove all stored tokens.

🏷️ Tunnel Naming Behavior

The --tunnel-name / -n flag on tunnel mapped and ssh serve controls the tunnel lifecycle:

Without --tunnel-name (default) With --tunnel-name
Lifecycle Ephemeral — tunnel and DNS records are automatically deleted on shutdown (Ctrl+C) Persistent — tunnel and DNS records are preserved across runs
Next run A brand-new tunnel is created every time Reuses the existing tunnel if the same name exists
DNS protection None — DNS records are disposable Named tunnels protect their DNS records from being claimed by other tunnel setups
Force override N/A Use --force / -f to override DNS owned by another named tunnel

Tip: Use unnamed tunnels for development and quick testing. Use named tunnels for long-lived services where you want DNS stability and protection across restarts.

📐 Mapping Format

The DOMAIN=SERVICE pairs used in tunnel mapped support a variety of formats.

Basic

# Port only → inferred as http://localhost:<port>
pyflared tunnel mapped app.com=8000

# Host and port
pyflared tunnel mapped app.com=localhost:3000

# Explicit scheme
pyflared tunnel mapped app.com=http://backend:9000
pyflared tunnel mapped secure.com=https://localhost:443

Path Routing

# Route a subdomain path to a specific backend path
pyflared tunnel mapped app.com/api=localhost:8000

# Port with backend path
pyflared tunnel mapped api.com=8000/v1/api

TCP & SSH

Well-known ports are automatically mapped to the correct protocol:

# SSH (port 22) → ssh://
pyflared tunnel mapped ssh.example.com=22

# PostgreSQL (5432), Redis (6379), MongoDB (27017) → tcp://
pyflared tunnel mapped db.com=5432
pyflared tunnel mapped redis.com=6379

Unix Sockets

pyflared tunnel mapped sock.com=/var/run/app.sock

TLS Verification

Syntax Behavior
https://localhost:443 Auto-disables TLS verification (local backend)
https://backend:443?verify_tls=false Explicitly disable TLS verification
https://localhost?verify_tls=true Force TLS verification even for localhost
https://backend:443?verify_tls=api.internal.com Verify against a custom server name

Special Services

# Cloudflare built-in test page
pyflared tunnel mapped test.com=hello_world

# HTTP status code response
pyflared tunnel mapped app.com=http_status:404

# Bastion mode (SSH browser rendering)
pyflared tunnel mapped bastion.com=bastion

🔧 Configuration

Environment Variables

Variable Description
CLOUDFLARE_API_TOKEN Your Cloudflare API token for tunnel management

API Token Permissions

For DNS-mapped tunnels, your API token needs the following permissions:

  • Account > Cloudflare Tunnel > Edit
  • Zone > DNS > Edit

❓ Troubleshooting

SSL Handshake Failed (Error 525)

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.

🛠️ Development

Prerequisites

Setup

git clone https://github.com/AzmainMahatab/pyflared.git
cd pyflared
hatch env create

Running Tests

hatch test

Type Checking

hatch run types:check

Building

hatch build

📄 License

Pyflared is distributed under the terms of the MPL-2.0 license.

🙏 Acknowledgments


Made with ❤️ by Azmain Mahatab

Metadata

Release files for pyflared 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyflared 0.1.0
File Size Uploaded
pyflared-0.1.0.tar.gz 53.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pyflared 0.1.0
File
pyflared-0.1.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
pyflared-0.1.0-py3-none-musllinux_1_1_x86_64.whl Python 3 none Linux musl 1.1+ x86-64 Details
pyflared-0.1.0-py3-none-musllinux_1_1_aarch64.whl Python 3 none Linux musl 1.1+ ARM64 Details
pyflared-0.1.0-py3-none-manylinux_2_17_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details
pyflared-0.1.0-py3-none-manylinux_2_17_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details
pyflared-0.1.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details
pyflared-0.1.0-py3-none-macosx_10_9_x86_64.whl Python 3 none macOS 10.9+ x86-64 Details

Total release size: 131.2 MB

Release files / pyflared-0.1.0.tar.gz

Download URL pyflared-0.1.0.tar.gz
Size 53.3 kB
Tags Source
SHA-256 checksum
How to use checksums
aa9c8ec6e82d7b1069294fba152067bfc3ff7dc55209ac082fb00de5fd47c456
BLAKE2b-256 checksum
How to use checksums
a5ec38df586d7f3ac0766a5ae579eadf0498e2cf55a8dbdc91a88b8cf8562b81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log

Release files / pyflared-0.1.0-py3-none-win_amd64.whl

Download URL pyflared-0.1.0-py3-none-win_amd64.whl
Size 18.2 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
7766f35f3655f436cca28270374a982ac6081c855c981c7e22b380a32c743eff
BLAKE2b-256 checksum
How to use checksums
778f3ef02033480a3099e71097b4245a6c5065a782976406d1a4d49e4d717452
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log

Release files / pyflared-0.1.0-py3-none-musllinux_1_1_x86_64.whl

Download URL pyflared-0.1.0-py3-none-musllinux_1_1_x86_64.whl
Size 19.0 MB
Tags Linux musl 1.1+ x86-64 Python 3
SHA-256 checksum
How to use checksums
41a8dea262ff062c8894efd6efd2fc7dace36deb7c10041e40568c82f76b169f
BLAKE2b-256 checksum
How to use checksums
4780c28301ad53a919853da45a1ddf43f888f431cd4f24c632807951b1d65b2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log

Release files / pyflared-0.1.0-py3-none-musllinux_1_1_aarch64.whl

Download URL pyflared-0.1.0-py3-none-musllinux_1_1_aarch64.whl
Size 17.5 MB
Tags Linux musl 1.1+ ARM64 Python 3
SHA-256 checksum
How to use checksums
347a86fcd58bcd524bff008edbe4ae7fb64afe5c5941c2b0c969074ad284f649
BLAKE2b-256 checksum
How to use checksums
5ce6490790941123b8527092a7d488023b8a479fa25ec8933241ccabb1810222
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log

Release files / pyflared-0.1.0-py3-none-manylinux_2_17_x86_64.whl

Download URL pyflared-0.1.0-py3-none-manylinux_2_17_x86_64.whl
Size 19.0 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
7c13bc24492fdb25e44425cc0cbe483fe92c55d2d0274a14054377292e880672
BLAKE2b-256 checksum
How to use checksums
0271b71797dfa758db11d1b57a85d55dcfc0734f7d0b4350ec46d28d542f9998
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log

Release files / pyflared-0.1.0-py3-none-manylinux_2_17_aarch64.whl

Download URL pyflared-0.1.0-py3-none-manylinux_2_17_aarch64.whl
Size 17.5 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
d238c580dfd2a57b4b5e197364d4f34fc1ad67d1f9ac78891547c45150eb31fb
BLAKE2b-256 checksum
How to use checksums
b9b6902dbc974a3a21c12c8504a4d52a125f61eb9fb421bbb68a3b74ebcf7d81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log

Release files / pyflared-0.1.0-py3-none-macosx_11_0_arm64.whl

Download URL pyflared-0.1.0-py3-none-macosx_11_0_arm64.whl
Size 19.0 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
51de0c3eaa635706f3995df305d1ffa12cb32941d81d88c6e523a3a7b4eaaa23
BLAKE2b-256 checksum
How to use checksums
aef0ac2d595a2cc4842e038fcf1cbe2da805d91c90d1a94769be0e2c3db6645d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log

Release files / pyflared-0.1.0-py3-none-macosx_10_9_x86_64.whl

Download URL pyflared-0.1.0-py3-none-macosx_10_9_x86_64.whl
Size 20.9 MB
Tags Python 3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
5d1ca6c214084ded8ae87d85fe1be7c3fecd91b565e4b4a3e7d07bc9765cf9ab
BLAKE2b-256 checksum
How to use checksums
4bc91e30e0e6bf0093da40a4b4e6a084c35291cb23c45807d1e5e5ea4eb5df00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 15, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page