Genro Routes

Genro Routes Logo

Genro Routes is a transport-agnostic routing engine that decouples method routing from how those methods are exposed. Define your handlers once, then expose them via HTTP, CLI, WebSocket, or any other transport layer.

Why Transport-Agnostic?

Traditional web frameworks tightly couple routing to HTTP. Genro Routes separates these concerns:

Layer

Responsibility

genro-routes

Method registration, hierarchies, plugins, introspection

Transport adapter

Protocol handling, request/response mapping

The routing logic lives in your application objects - the transport adapter (like genro-asgi for HTTP) simply maps external requests to router entries.

What Does This Enable?

  • Same handlers, multiple transports - Expose your API via HTTP and CLI without duplication

  • Runtime introspection - Query available routes, generate documentation, build admin UIs

  • Testability - Test business logic without HTTP overhead

  • Flexibility - Swap transports without changing application code

Use Cases

  • HTTP APIs - Via genro-asgi adapter

  • Internal services - Direct method invocation with plugin pipeline

  • CLI tools - Map commands to router entries

  • Admin dashboards - Runtime introspection for dynamic UIs

Key Features

  • Instance-scoped routers - Every object gets an isolated router with its own plugin stack

  • Hierarchical organization - Build router trees with attach_instance() and / path traversal

  • Composable plugins - Hook into decoration and handler execution with BasePlugin

  • Plugin inheritance - Plugins propagate automatically from parent to child routers

  • Flexible registration - Use @route decorator with prefixes, metadata, and explicit names

  • Runtime configuration - Configure plugins with routing.configure() using target syntax

  • Comprehensive test suite - Full coverage across all features

Quick Example

from genro_routes import RoutingClass, Router, route

class Service(RoutingClass):
    def __init__(self, label: str):
        self.label = label
        self.api = Router(self, name="api")

    @route("api")
    def describe(self):
        return f"service:{self.label}"

# Each instance is isolated
first = Service("alpha")
second = Service("beta")

assert first.api.node("describe")() == "service:alpha"
assert second.api.node("describe")() == "service:beta"

Documentation Sections

Installation

pip install genro-routes

For development:

git clone https://github.com/genropy/genro-routes.git
cd genro-routes
pip install -e ".[all]"

Next Steps

Project Status

Genro Routes is currently in beta. The core API is stable with complete documentation.

  • Python Support: 3.10, 3.11, 3.12, 3.13

  • License: Apache 2.0

Contributing

Contributions are welcome! Please open an issue or pull request on GitHub.

Indices and Tables