Skip to main content

Context manger for Cloudflared

Project description

with-cloudflared

With-cloudflared provides a context manager to start and stop cloudflared. Cloudflare Tunnel provides you with a secure way to connect your resources to Cloudflare without a publicly routable IP address. This is useful for development and testing, as well as for production use cases. See the Cloudflare Tunnel documentation for more information.

Installation

pip install with-cloudflared

Usage

import uvicorn
from fastapi import FastAPI
from with_cloudflared import cloudflared

app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}

if __name__ == "__main__":
    port = 8000
    with cloudflared(port=port) as cloudflared_address:
        print(f" * Running on {cloudflared_address}")
        uvicorn.run(app, port=port)

This will start cloudflared and then start the FastAPI server. The app will be publicly available at the cloudflared address e.g. something like https://rp-son-configured-army.trycloudflare.com.

The first time you run this it will take a few seconds to download and start cloudflared. Subsequent runs will be much faster.

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

with_cloudflared-0.1.0.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

with_cloudflared-0.1.0-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

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