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
¶
Bases: BaseModel
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")
-
nextmv
💻 Local
Reference
Application Module
applicationApplication
app_id
class-attribute
instance-attribute
¶
ID of the application. This ID is auto-generated if not provided.
content_format
class-attribute
instance-attribute
¶
The content format of the application, which is determined by the manifest.
description
class-attribute
instance-attribute
¶
Description of the application.
from_registry
classmethod
¶
from_registry(
src: str | None = None, app_id: str | None = None
) -> Application
Load an application from the local registry.
The local registry is a YAML file stored at $HOME/.nextmv/registry.yaml
that keeps track of locally registered applications. This method looks
for an entry in the local registry that matches the provided src or
app_id, and loads the application from the corresponding source path.
Specify either the src or the app_id to identify the application to
load. If both are provided, the method will prioritize loading by
app_id.
| PARAMETER | DESCRIPTION |
|---|---|
|
Source path of the application to load. This is typically the path
to the directory containing the application's manifest (
TYPE:
|
|
ID of the application to load. This ID is auto-generated if not provided during registration.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Application
|
The loaded application instance. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If neither |
Examples:
Assuming an application is registered in the local registry with the following entry:
>>> from nextmv.local import Application
>>> app = Application.from_registry(app_id="app-123")
>>> print(app.src)
/path/to/app
Source code in nextmv/nextmv/local/application.py
get_or_register
classmethod
¶
get_or_register(
app_src: str, app_id: str | None = None
) -> tuple[Application, bool]
Get a local application from the registry or register it if it does not exist.
This function checks if a local application with the given source and
ID is already registered in the local registry. If it is, it retrieves
and returns that application. If it is not registered, it creates a new
Application instance with the provided source and ID, registers it in
the local registry, and then returns it. The boolean in the returned
tuple indicates whether a new application was registered (True) or an
existing one was retrieved (False).
| PARAMETER | DESCRIPTION |
|---|---|
|
The source path of the application to get or register.
TYPE:
|
|
The ID of the application to get or register. If None, the ID will be derived from the application source.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Application, bool]
|
A tuple containing the local application retrieved from the registry or newly registered, and a boolean indicating whether the application was newly registered. |
Source code in nextmv/nextmv/local/application.py
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
is_registered
¶
Check if the local application is registered in the local registry.
This method checks if the application has an entry in the local registry.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the application is registered, False otherwise. |
Source code in nextmv/nextmv/local/application.py
list_runs
¶
list_runs(status: StatusV2 | None = None) -> list[Run]
List all runs for the application.
| PARAMETER | DESCRIPTION |
|---|---|
|
If specified, only runs with the given status will be returned.
TYPE:
|
| 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 you
specify this argument when creating the Application, the provided manifest
will be written to the src directory, overriding any existing manifest
file.
model_post_init
¶
Actions taken after the Application model is initialized.
Source code in nextmv/nextmv/local/application.py
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
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 app.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
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 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | |
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
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 app.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
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |
register
¶
Register the local application in the local registry.
This method adds an entry for the application in the local registry,
which is stored as a YAML file at $HOME/.nextmv/registry.yaml. The
registry keeps track of locally registered applications, allowing you
to manage and list them easily.
If the application is already registered, this method does nothing.
Source code in nextmv/nextmv/local/application.py
run_input
¶
run_input(
run_id: str, output_dir_path: str | None = "."
) -> dict[str, Any] | str | None
Get the input of a local run.
This method retrieves the input of a run that was executed locally
using the new_run or new_run_with_result method. This is the local
equivalent to cloud.Application.run_input, which retrieves the input
of a remote run in Nextmv Cloud.
| PARAMETER | DESCRIPTION |
|---|---|
|
ID of the run to retrieve input for.
TYPE:
|
|
Path to a directory where non-JSON input files will be saved. This is required if the input is non-JSON. If the directory does not exist, it will be created. Uses the current directory by default.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any] | str | None
|
The input of the run depending on the input format. If the input
format is JSON, a dict is returned. If the input format is text, a
string is returned. For multi-file and csv-archive, the input files
are saved to the given |
Source code in nextmv/nextmv/local/application.py
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | |
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) -> list[str]
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:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
The local URLs of the visual files that were opened in the web browser. |
| 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,
rich_print: 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:
|
|
Whether to use rich printing for output during the sync process.
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
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 | |
update
¶
update(
app_id: str | None = None,
description: str | None = None,
content_format: InputFormat | None = None,
) -> None
Update the local application.
This method allows you to update the local application's metadata, such as its app_id, description and content format. It does not affect the application's source code or runs.
| PARAMETER | DESCRIPTION |
|---|---|
|
New app_id for the application. If None, the app_id is not updated.
TYPE:
|
|
New description for the application. If None, the description is not updated.
TYPE:
|
|
New content format for the application. If None, the content format is not updated.
TYPE:
|