Application Module¶
This section documents the application components of the Nextmv Python SDK - Local experience.
application
¶
Application module for interacting with local Nextmv applications.
This module provides functionality to interact with applications in Nextmv, including application management, running applications, and managing inputs.
| CLASS | DESCRIPTION |
|---|---|
Application |
Class for interacting with local Nextmv Applications. |
Application
dataclass
¶
Application(
src: str,
description: str | None = None,
manifest: Manifest | None = None,
)
A decision model that can be executed.
You can import the Application class directly from local:
This class represents an application in Nextmv, providing methods to interact with the application, run it with different inputs, manage versions, instances, experiments, and more.
| PARAMETER | DESCRIPTION |
|---|---|
|
Source of the application, when initialized locally. An application's
source typically refers to the directory containing the
TYPE:
|
|
Description of the application.
TYPE:
|
Examples:
>>> from nextmv.local import Application
>>> app = Application(src="path/to/app")
>>> # Retrieve an app's run result
>>> result = app.run_result("run-id")
description
class-attribute
instance-attribute
¶
Description of the application.
initialize
classmethod
¶
initialize(
src: str | None = None,
description: str | None = None,
destination: str | None = None,
) -> Application
Initialize a sample Nextmv application, locally.
This method will create a new application in the local file system. The
application is a dir with the name given by src (it becomes the
source of the app), under the location given by destination. If the
destination parameter is not specified, the current working directory
is used as default. This method will scaffold the application with the
necessary files and directories to have an opinionated structure for
your decision model. Once the application is initialized, you are
encouraged to complete it with the decision model itself, so that the
application can be run locally.
If the src parameter is not provided, a random name will be generated
for the application.
| PARAMETER | DESCRIPTION |
|---|---|
|
Source (ID, name) of the application. Will be generated if not provided.
TYPE:
|
|
Description of the application.
TYPE:
|
|
Destination directory where the application will be initialized. If not provided, the current working directory will be used.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Application
|
The initialized application instance. |
Source code in nextmv/nextmv/local/application.py
list_runs
¶
List all runs for the application.
| RETURNS | DESCRIPTION |
|---|---|
list[Run]
|
A list of all runs associated with the application. |
Source code in nextmv/nextmv/local/application.py
manifest
class-attribute
instance-attribute
¶
Manifest of the application. A manifest is a file named app.yaml that
must be present at the root of the application's src directory. If the
app is initialized, and a manifest is not present, a default Python
manifest will be created, using the nextmv.default_python_manifest
function. If you specify this argument, and a manifest file is already
present in the src directory, the provided manifest will override the
existing one.
new_run
¶
new_run(
input: Input | dict[str, Any] | BaseModel | str = None,
name: str | None = None,
description: str | None = None,
options: Options | dict[str, str] | None = None,
configuration: RunConfiguration
| dict[str, Any]
| None = None,
json_configurations: dict[str, Any] | None = None,
input_dir_path: str | None = None,
) -> str
Run the application locally with the provided input.
This method is the local equivalent to cloud.Application.new_run,
which submits the input to Nextmv Cloud. This method runs the
application locally using the src of the app.
Make sure that the src attribute is set on the Application class
before running locally, as it is required by the method.
| PARAMETER | DESCRIPTION |
|---|---|
|
Input to use for the run. This can be a If If you want to work with When
When working with JSON or text data, use the In general, if an input is too large, it will be uploaded with the
TYPE:
|
|
Name of the local run.
TYPE:
|
|
Description of the local run.
TYPE:
|
|
Options to use for the run. This can be a
TYPE:
|
|
Configuration to use for the run. This can be a
TYPE:
|
|
Optional configurations for JSON serialization. This is used to customize the serialization before data is sent.
TYPE:
|
|
Path to a directory containing input files. This is useful for
input formats like
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
ID ( |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the |
FileNotFoundError
|
If the manifest.yaml file cannot be found in the specified |
Examples:
>>> from nextmv.local import Application
>>> app = Application(id="my-app", src="/path/to/app")
>>> run_id = app.new_run(
... input={"vehicles": [{"id": "v1"}]},
... options={"duration": "10s"}
... )
>>> print(f"Local run completed with ID: {run_id}")
Source code in nextmv/nextmv/local/application.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
new_run_with_result
¶
new_run_with_result(
input: Input | dict[str, Any] | BaseModel | str = None,
name: str | None = None,
description: str | None = None,
run_options: Options | dict[str, str] | None = None,
polling_options: PollingOptions = DEFAULT_POLLING_OPTIONS,
configuration: RunConfiguration
| dict[str, Any]
| None = None,
json_configurations: dict[str, Any] | None = None,
input_dir_path: str | None = None,
output_dir_path: str | None = ".",
) -> RunResult
Submit an input to start a new local run of the application and poll
for the result. This is a convenience method that combines the
new_run and run_result_with_polling methods, applying
polling logic to check when the local run succeeded.
This method is the local equivalent to
cloud.Application.new_run_with_result, which submits the input to
Nextmv Cloud. This method runs the application locally using the src
of the app.
Make sure that the src attribute is set on the Application class
before running locally, as it is required by the method.
| PARAMETER | DESCRIPTION |
|---|---|
|
Input to use for the run. This can be a If If you want to work with When
When working with JSON or text data, use the In general, if an input is too large, it will be uploaded with the
TYPE:
|
|
Name of the local run.
TYPE:
|
|
Description of the local run.
TYPE:
|
|
Options to use for the run. This can be a
TYPE:
|
|
Options to use when polling for the run result.
TYPE:
|
|
Configuration to use for the run. This can be a
TYPE:
|
|
Optional configurations for JSON serialization. This is used to customize the serialization before data is sent.
TYPE:
|
|
Path to a directory containing input files. This is useful for
input formats like
TYPE:
|
|
Path to a directory where non-JSON output files will be saved. This is required if the output is non-JSON. If the directory does not exist, it will be created. Uses the current directory by default.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RunResult
|
Result of the run, including output. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the |
FileNotFoundError
|
If the manifest.yaml file cannot be found in the specified |
Examples:
>>> from nextmv.local import Application
>>> app = Application(id="my-app", src="/path/to/app")
>>> run_result = app.new_run_with_result(
... input={"vehicles": [{"id": "v1"}]},
... options={"duration": "10s"}
... )
>>> print(f"Local run completed with ID: {run_result.id}")
Source code in nextmv/nextmv/local/application.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
run_logs
¶
run_logs(run_id: str) -> str
Get the logs of a local run.
If the run does not have any logs, or they are empty, then this method
simply returns a blank string. This method is equivalent to fetching
the content of the .nextmv/runs/{run_id}/logs/logs.log file.
| PARAMETER | DESCRIPTION |
|---|---|
|
ID of the run to retrieve logs for.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The contents of the logs file for the run. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the |
Source code in nextmv/nextmv/local/application.py
run_metadata
¶
run_metadata(run_id: str) -> RunInformation
Get the metadata of a local run.
This method is the local equivalent to
cloud.Application.run_metadata, which retrieves the metadata of a
remote run in Nextmv Cloud. This method is used to get the metadata of
a run that was executed locally using the new_run or
new_run_with_result method.
Retrieves information about a run without including the run output. This is useful when you only need the run's status and metadata.
| PARAMETER | DESCRIPTION |
|---|---|
|
ID of the run to retrieve metadata for.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RunInformation
|
Metadata of the run (run information without output). |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the |
Examples:
>>> metadata = app.run_metadata("run-789")
>>> print(metadata.metadata.status_v2)
StatusV2.succeeded
Source code in nextmv/nextmv/local/application.py
run_result
¶
run_result(
run_id: str, output_dir_path: str | None = "."
) -> RunResult
Get the local result of a run.
This method is the local equivalent to cloud.Application.run_result,
which retrieves the result of a remote run in Nextmv Cloud. This method
is used to get the result of a run that was executed locally using the
new_run or new_run_with_result method.
Retrieves the complete result of a run, including the run output.
| PARAMETER | DESCRIPTION |
|---|---|
|
ID of the run to get results for.
TYPE:
|
|
Path to a directory where non-JSON output files will be saved. This is required if the output is non-JSON. If the directory does not exist, it will be created. Uses the current directory by default.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RunResult
|
Result of the run, including output. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the |
Examples:
Source code in nextmv/nextmv/local/application.py
run_result_with_polling
¶
run_result_with_polling(
run_id: str,
polling_options: PollingOptions = DEFAULT_POLLING_OPTIONS,
output_dir_path: str | None = ".",
) -> RunResult
Get the result of a local run with polling.
This method is the local equivalent to
cloud.Application.run_result_with_polling, which retrieves the result
of a remote run in Nextmv Cloud. This method is used to get the result
of a run that was executed locally using the new_run or
new_run_with_result method.
Retrieves the result of a run including the run output. This method polls for the result until the run finishes executing or the polling strategy is exhausted.
| PARAMETER | DESCRIPTION |
|---|---|
|
ID of the run to retrieve the result for.
TYPE:
|
|
Options to use when polling for the run result.
TYPE:
|
|
Path to a directory where non-JSON output files will be saved. This is required if the output is non-JSON. If the directory does not exist, it will be created. Uses the current directory by default.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RunResult
|
Complete result of the run including output data. |
| RAISES | DESCRIPTION |
|---|---|
HTTPError
|
If the response status code is not 2xx. |
TimeoutError
|
If the run does not complete after the polling strategy is exhausted based on time duration. |
RuntimeError
|
If the run does not complete after the polling strategy is exhausted based on number of tries. |
Examples:
>>> from nextmv.cloud import PollingOptions
>>> # Create custom polling options
>>> polling_opts = PollingOptions(max_tries=50, max_duration=600)
>>> # Get run result with polling
>>> result = app.run_result_with_polling("run-123", polling_opts)
>>> print(result.output)
{'solution': {...}}
Source code in nextmv/nextmv/local/application.py
run_visuals
¶
run_visuals(run_id: str) -> None
Open the local run visuals in a web browser.
This method opens the visual representation of a locally executed run
in the default web browser. It assumes that the run was executed locally
using the new_run or new_run_with_result method and that
the necessary visualization files are present.
If the run was correctly configured to produce visual assets, then the
run will contain a visuals directory with one or more HTML files.
Each file is opened in a new tab in the default web browser.
| PARAMETER | DESCRIPTION |
|---|---|
|
ID of the local run to visualize.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the |
Source code in nextmv/nextmv/local/application.py
src
instance-attribute
¶
Source of the application, when initialized locally. An application's
source typically refers to the directory containing the app.yaml
manifest.
sync
¶
sync(
target: Application,
run_ids: list[str] | None = None,
instance_id: str | None = None,
verbose: bool | None = False,
) -> None
Sync the local application to a Nextmv Cloud application target.
The Application class allows you to perform and handle local
application runs with methods such as:
new_runnew_run_with_resultrun_metadatarun_resultrun_result_with_polling
The runs produced locally live under self.src/.nextmv/runs. This
method syncs those runs to a Nextmv Cloud application target, making
them available for remote execution and management.
| PARAMETER | DESCRIPTION |
|---|---|
|
Target Nextmv Cloud application where the local application runs will be synced to.
TYPE:
|
|
List of run IDs to sync. If None, all local runs found under
TYPE:
|
|
Optional instance ID if you want to associate your runs with an instance.
TYPE:
|
|
Whether to print verbose output during the sync process. Useful for debugging a large number of runs being synced.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the |
ValueError
|
If the |
ValueError
|
If the application does not exist in Nextmv Cloud. |
ValueError
|
If a run does not exist locally. |
HTTPError
|
If the response status code is not 2xx. |
Source code in nextmv/nextmv/local/application.py
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 | |