Implement py. file in Balena OS

I’m pretty new in coding and in Balena OS, I want to implement a pyhton file in my RevPI connect that I flash with Balena OS. First I implement the “hello world python project” but in thise project there is only one file in python “src” and this file call an other file via render_template(‘index.html’). I want to implement a pyhton file that will integrate modbus communication. There is any solution to run a python as “master” file in Balena OS.

Best regards,


Hello Hugo,

Glad to hear that you are trying out Balena OS!

So if you want to run a python file in a container in balena OS, just like the hello world example is running a webserver in a container, I would recommend the folliwing:

  1. Copy the structure of the hello world example that you have already looked at: GitHub - balena-io-examples/balena-python-hello-world: Example of how to deploy Python code on a balena supported device.
  2. Add your python file into the project
  3. In the Dockerfile.template, you specify not only what dependencies will be installed into the container that will run your application, but you also specify an “entrypoint”, which is the command that will first be run when the container is started: balena-python-hello-world/Dockerfile.template at master · balena-io-examples/balena-python-hello-world · GitHub you will change this line to instead run your new python script

As balenaOS is built around running containerised applications - if you are unfamiliar with this sort of environment, its worth looking up a little bit about these workflows: Define a container - Balena Documentation

Hope this helps!