Caddy web server with Tailscale plugin, packaged for pip installation
Project description
caddytail
Caddy web server with the Tailscale plugin, packaged for pip installation. Includes a Python API for easy integration with Flask and FastAPI applications.
Installation
# Installation
pip install caddytail
Python API
caddytail provides a CaddyTail class that wraps your Flask or FastAPI application with a Caddy reverse proxy that handles Tailscale authentication automatically.
Flask Example
from flask import Flask, g
from caddytail import CaddyTail, flask_user_required
app = Flask(__name__)
caddy = CaddyTail(
app,
hostname="myapp", # Your Tailscale hostname
tailnet="your-tailnet", # Your tailnet name (without .ts.net)
static_paths={
"/static/*": "./static",
},
)
@app.get("/")
def index():
user = caddy.get_user()
if not user:
return "Not authenticated", 401
return f"Hello, {user['name']}!"
@app.get("/protected")
@flask_user_required(caddy)
def protected():
# User is automatically available in g.tailscale_user
return f"Hello, {g.tailscale_user['name']}!"
if __name__ == "__main__":
caddy.run() # Starts both Caddy and Flask
FastAPI Example
from fastapi import FastAPI, Request, Depends
from caddytail import CaddyTail, fastapi_user_dependency
app = FastAPI()
caddy = CaddyTail(
app,
hostname="myapp",
tailnet="your-tailnet",
static_paths={
"/static/*": "./static",
},
)
# Create a dependency for protected routes
get_user = fastapi_user_dependency(caddy)
@app.get("/")
async def index(request: Request):
user = caddy.get_user(request)
if not user:
return {"error": "Not authenticated"}
return {"message": f"Hello, {user['name']}!"}
@app.get("/protected")
async def protected(user: dict = Depends(get_user)):
# Automatically returns 401 if not authenticated
return {"message": f"Hello, {user['name']}!"}
if __name__ == "__main__":
caddy.run() # Starts both Caddy and FastAPI
CaddyTail Options
| Parameter | Default | Description |
|---|---|---|
app |
(required) | Flask or FastAPI application instance |
hostname |
(required) | Tailscale hostname (e.g., "myapp" -> myapp.tailnet.ts.net) |
tailnet |
(required) | Tailscale tailnet name (without .ts.net suffix) |
caddy_path |
bundled binary | Path to caddy binary |
app_port |
10800 | Port for the Python app to listen on |
caddy_http_port |
10102 | Port for Caddy's HTTP listener |
caddy_admin_port |
2019 | Port for Caddy's admin API |
static_paths |
None | Dict mapping URL patterns to local paths |
state_dir |
"./tailscale-state" | Directory for Tailscale state |
debug |
False | Enable Caddy debug mode |
User Information
The get_user() method returns a dict with Tailscale user information:
{
"name": "John Doe", # Display name
"login": "john@example.com", # Login/email
"profile_pic": "https://..." # Profile picture URL
}
Static File Serving
Caddy can serve static files directly, bypassing your Python application for better performance:
caddy = CaddyTail(
app,
hostname="myapp",
tailnet="your-tailnet",
static_paths={
"/static/*": "./static",
"/assets/*": "./public/assets",
"/uploads/*": "/var/www/uploads",
},
)
# Add paths dynamically
caddy.add_static_path("/media/*", "./media")
# Remove paths
caddy.remove_static_path("/uploads/*")
Running in Background
For advanced use cases, you can start Caddy and your app in background threads:
caddy_proc, app_thread = caddy.run_async()
# Do other things...
# When done
caddy.stop_caddy()
CLI Usage
Once installed, the caddytail command is also available on your PATH:
# Show version
caddytail version
# List modules (should include tailscale)
caddytail list-modules
# Run with a Caddyfile
caddytail run --config /path/to/Caddyfile
# Start in the background
caddytail start
# Stop the background server
caddytail stop
Tailscale Integration
This build of Caddy includes the Tailscale plugin, which allows you to:
- Serve sites directly on your Tailscale network
- Use Tailscale for automatic HTTPS certificates
- Authenticate users via Tailscale identity
Manual Caddyfile Example
{
tailscale
}
myapp.your-tailnet.ts.net {
tailscale_auth
reverse_proxy localhost:8000
}
See the caddy-tailscale documentation for more details.
Supported Platforms
Pre-built wheels are available for:
| Platform | Architecture |
|---|---|
| Linux (glibc) | x86_64, aarch64 |
| macOS | x86_64 (Intel), arm64 (Apple Silicon) |
| Windows | x86_64 |
Building from Source
If you need to build for a platform not listed above:
# Clone the repository
git clone https://github.com/yourusername/caddytail
cd caddytail
# Install Go and xcaddy
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
# Build caddy with the tailscale plugin
xcaddy build --with github.com/tailscale/caddy-tailscale --output src/caddytail/bin/caddy
# Build the wheel
pip install build
python -m build --wheel
License
This project packages Caddy (Apache 2.0 License) with the Tailscale plugin (BSD 3-Clause License).
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file caddytail-0.2.0.tar.gz.
File metadata
- Download URL: caddytail-0.2.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49657c3b5d1f3ac9092e616cf0dbb60963b52846f3e7bf1418a4a41571543d2e
|
|
| MD5 |
d8d698c5c153269bd8cf3af73a51ee23
|
|
| BLAKE2b-256 |
43ee19c560b2e0997610a74444882c7c2aa64e7b71ac2510da867eff4c2e4067
|
Provenance
The following attestation bundles were made for caddytail-0.2.0.tar.gz:
Publisher:
build.yml on jpc/caddytail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
caddytail-0.2.0.tar.gz -
Subject digest:
49657c3b5d1f3ac9092e616cf0dbb60963b52846f3e7bf1418a4a41571543d2e - Sigstore transparency entry: 828949452
- Sigstore integration time:
-
Permalink:
jpc/caddytail@e59fcae3b375e7ebc38bb6fefe3e95c088ace39d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jpc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@e59fcae3b375e7ebc38bb6fefe3e95c088ace39d -
Trigger Event:
push
-
Statement type:
File details
Details for the file caddytail-0.2.0-py3-none-win_amd64.whl.
File metadata
- Download URL: caddytail-0.2.0-py3-none-win_amd64.whl
- Upload date:
- Size: 21.4 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0d5922e5a2d6784c52c3767931afee28a80c0e59bb96d70a3b1cd3c90a60096
|
|
| MD5 |
5ff7a30ab9c43b4061ab8131db9c7b0b
|
|
| BLAKE2b-256 |
b5037eb19810e1cdf49594527158490356c5bd1ce1b4256eaae638a3e5ba73a1
|
Provenance
The following attestation bundles were made for caddytail-0.2.0-py3-none-win_amd64.whl:
Publisher:
build.yml on jpc/caddytail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
caddytail-0.2.0-py3-none-win_amd64.whl -
Subject digest:
a0d5922e5a2d6784c52c3767931afee28a80c0e59bb96d70a3b1cd3c90a60096 - Sigstore transparency entry: 828949464
- Sigstore integration time:
-
Permalink:
jpc/caddytail@e59fcae3b375e7ebc38bb6fefe3e95c088ace39d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jpc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@e59fcae3b375e7ebc38bb6fefe3e95c088ace39d -
Trigger Event:
push
-
Statement type:
File details
Details for the file caddytail-0.2.0-py3-none-manylinux2014_x86_64.whl.
File metadata
- Download URL: caddytail-0.2.0-py3-none-manylinux2014_x86_64.whl
- Upload date:
- Size: 21.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9655a642023bb38e2937641753c41abd5deee5a3ec0f9b3282c8eccc48d33442
|
|
| MD5 |
bcb3eddec5ab6c99b1c6ff66f4023d8c
|
|
| BLAKE2b-256 |
2a30b961f1294cb5266968898d422f51a80cd640744f5ef51630878bbd79ae40
|
Provenance
The following attestation bundles were made for caddytail-0.2.0-py3-none-manylinux2014_x86_64.whl:
Publisher:
build.yml on jpc/caddytail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
caddytail-0.2.0-py3-none-manylinux2014_x86_64.whl -
Subject digest:
9655a642023bb38e2937641753c41abd5deee5a3ec0f9b3282c8eccc48d33442 - Sigstore transparency entry: 828949465
- Sigstore integration time:
-
Permalink:
jpc/caddytail@e59fcae3b375e7ebc38bb6fefe3e95c088ace39d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jpc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@e59fcae3b375e7ebc38bb6fefe3e95c088ace39d -
Trigger Event:
push
-
Statement type:
File details
Details for the file caddytail-0.2.0-py3-none-manylinux2014_aarch64.whl.
File metadata
- Download URL: caddytail-0.2.0-py3-none-manylinux2014_aarch64.whl
- Upload date:
- Size: 19.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
860dc733a261f57429ccc1ae9bd6391b72684602b740677f7f389470e4c1c348
|
|
| MD5 |
48b315bb8cab09e71af3abdc43f15196
|
|
| BLAKE2b-256 |
db4c4f9ed9c7b1d6e9f64680bc985883685739445a54bb16f76fafa682dc5f98
|
Provenance
The following attestation bundles were made for caddytail-0.2.0-py3-none-manylinux2014_aarch64.whl:
Publisher:
build.yml on jpc/caddytail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
caddytail-0.2.0-py3-none-manylinux2014_aarch64.whl -
Subject digest:
860dc733a261f57429ccc1ae9bd6391b72684602b740677f7f389470e4c1c348 - Sigstore transparency entry: 828949458
- Sigstore integration time:
-
Permalink:
jpc/caddytail@e59fcae3b375e7ebc38bb6fefe3e95c088ace39d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jpc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@e59fcae3b375e7ebc38bb6fefe3e95c088ace39d -
Trigger Event:
push
-
Statement type:
File details
Details for the file caddytail-0.2.0-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: caddytail-0.2.0-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 19.9 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
465e37410d4a0b89906c76602a6a0ac35c3f3542a7ed04f9a98ae5ea261467a2
|
|
| MD5 |
b207d0b8085f06463a2801f73c6ffd15
|
|
| BLAKE2b-256 |
7845bcffe33dfa2e9bd6c7a223f9d9f70e58e3f6191a9a2909e395c4baf29681
|
Provenance
The following attestation bundles were made for caddytail-0.2.0-py3-none-macosx_11_0_arm64.whl:
Publisher:
build.yml on jpc/caddytail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
caddytail-0.2.0-py3-none-macosx_11_0_arm64.whl -
Subject digest:
465e37410d4a0b89906c76602a6a0ac35c3f3542a7ed04f9a98ae5ea261467a2 - Sigstore transparency entry: 828949470
- Sigstore integration time:
-
Permalink:
jpc/caddytail@e59fcae3b375e7ebc38bb6fefe3e95c088ace39d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jpc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@e59fcae3b375e7ebc38bb6fefe3e95c088ace39d -
Trigger Event:
push
-
Statement type:
File details
Details for the file caddytail-0.2.0-py3-none-macosx_10_15_x86_64.whl.
File metadata
- Download URL: caddytail-0.2.0-py3-none-macosx_10_15_x86_64.whl
- Upload date:
- Size: 21.4 MB
- Tags: Python 3, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
365d057236018252452f9dea3059a6a362f46e8009883d7a242e8a7208e15599
|
|
| MD5 |
294fa6317b7ac2770f0941bcd29db55a
|
|
| BLAKE2b-256 |
9edd8e6560ca96328fd53acdd29814abcf5605735b3ebbee02792753510e5928
|
Provenance
The following attestation bundles were made for caddytail-0.2.0-py3-none-macosx_10_15_x86_64.whl:
Publisher:
build.yml on jpc/caddytail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
caddytail-0.2.0-py3-none-macosx_10_15_x86_64.whl -
Subject digest:
365d057236018252452f9dea3059a6a362f46e8009883d7a242e8a7208e15599 - Sigstore transparency entry: 828949466
- Sigstore integration time:
-
Permalink:
jpc/caddytail@e59fcae3b375e7ebc38bb6fefe3e95c088ace39d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jpc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@e59fcae3b375e7ebc38bb6fefe3e95c088ace39d -
Trigger Event:
push
-
Statement type: