Skip to main content

A Python CLI tool for effortless Cloudflare Tunnel management

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyflared-0.1.0.tar.gz (53.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyflared-0.1.0-py3-none-win_amd64.whl (18.2 MB view details)

Uploaded Python 3Windows x86-64

pyflared-0.1.0-py3-none-musllinux_1_1_x86_64.whl (19.0 MB view details)

Uploaded Python 3musllinux: musl 1.1+ x86-64

pyflared-0.1.0-py3-none-musllinux_1_1_aarch64.whl (17.5 MB view details)

Uploaded Python 3musllinux: musl 1.1+ ARM64

pyflared-0.1.0-py3-none-manylinux_2_17_x86_64.whl (19.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

pyflared-0.1.0-py3-none-manylinux_2_17_aarch64.whl (17.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

pyflared-0.1.0-py3-none-macosx_11_0_arm64.whl (19.0 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

pyflared-0.1.0-py3-none-macosx_10_9_x86_64.whl (20.9 MB view details)

Uploaded Python 3macOS 10.9+ x86-64

File details

Details for the file pyflared-0.1.0.tar.gz.

File metadata

  • Download URL: pyflared-0.1.0.tar.gz
  • Upload date:
  • Size: 53.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyflared-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aa9c8ec6e82d7b1069294fba152067bfc3ff7dc55209ac082fb00de5fd47c456
MD5 6a1359bfde273b0b713166d5b56c8a1d
BLAKE2b-256 a5ec38df586d7f3ac0766a5ae579eadf0498e2cf55a8dbdc91a88b8cf8562b81

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyflared-0.1.0.tar.gz:

Publisher: cd.yml on AzmainMahatab/pyflared

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyflared-0.1.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: pyflared-0.1.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 18.2 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyflared-0.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 7766f35f3655f436cca28270374a982ac6081c855c981c7e22b380a32c743eff
MD5 7ec0efcf42f6ac81d89289135431749b
BLAKE2b-256 778f3ef02033480a3099e71097b4245a6c5065a782976406d1a4d49e4d717452

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyflared-0.1.0-py3-none-win_amd64.whl:

Publisher: cd.yml on AzmainMahatab/pyflared

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyflared-0.1.0-py3-none-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for pyflared-0.1.0-py3-none-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 41a8dea262ff062c8894efd6efd2fc7dace36deb7c10041e40568c82f76b169f
MD5 54f7ccbd6ccb4d55b2eca8cbb7fe027d
BLAKE2b-256 4780c28301ad53a919853da45a1ddf43f888f431cd4f24c632807951b1d65b2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyflared-0.1.0-py3-none-musllinux_1_1_x86_64.whl:

Publisher: cd.yml on AzmainMahatab/pyflared

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyflared-0.1.0-py3-none-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for pyflared-0.1.0-py3-none-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 347a86fcd58bcd524bff008edbe4ae7fb64afe5c5941c2b0c969074ad284f649
MD5 2c1a3b3d1604c486377c2b69d17f5f59
BLAKE2b-256 5ce6490790941123b8527092a7d488023b8a479fa25ec8933241ccabb1810222

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyflared-0.1.0-py3-none-musllinux_1_1_aarch64.whl:

Publisher: cd.yml on AzmainMahatab/pyflared

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyflared-0.1.0-py3-none-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for pyflared-0.1.0-py3-none-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 7c13bc24492fdb25e44425cc0cbe483fe92c55d2d0274a14054377292e880672
MD5 7e282513ed2e63fcf7adbac2a2b8933f
BLAKE2b-256 0271b71797dfa758db11d1b57a85d55dcfc0734f7d0b4350ec46d28d542f9998

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyflared-0.1.0-py3-none-manylinux_2_17_x86_64.whl:

Publisher: cd.yml on AzmainMahatab/pyflared

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyflared-0.1.0-py3-none-manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for pyflared-0.1.0-py3-none-manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 d238c580dfd2a57b4b5e197364d4f34fc1ad67d1f9ac78891547c45150eb31fb
MD5 567a8499e46e4bd3f568218c1a7df6fb
BLAKE2b-256 b9b6902dbc974a3a21c12c8504a4d52a125f61eb9fb421bbb68a3b74ebcf7d81

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyflared-0.1.0-py3-none-manylinux_2_17_aarch64.whl:

Publisher: cd.yml on AzmainMahatab/pyflared

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyflared-0.1.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyflared-0.1.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 51de0c3eaa635706f3995df305d1ffa12cb32941d81d88c6e523a3a7b4eaaa23
MD5 109e0cb11757e9791eea1eef67d26759
BLAKE2b-256 aef0ac2d595a2cc4842e038fcf1cbe2da805d91c90d1a94769be0e2c3db6645d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyflared-0.1.0-py3-none-macosx_11_0_arm64.whl:

Publisher: cd.yml on AzmainMahatab/pyflared

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyflared-0.1.0-py3-none-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyflared-0.1.0-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5d1ca6c214084ded8ae87d85fe1be7c3fecd91b565e4b4a3e7d07bc9765cf9ab
MD5 513f0d8625e8b081d682770863e34aed
BLAKE2b-256 4bc91e30e0e6bf0093da40a4b4e6a084c35291cb23c45807d1e5e5ea4eb5df00

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyflared-0.1.0-py3-none-macosx_10_9_x86_64.whl:

Publisher: cd.yml on AzmainMahatab/pyflared

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page