This project is not actively maintained. If you are considering using it please take a look at https://github.com/JustinGuese/openfaas-python3-fastapi-template as a possible alternative.
A Python FastAPI template that make use of the incubator project of-watchdog.
Templates available in this repository:
- python3-fastapi
With a function created from this template:
- An HTTP POST will execute the function (as usual)
- An HTTP GET will render a SwaggerUI page that tells you how to use the function (response/request schemas are generated from the pydantic models and constants the user defines in their function handler)
$ faas template pull https://github.com/loudsquelch/openfaas-python3-fastapi-template
Create a new function
$ faas new --lang python3-fastapi <fn-name>
Build, push, and deploy
$ faas up -f <fn-name>.yml
Set your OpenFaaS gateway URL. For example:
$ OPENFAAS_URL=http://127.0.0.1:8080
Test the new function
$ curl -i $OPENFAAS_URL/function/<fn-name>
The function handler is passed one argument - req which contains the request body.
By default, the template will automatically attempt to set the correct Content-Type header for you based on the type of response.