Genro Routes
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 traversalComposable plugins - Hook into decoration and handler execution with
BasePluginPlugin inheritance - Plugins propagate automatically from parent to child routers
Flexible registration - Use
@routedecorator with prefixes, metadata, and explicit namesRuntime configuration - Configure plugins with
routing.configure()using target syntaxComprehensive 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
User Guide
- Basic Usage
- Overview
- Creating Your First Router
- Registering Handlers
- Single Router Default
- Database Access via Context
- Calling Handlers
- Using Prefixes and Custom Names
- Checking Node Errors
- Exceptions: NotFound, NotAuthenticated, NotAuthorized, NotAvailable
- Custom Exception Mapping
- Catch-All Routing with
default_entry - Building Hierarchies
- Introspection
- Custom Metadata with
meta_* - Execution Context
- Wrapping Handler Results
- Next Steps
- Plugin Development
- Overview
- Built-in Plugins
- Shorthand Plugin Syntax
- Built-in Plugins API Reference
- Creating Custom Plugins
- Plugin Hooks
- Plugin Execution Order
- Plugin Inheritance
- Plugin Registration
- Per-Instance State
- Plugin Configuration
- Complete Example: Authorization Plugin
- Best Practices
- Runtime Plugin Management
- Next Steps
- Plugin Configuration
- Hierarchical Routers
- Overview
- Managing Hierarchies
- Basic Instance Attachment
- Multiple Routers: Cross-Mapping
- Parent with Multiple Routers
- Branch Routers
- Direct Router Hierarchies with parent_router
- Auto-Detachment
- Parent Tracking
- Plugin Inheritance
- Path Navigation
- Introspection
- Catch-All Routes with
default_entry - Real-World Examples
- Best Practices
- Common Patterns
- Next Steps
- Best Practices
Reference
- API Reference
- Constructor and slots
- Lazy binding
- Marker discovery
- Handler table and wrapping
- Lookup and execution
- Children (instance hierarchies)
- Introspection
- Output modes
- Hooks for subclasses
BaseRouter- Internal state
- Global registry
- Attaching plugins
- Wrapping pipeline
- Inheritance behaviour
Router- Re-exports
route()RoutingClassRouter
- Plugin API Reference
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
New to Genro Routes? Start with the Quick Start
Have questions? Check the FAQ for common questions and answers
Building plugins? Read the Plugin Development Guide
Need examples? Check the examples directory
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.