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 Cloudflared Version License


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.

✨ 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
  • 📦 Batteries Included — Bundles the cloudflared binary, 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

📦 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.

Cleanup Orphan Tunnels

Remove stale tunnels and DNS records created by pyflared:

pyflared tunnel cleanup

📖 Usage

pyflared --help

Commands

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

Options for tunnel mapped

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

🔧 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
  • Zone > Zone > Read

🛠️ 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 MIT 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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

pyflared-0.0.1b3-py3-none-macosx_10_9_x86_64.whl (21.1 MB view details)

Uploaded Python 3macOS 10.9+ x86-64

File details

Details for the file pyflared-0.0.1b3-py3-none-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyflared-0.0.1b3-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c20d0845918baaeddb3aff328303009f6c78da81cc23a1c0d36237a97af30ff6
MD5 2a25a86efe61f5e6034d23a899198728
BLAKE2b-256 0da00c99d76c0133fb35914568d1398ccaec85ce0bd204e3ca54925f9ad7f6ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyflared-0.0.1b3-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