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 |
---|---|
DownloadURL |
Result of getting a download URL. |
PollingOptions |
Options for polling when waiting for run results. |
UploadURL |
Result of getting an upload URL. |
Application |
Class for interacting with applications in Nextmv Cloud. |
FUNCTION | DESCRIPTION |
---|---|
poll |
Function to poll for results with configurable options. |
Application
dataclass
¶
Application(src: str, description: Optional[str] = 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: Optional[str] = None,
description: Optional[str] = None,
destination: Optional[str] = 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
new_run
¶
new_run(
input: Union[
Input, dict[str, Any], BaseModel, str
] = None,
name: Optional[str] = None,
description: Optional[str] = None,
options: Optional[
Union[Options, dict[str, str]]
] = None,
configuration: Optional[
Union[RunConfiguration, dict[str, Any]]
] = None,
json_configurations: Optional[dict[str, Any]] = None,
input_dir_path: Optional[str] = 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
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 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
|
new_run_with_result
¶
new_run_with_result(
input: Union[
Input, dict[str, Any], BaseModel, str
] = None,
name: Optional[str] = None,
description: Optional[str] = None,
run_options: Optional[
Union[Options, dict[str, str]]
] = None,
polling_options: PollingOptions = DEFAULT_POLLING_OPTIONS,
configuration: Optional[
Union[RunConfiguration, dict[str, Any]]
] = None,
json_configurations: Optional[dict[str, Any]] = None,
input_dir_path: Optional[str] = None,
output_dir_path: Optional[str] = ".",
) -> 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
511 512 513 514 515 516 517 518 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 |
|
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: Optional[str] = "."
) -> 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: Optional[str] = ".",
) -> 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: Optional[list[str]] = None,
instance_id: Optional[str] = None,
verbose: Optional[bool] = 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_run
new_run_with_result
run_metadata
run_result
run_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
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 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 743 744 745 746 747 748 |
|