βοΈ Approximate time to complete: 15 min.
In this tutorial you will learn how to work with multi-file inputs and outputs on the Nextmv Platform. Complete this tutorial if you:
- Want to work with CSV, Excel, or multiple data files instead of single JSON.
- Are fluent using Python π.
At a high level, this tutorial will go through the following steps:
- When to use multi-file format.
- Scaffold a multi-file app.
- Understand the app manifest.
- Load multi-file inputs.
- Write multi-file outputs.
- Run locally.
- View in Console.
Let's dive right in π€Ώ.
1. When to use multi-file format
By default, Nextmv applications use JSON as the data format. Input is read from stdin and output is written to stdout, all as a single JSON object. This works well for many use cases, but sometimes you need more flexibility.
The multi-file format reads from an inputs/ directory and writes to an outputs/ directory. Use it when:
- Your data lives in CSV or Excel files.
- You have multiple related input files (e.g., items, capacities, and configuration).
- You work with large datasets that are easier to manage as separate files.
Multi-file format is supported in local runs, cloud runs, and the Console.
2. Scaffold a multi-file app
Use the nextmv init command to create a new multi-file application. When prompted, select Python as the language and Multi-file as the format:
Walk through the prompts: Template, Python, Multi-file, and then the path for your new app. Alternatively, you can clone the python-ortools-knapsack-multicsv community app:
After scaffolding, the resulting directory structure looks like this:
The inputs/ directory contains your input data files. The app.yaml file configures the multi-file format. The main.py file contains your application logic.
3. Understand the app manifest
The app.yaml file is the app manifest that tells Nextmv how to run your application. For multi-file apps, it includes format configuration:
Key fields:
format: multi-fileenables the multi-file format.input.pathspecifies where input files are read from.output.solutionsspecifies where solution files are written.output.metricsspecifies where run metrics are written.output.assetsspecifies where asset metadata is written.
4. Load multi-file inputs
The nextmv Python package provides helpful functions for interacting with multi-file inputs/ outputs. You are not required to use these functions. The only requirement is that your model reads from the input path and and writes to the output path specified in your app.yaml.
You can use nextmv.load() with InputFormat.MULTI_FILE to load data from multiple files. Each file is described by a data file descriptor that specifies the file name, format, and key in the resulting data dictionary.
How it works:
csv_data_file("items")loadsitems.csvfrom the input directory. The.csvextension is added automatically.json_data_file("config")loadsconfig.jsonfrom the input directory. The.jsonextension is added automatically.input_data_keysets the key used to access the data ininput.data.- CSV files are loaded as a list of dicts, where each row becomes a dict.
For Excel files, use a custom DataFile with a loader function:
5. Write multi-file outputs
Use nextmv.Output with OutputFormat.MULTI_FILE to write solution files. Each solution file is described by a solution file descriptor that specifies the file name, format, and data.
How it works:
json_solution_file("result", data=solution)writes tooutputs/solutions/result.json.csv_solution_file("assignments", data=assignments)writes tooutputs/solutions/assignments.csv.- File extensions are added automatically by the convenience functions.
- Statistics are written to
outputs/metrics.json.
For Excel output, use a custom SolutionFile with a writer function:
The path parameter in nextmv.load() and nextmv.write() should match the paths configured in your app.yaml.
6. Run locally
Run your multi-file application locally using nextmv local run create, pointing to the inputs directory:
After running, the output directory structure looks like this:
The solutions/ directory contains your solution files, and the metrics.json file contains run statistics such as duration and objective value.
7. View in Console
When your app is pushed to Nextmv Cloud and run remotely, the Console provides a multi-file viewer for inspecting results.
The viewer shows:
- A file tree on the left with all input and output files.
- A content preview on the right for the selected file.
- CSV files render as interactive tables.
- JSON files render in the code editor.
This makes it easy to browse through all the files associated with a run without downloading them individually.
To push your app to Nextmv Cloud and run it remotely, follow the steps in the Connect your model tutorial.