Controllers (harp.controllers)

The Controllers (harp.controllers) package contains the routing and controller logic for the Harp framework.

You probably do not want to use this package unless you’re writing an extension for Harp.

Example usage:

from harp.controllers import RoutingController, GetHandler


class MyController(RoutingController):
    @GetHandler("/")
    async def index(self):
        return "Hello, world!"

Contents

class DefaultControllerResolver[source]

Bases: IControllerResolver

__init__(*, default_controller=None)[source]
async resolve(request)[source]
Parameters:

request (HttpRequest)

class IControllerResolver[source]

Bases: Protocol

__init__(*args, **kwargs)
async resolve(request)[source]
Parameters:

request (HttpRequest)

class ProxyControllerResolver[source]

Bases: DefaultControllerResolver

__init__(*, default_controller=None)[source]
add(endpoint, *, http_client, dispatcher=None, ControllerType=None)[source]
Parameters:
add_controller(port, controller)[source]
Parameters:
async resolve(request)[source]
Parameters:

request (HttpRequest)

property endpoints: dict[str, Endpoint]
property ports
class RoutingController[source]

Bases: object

RouterType

alias of Router

__init__(*, handle_errors=True, router=None)[source]
configure()[source]
create_router()[source]
handle_error(exc, *, status=500)[source]
RouterArguments = <harp.utils.arguments.Arguments object>
prefix = None
AnyMethodHandler(*paths, **opts)[source]
Parameters:

paths (str | Pattern)

ConnectHandler(*paths, **opts)[source]
Parameters:

paths (str | Pattern)

DeleteHandler(*paths, **opts)[source]
Parameters:

paths (str | Pattern)

GetHandler(*paths, **opts)[source]
Parameters:

paths (str | Pattern)

HeadHandler(*paths, **opts)[source]
Parameters:

paths (str | Pattern)

OptionsHandler(*paths, **opts)[source]
Parameters:

paths (str | Pattern)

PatchHandler(*paths, **opts)[source]
Parameters:

paths (str | Pattern)

PostHandler(*paths, **opts)[source]
Parameters:

paths (str | Pattern)

PutHandler(*paths, **opts)[source]
Parameters:

paths (str | Pattern)

RouteHandler(*paths, methods=None, **opts)[source]
Parameters:
RouterPrefix(prefix)[source]
TraceHandler(*paths, **opts)[source]
Parameters:

paths (str | Pattern)

async dump_request_controller(request)[source]

TODO: use orjson ?

Parameters:

request (HttpRequest)

async not_found_controller()[source]

Submodules