How to snap a simple flask application

Is there a good example or tutorial on how to snap a simple python3 Flask application?

It seems to be a simple task which despite this has me caught in lots of work and perils.

i dont think there is any tutorial, but i happen to recently have started an opencv demo that is embedded in a HTML page and served through flask here:

perhaps that gives you some hints …

So, I’ve finally - after massive issues all over - been able to produce a simple example snap containing a flask application.

The process is as follows:

  1. Produce the charmcraft.yaml
  2. Use the python plugin to install flask - Make it a part.
  3. Use the dump plugin to place the python-file with your flask app - Make it a second part.
  4. Use “organize” to copy the file to a place available to your command, e.g. bin/ or so.
  5. Create the command/service.
name: microsample
version: git
summary: A simple flask microservice on
description: |
  Get service status with: curl http://hostip:8080/  (Will return "Online" if OK)
grade: devel # must be 'stable' to release into candidate/stable channels

confinement: strict # use 'strict' once you have the right plugs and slots

# This helps, for example, to build only on archs we can run on.
  - build-on: amd64

base: core22

    command: bin/flask run -h -p 8080
    daemon: simple
    restart-condition: always
    plugs: [network-bind]
      FLASK_APP: ./
      LC_ALL: C.UTF-8
      LANG: C.UTF-8


# This installs flask using python pip.
    plugin: python
    source: .
    python-packages: [ flask ]
# This dumps our sources including
# where we manually have to copy the
# into place.
    plugin: dump
    source: .
# flask could be installed like this instead in the plugin.
#    stage-packages: [ python3-flask ]
    organize: bin/