Example external transform for Malcolm demonstrating the entry point discovery mechanism.
This package is independent from malcolm itself — it has its own pyproject.toml and declares a malcolm.transforms entry point that Malcolm discovers at startup whenever this package is installed in the same Python environment. Nothing in the core proxy imports from this package.
header_logger is a pass-through transform: it logs structural information about each request and response (body key set, body size, model, path) without modifying anything. It exists as a template and as a live test of the entry point discovery mechanism — not to do anything useful in production.
Into the same Python environment where malcolm is installed:
# Directly from GitHub
uv pip install git+https://github.com/malcolm-proxy/malcolm-transform-example
# Or clone and install in editable mode
git clone https://github.com/malcolm-proxy/malcolm-transform-example
cd malcolm-transform-example
uv pip install -e .After installation, confirm the entry point is visible:
python -c "from importlib.metadata import entry_points; print([ep.name for ep in entry_points(group='malcolm.transforms')])"You should see ['header_logger'] (plus any other external transforms you have installed).
Add it to your malcolm.yaml:
transforms:
- header_loggerOr with custom configuration:
transforms:
- header_logger:
prefix: "[my-proxy]"
logger_name: "my.custom.logger"When you start malcolm, the startup log will show the transform in the active pipeline:
malcolm.transforms INFO transform pipeline: ['header_logger']
And each request will produce log lines like:
malcolm_transform_example INFO [header_logger] request keys=['messages', 'model'] size=234
malcolm_transform_example INFO [header_logger] response model=gpt-4o size=1012
| Key | Default | Description |
|---|---|---|
prefix |
[header_logger] |
String prepended to every log line produced by this transform. |
logger_name |
malcolm_transform_example |
Python logger name the transform writes to. Useful if you want to route its output somewhere specific. |
Use this repo as a template:
- Fork it or copy its contents to a new repository.
- Rename the package: update
nameinpyproject.toml, renamesrc/malcolm_transform_example/to your package name, and update the test imports. - Update the entry point in
pyproject.tomlto point at your new package'screatefactory:[project.entry-points."malcolm.transforms"] your_transform_name = "your_package:create"
- Implement the four protocol methods on your transform class:
transform_request,transform_response,transform_stream_line,rewrite_path. - Implement
create(config: dict)as the factory that Malcolm will call at pipeline assembly time. RaiseValueErrorwith a clear message if required configuration is missing. - Install it into the same venv as
malcolm— the new transform becomes available inmalcolm.yamlautomatically.
See the transforms README in the Malcolm repo for the full protocol contract and precedence rules.
From the repo root:
uv sync
uv run pytestThe tests don't require malcolm to be installed — they verify the transform's behaviour in isolation.