https://github.com/vst/openfaas-template-python-fastapi
Experimental and Opinionated OpenFAAS Template (Python + FastAPI)
https://github.com/vst/openfaas-template-python-fastapi
Last synced: 10 months ago
JSON representation
Experimental and Opinionated OpenFAAS Template (Python + FastAPI)
- Host: GitHub
- URL: https://github.com/vst/openfaas-template-python-fastapi
- Owner: vst
- Archived: true
- Created: 2020-03-18T02:29:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-05-13T20:57:37.000Z (about 5 years ago)
- Last Synced: 2025-06-25T11:06:55.565Z (about 1 year ago)
- Language: Dockerfile
- Homepage:
- Size: 24.4 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# OpenFAAS Template using FastAPI Application as Upstream

This template provides an upstream FastAPI application as a
Python-based OpenFAAS function. Therefore:
1. This function is deployed using `of-watchdog` instead of the classic `watchdog`.
2. Multiple endpoints can be defined for functions using this template.
3. (Almost) all essential Web application functionalities are possible
(various HTTP verbs, full control over HTTP headers etc).
## Development Requirements
1. Python 3.7
2. Pipenv
3. Docker
4. OpenFAAS CLI
## Quickstart
Create a directory and change to it:
```
mkdir sandbox
cd sandbox
```
Pull this template:
```
faas-cli template pull "https://github.com/vst/openfaas-template-python-fastapi#0.0.3"
```
Create your new OpenFAAS function, namely `myfunc`:
```
faas-cli new myfunc --lang vst-python-fastapi
```
Change directory to your new OpenFAAS function:
```
cd myfunc
```
Install all your production and development dependencies:
```
pipenv install --dev
```
Run tests:
```
tox
```
Now you can make changes to code and test as you wish.
To build the OpenFAAS function:
```
cd ..
faas-cli build -f myfunc.yml
```
Run the Docker image that is built as an OpenFAAS function:
```
docker run --rm -p 8000:8080 myfunc
```
Now you can visit [http://localhost:8000](http://localhost:8000) or use `curl` to check your function live:
```
curl -D - http://localhost:8000
```
## Motivation
It is not so difficult to build such a function with the [official
*dockerfile* OpenFAAS
template](https://github.com/openfaas/templates/tree/master/template/dockerfile). The
motivation behind this very template is to pull in all required
development dependencies and setup the development environment with
sane configurations like you would do for a typical Python
application:
0. Pipenv
1. **IDE configuration template:** VS Code workspace
2. **Python development dependencies:**
- black (configured)
- flake8 (configured)
- ipython
- isort (configured)
- mypy (configured)
- pylint (configured)
- pytest (configured)
- sphinx (not configured)
- tox (configured)