Skip to main content

A Python wrapper for Cloudflare Tunnel (cloudflared)

Project description

pyflared

A Python CLI tool for effortless Cloudflare Tunnel management

PyPI - Version PyPI - Python 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/azmain/pyflared:latest
docker run --rm ghcr.io/azmain/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

Option Description
--verbose, -v Show detailed cloudflared logs
--remove-orphans, -ro Remove orphan tunnels before creating new ones
--tunnel-name Specify a custom tunnel name

🔧 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/Azmain/pyflared.git
cd pyflared
hatch env create

Running Tests

hatch test

Type Checking

hatch run types:check

Building

hatch build

🏗️ Architecture

pyflared/
├── cli.py           # Typer CLI application
├── _commands.py     # Core tunnel command wrappers
├── api_sdk/         # Cloudflare API integration
│   └── tunnel_manager.py  # Tunnel & DNS management
├── binary/          # cloudflared binary handling
│   ├── binary_decorator.py
│   └── process.py   # Async subprocess management
├── log/             # Logging configuration
├── shared/          # Shared types and utilities
└── utils/           # Helper utilities

📄 License

pyflared is distributed under the terms of the MIT license.

🙏 Acknowledgments


Made with ❤️ by Azmain

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.0.1b0.tar.gz (43.4 kB view details)

Uploaded Source

Built Distribution

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

pyflared-0.0.1b0-py3-none-win_amd64.whl (18.8 MB view details)

Uploaded Python 3Windows x86-64

File details

Details for the file pyflared-0.0.1b0.tar.gz.

File metadata

  • Download URL: pyflared-0.0.1b0.tar.gz
  • Upload date:
  • Size: 43.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.2 cpython/3.14.2 HTTPX/0.28.1

File hashes

Hashes for pyflared-0.0.1b0.tar.gz
Algorithm Hash digest
SHA256 0f3fa8ccc098b5eac42eefea2533b6c0d4a8f7211550626ed4a2c411521b899c
MD5 f40ce00d2c43c5d68a6036667b8ff7ca
BLAKE2b-256 3a276fe1f66e50efb318986ea266af862722e0e7ecd67b50ca15e7f97798a83f

See more details on using hashes here.

File details

Details for the file pyflared-0.0.1b0-py3-none-win_amd64.whl.

File metadata

  • Download URL: pyflared-0.0.1b0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 18.8 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.2 cpython/3.14.2 HTTPX/0.28.1

File hashes

Hashes for pyflared-0.0.1b0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 830f52dc266a2741274ee5a3a1ab9558e5701a6ce2bb3e67f277616b57a969c9
MD5 3e640df106e7802c63db176109437503
BLAKE2b-256 75aa763f27a66ddbba53c8f55a420c0b49bd7b6a82953e77ba53d4c8d2e9ea98

See more details on using hashes here.

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