Genro Routes Logo

Getting Started

  • Installation
    • Requirements
    • From PyPI
    • With Optional Dependencies
      • Development Tools
      • Documentation Tools
      • All Dependencies
    • From Source
    • Verify Installation
    • Next Steps
  • Quick Start
    • Installation
    • Your First Router
    • Custom Entry Names
    • Single Router Default
    • Building Hierarchies
    • Adding Plugins
    • Validating Arguments
    • Response Schemas
    • Execution Context
    • Next Steps
    • Need Help?
  • Examples Gallery
    • Library Wrappers
      • 1. Standard Faker
      • 2. Magic Faker (Dynamic Mapping)
      • 3. Syntax Highlighting (Pygments)
      • 4. QR Code Generator
    • Architectural Patterns
      • 5. Authentication & Roles
      • 6. Service Composition
      • 7. Self-Documentation (Meta-Example)
    • LLM & MCP Integration
      • 8. MCP Bridge
      • 9. Repository Explorer
      • 10. Deep Repo Explorer
    • Running the Examples
  • Genro Routes - Frequently Asked Questions
    • What is Genro Routes?
      • What problem does Genro Routes solve?
      • Genro Routes vs function dictionary?
      • Is Genro Routes a web framework?
    • Core Concepts
      • What is a Router?
      • How does the @route decorator work?
      • What is RoutingClass?
    • Hierarchies and Child Routers
      • How do I organize nested routers?
      • How do I access child routers?
      • Do plugins inherit to children?
    • Plugin System
      • What are plugins?
      • How do I use built-in plugins?
      • How do I configure plugins at runtime?
      • Can I create custom plugins?
    • Advanced Use Cases
      • How do I handle errors and defaults?
      • What exceptions can node() raise?
      • What is a root node?
      • How do I introspect the structure?
    • Comparisons
      • Genro Routes vs decorator dispatch?
    • Troubleshooting
      • “No plugin named ‘X’ attached to router”
      • “Handler name collision”
      • Plugins don’t propagate to children
      • ValidationError with Pydantic
    • Best Practices
      • When should I use Genro Routes?
      • Does plugin order matter?
      • How do I test code with Genro Routes?
    • Context and Shared State
      • How do I access a database connection from my handlers?
      • What happened to DbRoutingClass?
    • Useful Links
    • Contributing

User Guide

  • Basic Usage
    • Overview
    • Creating Your First Router
    • Registering Handlers
    • Single Router Default
    • Database Access via Context
      • Accessing the Default Router
    • 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
      • AuthPlugin API
      • EnvPlugin API
      • PydanticPlugin API
      • OpenAPIPlugin API
      • ChannelPlugin API
    • Creating Custom Plugins
      • Basic Plugin Structure
      • Constructor Signature
    • Plugin Hooks
    • Plugin Execution Order
      • The Onion Model
      • Example: Logging then Validation
      • Practical Ordering Guidelines
      • Visualizing the Stack
      • configure(**kwargs)
      • on_decore(router, func, entry)
      • wrap_handler(router, entry, call_next)
      • deny_reason(entry, **filters)
      • entry_metadata(router, entry)
      • on_attached_to_parent(parent_plugin)
      • on_parent_config_changed(old_config, new_config)
    • Plugin Inheritance
      • Inheritance Rules
      • Why This Design?
      • Example: AuthPlugin Inheritance
    • Plugin Registration
    • Per-Instance State
    • Plugin Configuration
      • Defining Configuration
      • Reading Configuration
      • Configuring at Runtime
      • The _target Parameter
      • The flags Parameter
    • Complete Example: Authorization Plugin
    • Best Practices
    • Runtime Plugin Management
      • Enabling and Disabling Plugins
      • Storing Runtime Data
    • Next Steps
  • Plugin Configuration
    • Overview
    • Target Syntax
    • Glob Pattern Syntax
    • Basic Configuration
    • Batch Updates
    • Introspection
    • Exposing Configuration API
    • Error Handling
    • Best Practices
    • Next Steps
  • 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
      • Direct Router Lookup with router_at_path
    • Introspection
    • Catch-All Routes with default_entry
    • Real-World Examples
      • Microservice-Style Organization
      • Multi-Level Organization with Branches
      • Dynamic Service Replacement
    • Best Practices
      • Logical Grouping with Branches
      • Shared Plugins at Root
      • Deep Hierarchies
      • Retrieve Child Instances
      • Explicit Detachment
      • Prevent Name Collisions
    • Common Patterns
      • Parent-Aware Children
      • Conditional Attachment
      • Multi-Router Services
    • Next Steps
  • Best Practices
    • Router Design
      • Keep Routers Focused
      • Use Meaningful Names
      • Leverage Prefixes for Organization
    • Hierarchy Design
      • Flat is Better Than Deep
      • Use Branch Routers for Organization
      • Attaching Child Instances
    • Plugin Usage
      • Apply Plugins at the Right Level
      • Compose Simple Plugins
      • Configure Plugins Explicitly
    • Error Handling
      • Let Errors Propagate
      • Use Plugin Wrappers for Cross-Cutting Concerns
    • Testing
      • Test Handlers in Isolation
      • Test Hierarchies
      • Test Plugin Behavior
    • Performance
      • Attach Plugins Early
      • Cache Handler References
    • Anti-Patterns
      • Global State in Plugins
      • Circular Dependencies
      • Over-Configuration
    • Summary
    • Next Steps

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
      • BaseRouter.__init__()
      • BaseRouter.instance
      • BaseRouter.name
      • BaseRouter.prefix
      • BaseRouter.description
      • BaseRouter.default_entry
      • BaseRouter.current_capabilities
      • BaseRouter.add_entry()
      • BaseRouter.include()
      • BaseRouter.detach_instance()
      • BaseRouter.get_url()
      • BaseRouter.router_at_path()
      • BaseRouter.nodes()
      • BaseRouter.node()
      • BaseRouter.iter_plugins()
    • Internal state
    • Global registry
    • Attaching plugins
    • Wrapping pipeline
    • Inheritance behaviour
    • Router
      • Router.__init__()
      • Router.register_plugin()
      • Router.available_plugins()
      • Router.plug()
      • Router.iter_plugins()
      • Router.get_config()
      • Router.__getattr__()
      • Router.set_plugin_enabled()
      • Router.is_plugin_enabled()
      • Router.set_runtime_data()
      • Router.get_runtime_data()
      • Router.instance
      • Router.name
      • Router.prefix
      • Router.description
      • Router.default_entry
    • Re-exports
    • route()
    • RoutingClass
      • RoutingClass.attach_instance()
      • RoutingClass.routing
      • RoutingClass.ctx
      • RoutingClass.default_router
      • RoutingClass.capabilities
      • RoutingClass.result_wrapper()
    • Router
      • Router.__init__()
      • Router.register_plugin()
      • Router.available_plugins()
      • Router.plug()
      • Router.iter_plugins()
      • Router.get_config()
      • Router.__getattr__()
      • Router.set_plugin_enabled()
      • Router.is_plugin_enabled()
      • Router.set_runtime_data()
      • Router.get_runtime_data()
      • Router.instance
      • Router.name
      • Router.prefix
      • Router.description
      • Router.default_entry
  • Plugin API Reference
    • Auto-Generated Plugin API
      • AuthPlugin
        • AuthPlugin.plugin_code
        • AuthPlugin.plugin_description
        • AuthPlugin.plugin_code
        • AuthPlugin.plugin_description
        • AuthPlugin.plugin_default_param
        • AuthPlugin.configure()
        • AuthPlugin.deny_reason()
        • AuthPlugin.name
      • EnvPlugin
        • EnvPlugin.plugin_code
        • EnvPlugin.plugin_description
        • EnvPlugin.plugin_code
        • EnvPlugin.plugin_description
        • EnvPlugin.plugin_default_param
        • EnvPlugin.configure()
        • EnvPlugin.deny_reason()
        • EnvPlugin.name
      • CapabilitiesSet
        • CapabilitiesSet.__iter__()
        • CapabilitiesSet.__contains__()
        • CapabilitiesSet.__len__()
      • capability()
      • Configuration
      • LoggingPlugin
        • LoggingPlugin.plugin_code
        • LoggingPlugin.plugin_description
        • LoggingPlugin.plugin_code
        • LoggingPlugin.plugin_description
        • LoggingPlugin.__init__()
        • LoggingPlugin.configure()
        • LoggingPlugin.wrap_handler()
      • Configuration
      • OpenAPIPlugin
        • OpenAPIPlugin.plugin_code
        • OpenAPIPlugin.plugin_description
        • OpenAPIPlugin.plugin_code
        • OpenAPIPlugin.plugin_description
        • OpenAPIPlugin.configure()
        • OpenAPIPlugin.entry_metadata()
        • OpenAPIPlugin.name
      • OpenAPITranslator
        • OpenAPITranslator.translate_openapi()
        • OpenAPITranslator.translate_h_openapi()
        • OpenAPITranslator.entry_info_to_openapi()
        • OpenAPITranslator.create_pydantic_model_for_func()
        • OpenAPITranslator.schema_to_parameters()
        • OpenAPITranslator.python_type_to_openapi_schema()
        • OpenAPITranslator.SCALAR_TYPES
        • OpenAPITranslator.guess_http_method()
        • OpenAPITranslator.entry_to_openapi()
      • PydanticPlugin
        • PydanticPlugin.plugin_code
        • PydanticPlugin.plugin_description
        • PydanticPlugin.plugin_code
        • PydanticPlugin.plugin_description
        • PydanticPlugin.__init__()
        • PydanticPlugin.configure()
        • PydanticPlugin.on_decore()
        • PydanticPlugin.wrap_handler()
        • PydanticPlugin.get_model()
        • PydanticPlugin.name
        • PydanticPlugin.entry_metadata()
Genro Routes
  • Examples Gallery
  • Edit on GitHub

Examples Gallery

Learning by example is often the fastest way to understand the architectural power of genro-routes. This gallery showcases a variety of use cases, from simple library wrappers to complex service compositions.

Tip

New to Genro-Routes? Read our architectural deep-dive: Why wrap a library with Genro-Routes?

Library Wrappers

These examples show how to take existing Python libraries and turn them into robust, validated, and self-documenting services.

1. Standard Faker

Demonstrates explicit routing using the {route} decorator. Perfect for well-defined APIs where you want full control over which methods are exposed.

  • Source: examples/faker_standard.py

2. Magic Faker (Dynamic Mapping)

Shows how to use Python introspection to automatically map all public methods of a library (Faker providers) into the routing tree with zero boilerplate.

  • Source: examples/faker_magic.py

3. Syntax Highlighting (Pygments)

Turns the Pygments library into a service. It demonstrates how Pydantic validation protects complex formatting options (HTML vs ANSI).

  • Source: examples/pygments_highlighting.py

4. QR Code Generator

A classic “Asset Generation as a Service” example. Shows how to validate input data before triggering expensive image processing.

  • Source: examples/qrcode_generator.py

Architectural Patterns

5. Authentication & Roles

A deep dive into the AuthPlugin. Shows how to protect specific nodes with role tags and how to handle the new specific exceptions like NotAuthenticated and NotAuthorized.

  • Source: examples/auth_roles.py

6. Service Composition

One of the most powerful features of the library. Shows how to build a large application by mounting independent RoutingClass modules (like “Billing” and “Inventory”) into a single, unified hierarchical tree.

  • Source: examples/service_composition.py

7. Self-Documentation (Meta-Example)

The ultimate demonstration of dynamic mapping: genro-routes documenting itself. Exposes the internal Router API as a service, showing how to use the library as a transparent management layer for existing codebases.

  • Source: examples/self_documentation.py

LLM & MCP Integration

These examples demonstrate how genro-routes enables live documentation that LLMs can consume directly, turning any Python service into an AI-accessible tool provider.

8. MCP Bridge

A conceptual implementation of a Model Context Protocol (MCP) bridge. Shows how to:

  • Discover all routes via nodes() introspection

  • Extract JSON schemas from Pydantic metadata

  • Generate MCP-compatible tool definitions

  • Route LLM tool calls back to Python functions

Includes an agent simulation using the Anthropic API.

  • Source: examples/mcp_bridge/

9. Repository Explorer

Exposes a filesystem repository as a service with list_dir, read_file, and get_info methods. Demonstrates the correct pattern: methods with path parameters instead of one-router-per-file (anti-pattern).

  • Source: examples/repo_explorer.py

Tip

Evolution ideas: content caching, full-text search, file watch for changes.

10. Deep Repo Explorer

Maps Python files as routers, introspecting classes and functions at runtime. Combined with MCP Bridge, allows an LLM to discover API structure without filesystem access.

  • Source: examples/deep_repo_explorer.py

Tip

Evolution ideas: signature indexing, pattern-based search, semantic search via embeddings.


Running the Examples

You can find all these files in the examples/ directory of the repository. To run them:

  1. Clone the repository.

  2. Install dependencies: pip install faker pygments qrcode[pil].

  3. Run any example directly: python examples/faker_standard.py.

Previous Next

© Copyright 2025, Softwell S.r.l..

Built with Sphinx using a theme provided by Read the Docs.