This template helps you writing your own optimization model in Python. It contains several files to easily deploy the model to the Nextmv platform.
The most important files created are main.py and input.json.
main.pyis the starting point for the model.input.jsonis a sample input file.
Follow these steps to run locally.
-
The packages listed in the
requirements.txtwill get bundled with the app as defined in theapp.yamlmanifest. When working locally, make sure that these are installed as well:pip3 install -r requirements.txt
-
Run the command below to check that everything works as expected:
python3 main.py -input input.json -output output.json -recipient nextmv
-
A file
output.jsonshould have been created a greeting message.
Pre-requisites: Docker needs to be installed.
To run the application locally in the same docker image as the one used on the Nextmv Cloud, you can use the following command:
cat input.json | docker run -i --rm \
-v $(pwd):/app ghcr.io/nextmv-io/runtime/python:3.11 \
sh -c 'pip install -r requirements.txt &> /dev/null && python3 /app/main.py'Note that this command installs the dependencies from the requirements.txt
file on the fly. If you want to avoid this, you can build a custom image with
the dependencies already installed.
You can also debug the application by running it in a Dev Container. This
workspace recommends to install the Dev Container extension for VSCode. If you
have the extension installed, you can open the workspace in a container by using
the command Dev Containers: Reopen in Container.
- Open
main.pyand start writing the model in python. - Further documentation, guides, and API references about custom modeling and deployment can also be found on our blog and on our documentation site.
- Need more assistance? Send us an email!