Flask-Cloudflared

0.0.15 · active · verified Fri Apr 17

Flask-Cloudflared (current version 0.0.15) is a Python library designed to effortlessly start a TryCloudflare Tunnel directly from your Flask application. It simplifies exposing your local development server to the internet via Cloudflare Tunnels, making it ideal for webhook testing, demos, or sharing progress without complex port forwarding. The library is actively maintained, with new patch versions released as needed.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a basic Flask application and start a Cloudflare Tunnel to expose it. The `run_cloudflared_tunnel` function handles the tunnel creation and outputs the public URL. Ensure Flask is running on the port specified for the tunnel.

import os
from flask import Flask
from flask_cloudflared import run_cloudflared_tunnel

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    # Cloudflared will attempt to expose the specified port (default Flask port is 5000)
    # The tunnel runs in a separate process, allowing app.run() to proceed.
    tunnel_url = run_cloudflared_tunnel(port=5000)
    if tunnel_url:
        print(f"Cloudflare Tunnel is active at: {tunnel_url}")
    else:
        print("Failed to start Cloudflare Tunnel.")
    
    # Run the Flask application on the same port
    app.run(port=5000)

view raw JSON →