pymhf.core.http_api module#

class pymhf.core.http_api.APIEndpointProtocol(*args, **kwargs)#

Bases: Protocol

Protocol for API Endpoint objects

class pymhf.core.http_api.CleanableAPIRouter(mod_name: str, *args, **kwargs)#

Bases: APIRouter

clear()#

Remove all existing routes.

load_routes(routes: dict[str, list[APIEndpointProtocol]])#

Load all the routes for a mod.

class pymhf.core.http_api.EndpointData(route, method, dont_extend)#

Bases: NamedTuple

dont_extend: bool#

Alias for field number 2

method: Literal['GET', 'PUT', 'WEBSOCKET'] | None#

Alias for field number 1

route: str#

Alias for field number 0

class pymhf.core.http_api.ThreadedServer(app: FastAPI, host: str, port: int)#

Bases: object

Loosely wrapped version of the uvicorn Server object to facilitate running it in a thread.

run()#
shutdown()#
pymhf.core.http_api.create_app() FastAPI#
pymhf.core.http_api.endpoint(route: str | None = None, method: Literal['GET', 'PUT', 'WEBSOCKET'] | None = None, dont_extend: bool = False)#

Create a HTTP endpoint for the decorated method or property.

Parameters:
  • route – The name of the path to serve the endpoint on. This will always be relative to the name of the mod this method or property belongs to. If not provided, it will fallback to the name of the function.

  • method – The type of HTTP request this will be bound to. Note that if this is specified as “WEBSOCKET”, this function will be called repeatedly, so make sure nothing which blocks or takes a long time to retrieve is called.

  • dont_extend – By default, if this decorator is applied to a property, if that property also has a setter, then a PUT endpoint will also be generated for it. To disable this set this to True.

async pymhf.core.http_api.websocket_wrapper(websocket: WebSocket, func_name: str)#