Routes are wrapped function objects that are called upon a HTTP request.


Route(function, *, …) A route object is a wrapped function.
class kyoukai.route.Route(function, *, reverse_hooks: bool = False, should_invoke_hooks: bool = True, do_argument_checking: bool = True, endpoint: str = None)[source]

Bases: object

A route object is a wrapped function. They invoke this function when invoked on routing and calling.

  • function – The underlying callable. This can be a function, or any other callable.
  • reverse_hooks (bool) – If the request hooks should be reversed for this request (i.e child to parent.)
  • should_invoke_hooks (bool) – If request hooks should be invoked. This is automatically False for error handlers.
  • do_argument_checking (bool) – If argument type and name checking is enabled for this route.
  • endpoint (Optional[str]) – The custom endpoint for this route.
do_argument_checking = None

If this route should do argument checking.

bp = None

The Blueprint this route is associated with.

routes = None

A list of tuples (url, methods) for this Route.

endpoint = None

The custom endpoint for this route. Could be None.

hooks = None

Our own specific hooks.

add_path(url, methods=('GET', 'HEAD'))[source]

Adds a path to the current set of paths for this route.

  • url (str) – The routing URL to add.
  • methods (Sequence[str]) – An iterable of methods to use for this path.

The URL and methods will be added as a pair.

Return type:Submount
Returns:A submount that represents this route.

New in version 2.2.0.

Changed in version 2.x.x: Changed from getting a list of rules to a single submount object.


Gets the endpoint name for this route.

Parameters:bp – The Blueprint to use for name calculation.
Return type:str
Returns:The endpoint that can be used.
coroutine invoke_function(self, ctx, pre_hooks, post_hooks, params)[source]

Invokes the underlying callable. This is for use in chaining routes.

  • ctx – The HTTPRequestContext to use for this route.
  • pre_hooks (list) – A list of hooks to call before the route is invoked.
  • post_hooks (list) – A list of hooks to call after the route is invoked.
  • params – The parameters to pass to the function.

The result of the invoked function.


Checks the arguments for a route.

Parameters:params (Optional[dict]) – The parameters passed in, as a dict.
Raises:TypeError – If the arguments passed in were not correct.
add_hook(type_, hook)[source]

Adds a hook to the current Route.

  • type (str) – The type of hook to add (currently “pre” or “post”).
  • hook – The callable function to add as a hook.

Gets the hooks for the current Route for the type.

Parameters:type (str) – The type to get.
Returns:A list of callables.

Convenience decorator to add a pre-request hook.


Convenience decorator to add a post-request hook.

coroutine invoke(self, ctx, args=(), params=None)[source]

Invokes a route. This will run the underlying function.

Return type:



The result of the route’s function.