fastiot_sample_services.fastapi package

FastAPI Module with uvicorn webserver and UI created with vue.js

This module is a short demo how to create a vue.js based frontend and serve the files using FastAPI and and Uvicorn-Server to serve the files.

Included is a sample to use received fastiot.msg.thing.Thing over nats and use this for requests and also a websocket.

Submodules

fastiot_sample_services.fastapi.env module

class fastiot_sample_services.fastapi.env.FastAPIModuleConstants[source]
property fastapi_port: int

..envvar:: FASTIOT_SAMPLE_FASTIOT_PORT

Set the port for the FastAPI REST interface in the FastAPI sample module.

fastiot_sample_services.fastapi.fastapi_module module

class fastiot_sample_services.fastapi.fastapi_module.FastAPIModule(**kwargs)[source]
__init__(**kwargs)[source]
async serve_websocket(websocket)[source]

Demonstration of using websockets

You need to send one char first before all new arriving machine data will be sent to the client

https://fastapi.tiangolo.com/advanced/websockets/

fastiot_sample_services.fastapi.model module

pydantic model fastiot_sample_services.fastapi.model.Response[source]
field resp_value: float [Required]
Validated by:
pydantic model fastiot_sample_services.fastapi.model.Request[source]
field req_value: List[int] [Required]
Validated by:

fastiot_sample_services.fastapi.run module

fastiot_sample_services.fastapi.uvicorn_server module

Simple class to provide an async uvicorn server to be started within a SAM module

class fastiot_sample_services.fastapi.uvicorn_server.UvicornAsyncServer(app, port, host='0.0.0.0')[source]

Uvicorn async server

__init__(app, port, host='0.0.0.0')[source]

Create an Uvicorn test server

Args:

app (FastAPI, optional): the FastAPI app. Defaults to main.app. host (str, optional): the host ip. Defaults to ‘127.0.0.1’. port (int, optional): the port. Defaults to PORT.

async startup(sockets=None)[source]

Override uvicorn startup

Return type:

None

async up()[source]

Start up server asynchronously

Return type:

None

async down()[source]

Shut down server asynchronously

Return type:

None