Tutorial for deploying a Python Flask Server on Wasmer Edge
In this guide, you'll learn the process of deploying a python flask application on Wasmer Edge. We'll be deploying a basic flask server with default index endpoint.
Install the latest version of Wasmer CLI following the instructions here.
You can see all commands available with
wasmer --help. You can also
read the CLI documentation online.
Please check that you have the latest version of wasmer runtime as this tutorial depends on version 4.2.3 or higher.
Create a new account in Wasmer (opens in a new tab). Then, log in into the Wasmer CLI and follow the provided steps to provide the CLI access to your Wasmer account.
$ wasmer app create App type: Static website HTTP server Browser shell JS Worker (experimental) > Python Application
This is an interactive command. You can also use the
--type flag to specify
the app type.
Further you will be prompted to enter your package name and app name. You can choose any name you like.
The app names should be globally unique across all apps on the registry.
You directory composition should look like this:
$ python -m venv .env
You directory composition should look like this with
.env folder added:
$ source .env/bin/activate
$ pip install flask
main.py file to look like this:
from flask import Flask app = Flask(__name__) @app.route("/") def index(): return "Hello, from Wasmer Edge 🚀"
You can change the return string to anything you like.
$ python -m flask --app /src/main run --debug --no-reload * Serving Flask app './src/main' * Debug mode: on WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://127.0.0.1:5000 Press CTRL+C to quit
wasmer.toml we need to set up some
[package] name = "wasmer/python-flask-server" version = "0.1.1" description = "wasmer/python-flask-server python application" readme = "README.md" [dependencies] "wasmer/python" = "^3.12.6" [fs] "/src" = "./src" "/cpython/lib/python3.12" = "./.env/lib/python3.11" [[command]] name = "script" module = "wasmer/python:python" runner = "wasi" [command.annotations.wasi] main-args = [ # This is the command we want the python runner to run "-m", "flask", "--app", "/src/main", "run", "--debug", "--no-reload", ] env = ["PYTHONEXECUTABLE: /bin/python"] # This is the path to the python executable
app.yaml we want to provide the same args as we did in the
--- kind: wasmer.io/App.v0 name: wasmer-python-flask-server-myapp-example package: firstname.lastname@example.org cli_args: # This is the command we want the python runner to run on Wasmer Edge - -m - flask - --app - /src/main - run - --debug - --no-reload env: PYTHONEXECUTABLE: /bin/python # This is the path to the python executable
Now, we can test if our application runs with wasmer
$ wasmer run . --net * Serving Flask app '/src/main' * Debug mode: on WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://127.0.0.1:5000 Press CTRL+C to quit
The above command will start a web server on
Let's try to cURL the server:
$ curl http://127.0.0.1:5000 Hello, from Wasmer Edge 🚀
Deploying is the easiest part. Just run the following command:
$ wasmer deploy Loaded app from: /.../wasmer-edge/python-flask/app.yaml Deploying app wasmer-python-flask-server-myapp-example... ✅ App dynamite-bud/wasmer-python-flask-server-myapp-example was successfully deployed! > App URL: https://wasmer-python-flask-server-myapp-example.wasmer.app > Versioned URL: https://2mzhyi8cqzxr.id.wasmer.app > Admin dashboard: https://wasmer.io/apps/wasmer-python-flask-server-myapp-example Waiting for new deployment to become available... (You can safely stop waiting now with CTRL-C)
Now you can visit the URL and see your application running on Wasmer Edge.
You must be in the directory holding the
You can view the above info again using
wasmer app info.
Congratulations! You have successfully deployed your python flask application on Wasmer Edge.wasmerio/python-flask-server-myapp-example