A Python client for the Caddy API
Project description
Caddy API Client
A Python client for managing Caddy server configurations through its API.
Installation
Production Installation (Recommended)
For production workloads, it's recommended to install the package from PyPI:
pip install caddy-api-client
Development Installation
For development or if you need to modify the client:
- Clone the repository:
git clone https://github.com/migetapp/caddy-api-client.git
cd caddy-api-client
- Install the package in development mode:
pip install -e .
Usage
from caddy_api_client import CaddyAPIClient
# Initialize the client
client = CaddyAPIClient("http://localhost:2019") # Default Caddy admin endpoint
# Add a domain with automatic TLS (Let's Encrypt/ZeroSSL) and www redirect
client.add_domain_with_auto_tls(
domain="example.org",
target="nginx",
target_port=80,
redirect_mode="domain_to_www", # Redirects example.org to www.example.org
enable_security_headers=True, # Adds security headers
enable_hsts=True # Enables HSTS
)
# Add a domain with www to non-www redirect
client.add_domain_with_auto_tls(
domain="www.example.net",
target="192.168.10.101",
target_port=80,
redirect_mode="www_to_domain" # Redirects www.example.net to example.net
)
# Add a domain with custom TLS certificates using PEM data
with open('cert.pem', 'r') as f:
certificate = f.read()
with open('key.pem', 'r') as f:
private_key = f.read()
client.add_domain_with_tls(
domain="example.net",
target="192.168.10.101",
target_port=80,
certificate=certificate,
private_key=private_key
)
# Get domain configuration
config = client.get_domain_config("example.com")
print(config)
# Update domain configuration
client.update_domain(
domain="example.com",
target="172.16.0.2",
target_port=8080,
redirect_mode="domain_to_www" # Add or update redirect configuration
)
# Delete domain
client.delete_domain("example.com") # Removes domain and its redirect configuration
## Features
- Add domains with TLS certificates using PEM data
- Add domains with automatic TLS (Let's Encrypt/ZeroSSL)
- Configure domain redirects:
- www to non-www (`www_to_domain`)
- non-www to www (`domain_to_www`)
- Security features:
- Security headers (Server, X-Frame-Options, etc.)
- HTTP Strict Transport Security (HSTS)
- HTTP to HTTPS redirect
- Path-based security rules
- Delete domain configurations (preserves other domain configurations)
- Get domain configurations
- Update domain configurations
- Support for HTTP/2 and HTTP/3
## Error Handling
The client includes comprehensive error handling for API requests. All methods will raise exceptions with descriptive messages if something goes wrong during the API calls.
## License
This project is licensed under the Apache License, Version 2.0 - see the [LICENSE](LICENSE) file for details.
Copyright 2025 Krzysztof Taraszka and The Miget Authors.
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
caddy_api_client-0.2.3.tar.gz
(16.3 kB
view details)
Built Distribution
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 caddy_api_client-0.2.3.tar.gz.
File metadata
- Download URL: caddy_api_client-0.2.3.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68a42424015506533a0b50137010aa3ae1d78d584124b917429b07e68107bed5
|
|
| MD5 |
dce5d08c15c9bbf716f5d282a82007d7
|
|
| BLAKE2b-256 |
17c811336e28c1d3986490209194a2c46ace8b65891b359918b475c75b808194
|
File details
Details for the file caddy_api_client-0.2.3-py3-none-any.whl.
File metadata
- Download URL: caddy_api_client-0.2.3-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e767ad23e74eb5f52178dc5572e5e13916cfb31f0de2ea24a518f91eab35843
|
|
| MD5 |
7188c4fb78e6b4ae47a53b41b5c928d8
|
|
| BLAKE2b-256 |
7c9308ff98d50e340e6ce160c69991d9f1b8f2f608b9e2dcfee58148d2b55283
|