caddyconfig
Caddy JSON configuration manipulation for Python, built on Pydantic v2.
Provides typed models, validation, a fluent builder API, and bidirectional serialization to/from Caddy's native JSON format.
Installation
pip install caddyconfig
Requires Python 3.10+.
Quick Start
Fluent Builder API
from caddyconfig.builder import CaddyConfigBuilder
config = (
CaddyConfigBuilder()
.admin(listen="localhost:2019")
.logging(writer="stderr", level="INFO")
.server("main", listen=[":443", ":80"])
.route()
.match(host=["acme.com"])
.handle_static(200, body="Welcome")
.done()
.route()
.match(path=["/api"])
.handle_reverse_proxy("10.0.0.1:8080")
.done()
.done()
.build()
)
print(config.to_json(indent=2))
Direct Model API
from caddyconfig import (
CaddyConfig, Admin, Logging, LogSink, LogEntry,
Apps, HttpApp, Server, Route, MatchCriteria,
StaticResponseHandler, ReverseProxyHandler,
)
config = CaddyConfig(
admin=Admin(listen="localhost:2019"),
logging=Logging(
sink=LogSink(writer="stderr"),
logs={"default": LogEntry(name="default", level="INFO")},
),
apps=Apps(
http=HttpApp(
servers={
"main": Server(
name="main",
listen=[":443", ":80"],
routes=[
Route(
match=[MatchCriteria(host=["acme.com"])],
handle=[StaticResponseHandler(status_code=200, body="Welcome")],
),
Route(
match=[MatchCriteria(path=["/api"])],
handle=[ReverseProxyHandler(upstreams=["10.0.0.1:8080"])],
),
],
)
}
),
)
)
JSON Roundtrip
json_str = config.to_json()
config2 = CaddyConfig.from_json(json_str)
assert config2.to_dict() == config.to_dict()
Route Lookup and Mutation
server = config.apps.http.get_server("main")
# Find a route by matcher criteria (partial match supported)
route = server.find_route(MatchCriteria(path=["/api"]))
# Upsert: replace if exists, insert otherwise
server.upsert_route(MatchCriteria(path=["/api"]), new_route)
# Remove a route
server.remove_route(MatchCriteria(path=["/api"]))
# Search recursively through subroutes
route = server.find_route(MatchCriteria(path=["/api"]), recursive=True)
Supported Handlers
| Handler | Model | Builder Method |
|---|---|---|
static_response |
StaticResponseHandler |
.handle_static(status, body=...) |
reverse_proxy |
ReverseProxyHandler |
.handle_reverse_proxy("host:port") |
file_server |
FileServerHandler |
.handle_file_server(root=...) |
authentication |
AuthenticationHandler |
.handle_auth_basic(("u", "pw")) |
subroute |
SubrouteHandler |
.handle_subroute() |
| unknown types | RawHandler |
.handle(raw_handler) |
Development
# Install dependencies
uv sync
# Run tests
uv run pytest
# Run a single test file
uv run pytest tests/test_builder.py
# With coverage
uv run pytest --cov=caddyconfig
License
Apache License 2.0
Metadata
Release files for caddyconfig 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| caddyconfig-0.1.9.tar.gz | 39.2 kB | Without provenance | Details for caddyconfig-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| caddyconfig-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for caddyconfig-0.1.9-py3-none-any.whl |
Total release size: 70.1 kB
Release files / caddyconfig-0.1.9.tar.gz
| Download URL | caddyconfig-0.1.9.tar.gz |
|---|---|
| Size | 39.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7440a99d40104f5fef569f097145883f9fe1523ccc3fb259136a74a0e0fe032a
|
|
BLAKE2b-256 checksum How to use checksums |
6abe1b85a6742336b8514496b9820edb3bc6e2a591f18f128dac8088bcc84c98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / caddyconfig-0.1.9-py3-none-any.whl
| Download URL | caddyconfig-0.1.9-py3-none-any.whl |
|---|---|
| Size | 30.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
22dbb28eae2706eb53946a3199dbdc96d2329181384fcf62505d20c361753181
|
|
BLAKE2b-256 checksum How to use checksums |
fa67493560fa08c9bd0513ff01d2708f3ef86d194b99ad31580598bc062aeb93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for caddyconfig 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.