xRegistry Code Generation CLI
Generate production-ready, type-safe messaging SDKs from xRegistry message catalog definitions. One command gives you compile-ready producer/consumer code with tests, dependency management, and protocol-specific bindings.
Quick Start
1. Install (Docker or pip):
# Docker (recommended - no Python needed)
docker pull ghcr.io/xregistry/codegen/xrcg:latest
# Or via pip
pip install git+https://github.com/xregistry/codegen.git
2. Generate a Kafka producer from a sample definition:
# Using Docker (Linux/macOS)
docker run --rm -v $(pwd):/work ghcr.io/xregistry/codegen/xrcg:latest \
generate --projectname PrinterEvents --language py --style kafkaproducer \
--definitions https://raw.githubusercontent.com/xregistry/codegen/main/samples/message-definitions/inkjet.xreg.json \
--output ./generated
# Using Docker (Windows PowerShell)
docker run --rm -v ${PWD}:/work ghcr.io/xregistry/codegen/xrcg:latest `
generate --projectname PrinterEvents --language py --style kafkaproducer `
--definitions https://raw.githubusercontent.com/xregistry/codegen/main/samples/message-definitions/inkjet.xreg.json `
--output ./generated
# Or with pip install (any platform)
xrcg generate --projectname PrinterEvents --language py --style kafkaproducer \
--definitions https://raw.githubusercontent.com/xregistry/codegen/main/samples/message-definitions/inkjet.xreg.json \
--output ./generated
This produces a complete Python project with:
- Type-safe producer classes for each message type
- Strongly-typed data classes generated from Avro schema
- Integration tests using Testcontainers
- Ready to use:
cd generated && pip install -e . && pytest
3. Or generate for a different platform — same definition, different target:
xrcg generate --projectname ContosoEvents --language cs --style ehproducer \
--definitions ./contoso-erp.xreg.json --output ./generated # C# Event Hubs
xrcg generate --projectname ContosoEvents --language ts --style mqttclient \
--definitions ./contoso-erp.xreg.json --output ./generated # TypeScript MQTT
xrcg generate --projectname ContosoEvents --language py --style kafkaconsumer \
--definitions ./contoso-erp.xreg.json --output ./generated # Python Kafka
What You Get
Unlike snippet generators, this tool produces complete SDK-like projects:
| Feature | What's Generated |
|---|---|
| Type-safe clients | Producer/consumer classes with strongly-typed methods per message |
| Data classes | Schema-derived classes via Avrotize (JSON Schema, Avro, Protobuf) |
| Build files | pom.xml, .csproj, package.json, pyproject.toml with correct dependencies |
| Integration tests | Docker-based tests using Testcontainers for Kafka, MQTT, AMQP brokers |
| Project structure | Language-idiomatic layout ready for IDE import |
Supported Languages: Java 21+, C# (.NET 6+), Python 3.9+, TypeScript/JavaScript, Go 1.21+, Rust (cargo)
Supported Protocols: Apache Kafka, MQTT 5.0, AMQP 1.0, Azure Event Hubs, Azure Service Bus, Azure Event Grid, HTTP/CloudEvents
Generating Code
For complete command documentation, see Command Reference.
The Generate Command
xrcg generate --projectname <name> --language <lang> --style <style> \
--definitions <file-or-url> --output <dir>
| Option | Description |
|---|---|
--projectname |
Project/namespace name for generated code |
--language |
Target language: java, cs, py, ts, asyncapi, openapi |
--style |
Protocol binding: kafkaproducer, ehconsumer, mqttclient, etc. |
--definitions |
Path or URL to xRegistry JSON/YAML definition |
--output |
Output directory (will be created/overwritten) |
--templates |
Custom template directory (optional) |
--template-args |
Extra args as key=value (optional) |
Python URI-template encoding
Python mqttclient, kafkaproducer, and amqpproducer support
--template-args uri_template_encoding=percent. This opt-in applies RFC 6570
simple-expansion percent encoding to scalar {placeholder} values in MQTT
topics, CloudEvents URI-template metadata, Kafka keys, and AMQP URI-template
properties and annotations. Pass original identifiers, not pre-encoded values.
Payload fields are unchanged; CloudEvents timestamps retain their RFC 3339 format.
For example, TEST_SITE_A2/A10 expands to TEST_SITE_A2%2FA10 within one MQTT
topic level. MQTT consumers generated with the same option decode extracted
parameters once. Literal %2F in an identifier expands to %252F and is returned
as %2F, not /.
The default, uri_template_encoding=legacy, retains existing literal
interpolation and consumer extraction. Enable percent mode consistently for
producers and consumers that share a routing contract. Regeneration changes
routing values containing reserved characters, whitespace, or non-ASCII text;
unreserved identifiers keep their existing values. This option covers the
existing simple {placeholder} syntax, not other RFC 6570 operators.
Percent mode preserves the complete AMQP partition-key value rather than truncating it. A broker with a partition-key size limit can reject an oversized key; the generator does not shorten identifiers to fit that limit.
Available Templates
Run xrcg list to see all available language/style combinations:
├── java: Java 21+
│ ├── kafkaproducer, kafkaconsumer # Apache Kafka
│ ├── ehproducer, ehconsumer # Azure Event Hubs
│ ├── sbproducer, sbconsumer # Azure Service Bus
│ ├── amqpproducer, amqpconsumer # AMQP 1.0 (RabbitMQ 4+, Artemis, Qpid)
│ └── mqttclient # MQTT 5.0
├── cs: C# / .NET 6.0+
│ ├── kafkaproducer, kafkaconsumer
│ ├── ehproducer, ehconsumer, ehazfn # Event Hubs + Azure Functions
│ ├── sbproducer, sbconsumer, sbazfn
│ ├── egproducer, egazfn # Event Grid
│ ├── amqpproducer, amqpconsumer
│ └── mqttclient
├── py: Python 3.9+
│ ├── kafkaproducer, kafkaconsumer
│ ├── ehproducer, ehconsumer
│ └── mqttclient
├── ts: TypeScript
│ ├── kafkaproducer, kafkaconsumer
│ ├── ehproducer, ehconsumer
│ ├── sbproducer, sbconsumer
│ ├── egproducer, amqpproducer, amqpconsumer
│ └── mqttclient
├── asyncapi: AsyncAPI 3.0 definitions
└── openapi: OpenAPI 3.0 definitions
Protocol-Specific Examples
AMQP 1.0 (RabbitMQ, Artemis, Qpid)
# Generate Java producer
xrcg generate --language java --style amqpproducer \
--projectname MyProducer --definitions ./catalog.json --output ./out
# Generate C# consumer
xrcg generate --language cs --style amqpconsumer \
--projectname MyConsumer --definitions ./catalog.json --output ./out
See RabbitMQ AMQP 1.0 Setup Guide for broker configuration.
AsyncAPI / OpenAPI Generation
# Generate AsyncAPI producer definition
xrcg generate --language asyncapi --style producer \
--projectname MyAPI --definitions ./catalog.json --output ./out
# With binary CloudEvents mode
xrcg generate --language asyncapi --style producer \
--projectname MyAPI --definitions ./catalog.json --output ./out \
--template-args ce_content_mode=binary
# Generate OpenAPI for HTTP producer
xrcg generate --language openapi --style producer \
--projectname MyAPI --definitions ./catalog.json --output ./out
Custom Templates
Override built-in templates or add new language/style combinations:
xrcg generate --templates ./my-templates --language java --style myproducer ...
Template directory structure mirrors the built-in templates. See Authoring Templates.
Installation Details
Docker (Recommended)
docker pull ghcr.io/xregistry/codegen/xrcg:latest
Create a shell alias for convenience:
# Linux/macOS (.bashrc or .zshrc)
alias xrcg='docker run --rm -v $(pwd):/work ghcr.io/xregistry/codegen/xrcg:latest'
# Windows PowerShell (profile)
function xrcg { docker run --rm -v ${PWD}:/work ghcr.io/xregistry/codegen/xrcg:latest $args }
Note: File paths must be relative to your current directory due to Docker volume mapping.
Python Package
Requires Python 3.10+:
pip install git+https://github.com/xregistry/codegen.git
For development setup, see Development Environment.
Working with xRegistry Definitions
The generator consumes xRegistry message catalog documents—JSON/YAML files that describe schemas, messages, and endpoints. You can:
- Use existing definition files (see samples/message-definitions/)
- Create definitions manually following the xRegistry spec
- Manage definitions using the CLI's
manifestorcatalogcommands
Sample Definitions
| Sample | Description |
|---|---|
| contoso-erp.xreg.json | ERP system events (orders, payments, inventory) |
| fabrikam-motorsports.xreg.json | Motorsports telemetry stream |
| inkjet.xreg.json | IoT printer events |
Managing Definitions with CLI
Manifest Mode (Local Files)
Work with local JSON files for version-controlled, offline workflows:
# Create a message group
xrcg manifest messagegroup add --manifest=./catalog.json --id=orders --envelope=CloudEvents/1.0
# Add a message definition
xrcg manifest message add --manifest=./catalog.json --messagegroupid=orders \
--id=OrderPlaced --description="Order was placed"
# Validate the file
xrcg validate --definitions ./catalog.json
Catalog Mode (Remote Registry)
Interact with a remote xRegistry HTTP API for team collaboration:
# Configure registry connection
xrcg config set registry.base_url https://registry.example.com
xrcg config set registry.auth_token <token>
# Work with remote registry
xrcg catalog messagegroup add --id=orders ...
xrcg catalog message list --messagegroupid=orders
Currently supports xrserver registry.
Validate Command
Check definition files for errors:
xrcg validate --definitions ./catalog.json
xrcg validate --definitions https://example.com/catalog.json
Configuration
Store defaults to avoid repetition:
xrcg config set defaults.language java
xrcg config set defaults.output_dir ./generated
xrcg config list
Config location: ~/.config/xrcg/config.json (Linux), %APPDATA%\xrcg\config.json (Windows)
What is xRegistry?
xRegistry is a CNCF project defining a standard format for describing messaging and eventing infrastructure. A message catalog document contains:
- Schema groups — Payload schemas (JSON Schema, Avro, Protobuf)
- Message groups — Message definitions with CloudEvents envelope metadata
- Endpoints — Protocol bindings (Kafka topics, AMQP queues, HTTP endpoints)
The code generator follows references between these elements to produce cohesive, type-safe SDKs.
Community
- Slack: #cloudevents on CNCF Slack
- Mailing list: cncf-cloudevents@lists.cncf.io
- Governance: GOVERNANCE.md
- Contributing: CONTRIBUTING.md
License
Metadata
Release files for xrcg 0.11.4
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 |
|---|---|---|---|---|
| xrcg-0.11.4.tar.gz | 775.5 kB | Without provenance | Details for xrcg-0.11.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xrcg-0.11.4-py3-none-any.whl | Python 3 | none | any | Details for xrcg-0.11.4-py3-none-any.whl |
Total release size: 1.8 MB
Release files / xrcg-0.11.4.tar.gz
| Download URL | xrcg-0.11.4.tar.gz |
|---|---|
| Size | 775.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
11bb88fa3e395cd10a70bc64e68af42bbdd999925244eac915864738defcc247
|
|
BLAKE2b-256 checksum How to use checksums |
a139aa4facca7ae7d9120b00f386aa8075136105c6e76a17c2a3acfcbe4ff87e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / xrcg-0.11.4-py3-none-any.whl
| Download URL | xrcg-0.11.4-py3-none-any.whl |
|---|---|
| Size | 1.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1077c6d93b689677119352f3f1080d30a531dde9582a34de35007ab20434750f
|
|
BLAKE2b-256 checksum How to use checksums |
54e44ffccdaa83cc7ea3ae6e379488716cc20bc47d038a95654b56a1c7d7fd82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for xrcg 0.11.4
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.