Application Module¶
This section documents the application components of the Nextmv Cloud API.
application
¶
Application module for interacting with Nextmv Cloud applications.
This module provides functionality to interact with applications in Nextmv Cloud, including application management, running applications, and managing experiments and 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(
client: Client,
id: str,
default_instance_id: str = None,
endpoint: str = "v1/applications/{id}",
experiments_endpoint: str = "{base}/experiments",
src: Optional[str] = None,
description: Optional[str] = None,
)
A published decision model that can be executed.
You can import the Application
class directly from cloud
:
This class represents an application in Nextmv Cloud, providing methods to interact with the application, run it with different inputs, manage versions, instances, experiments, and more.
PARAMETER | DESCRIPTION |
---|---|
|
Client to use for interacting with the Nextmv Cloud API.
TYPE:
|
|
ID of the application.
TYPE:
|
|
Default instance ID to use for submitting runs.
TYPE:
|
|
Base endpoint for the application.
TYPE:
|
|
Base endpoint for the experiments in the application.
TYPE:
|
Examples:
>>> from nextmv.cloud import Client, Application
>>> client = Client(api_key="your-api-key")
>>> app = Application(client=client, id="your-app-id")
>>> # Retrieve app information
>>> instances = app.list_instances()
acceptance_test
¶
acceptance_test(acceptance_test_id: str) -> AcceptanceTest
Retrieve details of an acceptance test.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the acceptance test to retrieve.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AcceptanceTest
|
The requested acceptance test details. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
Source code in nextmv/nextmv/cloud/application.py
acceptance_test_with_polling
¶
acceptance_test_with_polling(
acceptance_test_id: str,
polling_options: PollingOptions = _DEFAULT_POLLING_OPTIONS,
) -> AcceptanceTest
Retrieve details of an acceptance test using polling.
Retrieves the result of an acceptance test. This method polls for the result until the test finishes executing or the polling strategy is exhausted.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the acceptance test to retrieve.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AcceptanceTest
|
The requested acceptance test details. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
Source code in nextmv/nextmv/cloud/application.py
batch_experiment
¶
batch_experiment(batch_id: str) -> BatchExperiment
Get a batch experiment.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the batch experiment.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BatchExperiment
|
The requested batch experiment details. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
Source code in nextmv/nextmv/cloud/application.py
batch_experiment_metadata
¶
batch_experiment_metadata(
batch_id: str,
) -> BatchExperimentMetadata
Get metadata for a batch experiment.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the batch experiment.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BatchExperimentMetadata
|
The requested batch experiment metadata. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> metadata = app.batch_experiment_metadata("batch-123")
>>> print(metadata.name)
'My Batch Experiment'
Source code in nextmv/nextmv/cloud/application.py
batch_experiment_with_polling
¶
batch_experiment_with_polling(
batch_id: str,
polling_options: PollingOptions = _DEFAULT_POLLING_OPTIONS,
) -> BatchExperiment
Get a batch experiment with polling.
Retrieves the result of an experiment. This method polls for the result until the experiment finishes executing or the polling strategy is exhausted.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the batch experiment.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BatchExperiment
|
The requested batch experiment details. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> batch_exp = app.batch_experiment_with_polling("batch-123")
>>> print(batch_exp.name)
'My Batch Experiment'
Source code in nextmv/nextmv/cloud/application.py
cancel_run
¶
cancel_run(run_id: str) -> None
Cancel a run.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the run to cancel.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
Source code in nextmv/nextmv/cloud/application.py
default_instance_id
class-attribute
instance-attribute
¶
Default instance ID to use for submitting runs.
delete
¶
Delete the application.
Permanently removes the application from Nextmv Cloud.
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
Source code in nextmv/nextmv/cloud/application.py
delete_acceptance_test
¶
delete_acceptance_test(acceptance_test_id: str) -> None
Delete an acceptance test.
Deletes an acceptance test along with all the associated information such as the underlying batch experiment.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the acceptance test to delete.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
Source code in nextmv/nextmv/cloud/application.py
delete_batch_experiment
¶
delete_batch_experiment(batch_id: str) -> None
Delete a batch experiment.
Deletes a batch experiment along with all the associated information, such as its runs.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the batch experiment to delete.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
Source code in nextmv/nextmv/cloud/application.py
delete_scenario_test
¶
delete_scenario_test(scenario_test_id: str) -> None
Delete a scenario test.
Deletes a scenario test. Scenario tests are based on the batch
experiments API, so this function summons delete_batch_experiment
.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the scenario test to delete.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
Source code in nextmv/nextmv/cloud/application.py
delete_secrets_collection
¶
delete_secrets_collection(
secrets_collection_id: str,
) -> None
Delete a secrets collection.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the secrets collection to delete.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
Source code in nextmv/nextmv/cloud/application.py
description
class-attribute
instance-attribute
¶
Description of the application.
endpoint
class-attribute
instance-attribute
¶
Base endpoint for the application.
exists
staticmethod
¶
Check if an application exists.
PARAMETER | DESCRIPTION |
---|---|
|
Client to use for interacting with the Nextmv Cloud API.
TYPE:
|
|
ID of the application to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the application exists, False otherwise. |
Examples:
>>> from nextmv.cloud import Client
>>> client = Client(api_key="your-api-key")
>>> Application.exists(client, "app-123")
True
Source code in nextmv/nextmv/cloud/application.py
experiments_endpoint
class-attribute
instance-attribute
¶
Base endpoint for the experiments in the application.
initialize
classmethod
¶
initialize(
name: str,
id: Optional[str] = None,
description: Optional[str] = None,
destination: Optional[str] = None,
client: Optional[Client] = None,
) -> Application
Initialize a Nextmv application, locally.
This method will create a new application in the local file system. The
application is a folder with the name given by name
, 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 or remotely.
This method differs from the Application.new
method in that it
creates the application locally rather than in the Cloud.
Although not required, you are encouraged to specify the client
parameter, so that the application can be pushed and synced remotely,
with the Nextmv Cloud. If you don't specify the client
, and intend to
interact with the Nextmv Cloud, you will encounter an error. Make sure
you set the client
parameter on the Application
instance after
initialization, if you don't provide it here.
Use the destination
parameter to specify where you want the app to be
initialized, using the current working directory by default.
PARAMETER | DESCRIPTION |
---|---|
|
Name of the application.
TYPE:
|
|
ID 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:
|
|
Client to use for interacting with the Nextmv Cloud API.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Application
|
The initialized application instance. |
Source code in nextmv/nextmv/cloud/application.py
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 361 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 |
|
input_set
¶
input_set(input_set_id: str) -> InputSet
Get an input set.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the input set to retrieve.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
InputSet
|
The requested input set. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
Source code in nextmv/nextmv/cloud/application.py
instance
¶
instance(instance_id: str) -> Instance
Get an instance.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the instance to retrieve.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Instance
|
The requested instance details. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
Source code in nextmv/nextmv/cloud/application.py
instance_exists
¶
instance_exists(instance_id: str) -> bool
Check if an instance exists.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the instance to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the instance exists, False otherwise. |
Examples:
Source code in nextmv/nextmv/cloud/application.py
list_acceptance_tests
¶
List all acceptance tests.
RETURNS | DESCRIPTION |
---|---|
list[AcceptanceTest]
|
List of all acceptance tests associated with this application. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> tests = app.list_acceptance_tests()
>>> for test in tests:
... print(test.name)
'Test 1'
'Test 2'
Source code in nextmv/nextmv/cloud/application.py
list_batch_experiments
¶
List all batch experiments.
RETURNS | DESCRIPTION |
---|---|
list[BatchExperimentMetadata]
|
List of batch experiments. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Source code in nextmv/nextmv/cloud/application.py
list_input_sets
¶
List all input sets.
RETURNS | DESCRIPTION |
---|---|
list[InputSet]
|
List of all input sets associated with this application. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> input_sets = app.list_input_sets()
>>> for input_set in input_sets:
... print(input_set.name)
'Input Set 1'
'Input Set 2'
Source code in nextmv/nextmv/cloud/application.py
list_instances
¶
List all instances.
RETURNS | DESCRIPTION |
---|---|
list[Instance]
|
List of all instances associated with this application. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> instances = app.list_instances()
>>> for instance in instances:
... print(instance.name)
'Development Instance'
'Production Instance'
Source code in nextmv/nextmv/cloud/application.py
list_managed_inputs
¶
List all managed inputs.
RETURNS | DESCRIPTION |
---|---|
list[ManagedInput]
|
List of managed inputs. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Source code in nextmv/nextmv/cloud/application.py
list_scenario_tests
¶
List all batch scenario tests. Scenario tests are based on the batch
experiments API, so this function returns the same information as
list_batch_experiments
, albeit using a different query parameter.
RETURNS | DESCRIPTION |
---|---|
list[BatchExperimentMetadata]
|
List of scenario tests. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Source code in nextmv/nextmv/cloud/application.py
list_secrets_collections
¶
List all secrets collections.
RETURNS | DESCRIPTION |
---|---|
list[SecretsCollectionSummary]
|
List of all secrets collections associated with this application. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> collections = app.list_secrets_collections()
>>> for collection in collections:
... print(collection.name)
'API Keys'
'Database Credentials'
Source code in nextmv/nextmv/cloud/application.py
list_versions
¶
List all versions.
RETURNS | DESCRIPTION |
---|---|
list[Version]
|
List of all versions associated with this application. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> versions = app.list_versions()
>>> for version in versions:
... print(version.name)
'v1.0.0'
'v1.1.0'
Source code in nextmv/nextmv/cloud/application.py
managed_input
¶
managed_input(managed_input_id: str) -> ManagedInput
Get a managed input.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the managed input.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ManagedInput
|
The managed input. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Source code in nextmv/nextmv/cloud/application.py
new
classmethod
¶
new(
client: Client,
name: str,
id: Optional[str] = None,
description: Optional[str] = None,
is_workflow: Optional[bool] = None,
exist_ok: bool = False,
) -> Application
Create a new application directly in Nextmv Cloud.
The application is created as an empty shell, and executable code must be pushed to the app before running it remotely.
PARAMETER | DESCRIPTION |
---|---|
|
Client to use for interacting with the Nextmv Cloud API.
TYPE:
|
|
Name of the application.
TYPE:
|
|
ID of the application. Will be generated if not provided.
TYPE:
|
|
Description of the application.
TYPE:
|
|
Whether the application is a Decision Workflow.
TYPE:
|
|
If True and an application with the same ID already exists, return the existing application instead of creating a new one.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Application
|
The newly created (or existing) application. |
Examples:
>>> from nextmv.cloud import Client
>>> client = Client(api_key="your-api-key")
>>> app = Application.new(client=client, name="My New App", id="my-app")
Source code in nextmv/nextmv/cloud/application.py
new_acceptance_test
¶
new_acceptance_test(
candidate_instance_id: str,
baseline_instance_id: str,
id: str,
metrics: list[Union[Metric, dict[str, Any]]],
name: str,
input_set_id: Optional[str] = None,
description: Optional[str] = None,
) -> AcceptanceTest
Create a new acceptance test.
The acceptance test is based on a batch experiment. If you already started a batch experiment, you don't need to provide the input_set_id parameter. In that case, the ID of the acceptance test and the batch experiment must be the same. If the batch experiment does not exist, you can provide the input_set_id parameter and a new batch experiment will be created for you.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the candidate instance.
TYPE:
|
|
ID of the baseline instance.
TYPE:
|
|
ID of the acceptance test.
TYPE:
|
|
List of metrics to use for the acceptance test.
TYPE:
|
|
Name of the acceptance test.
TYPE:
|
|
ID of the input set to use for the underlying batch experiment, in case it hasn't been started.
TYPE:
|
|
Description of the acceptance test.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AcceptanceTest
|
The created acceptance test. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
ValueError
|
If the batch experiment ID does not match the acceptance test ID. |
Source code in nextmv/nextmv/cloud/application.py
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 |
|
new_acceptance_test_with_result
¶
new_acceptance_test_with_result(
candidate_instance_id: str,
baseline_instance_id: str,
id: str,
metrics: list[Union[Metric, dict[str, Any]]],
name: str,
input_set_id: Optional[str] = None,
description: Optional[str] = None,
polling_options: PollingOptions = _DEFAULT_POLLING_OPTIONS,
) -> AcceptanceTest
Create a new acceptance test and poll for the result.
This is a convenience method that combines the new_acceptance_test with polling logic to check when the acceptance test is done.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the candidate instance.
TYPE:
|
|
ID of the baseline instance.
TYPE:
|
|
ID of the acceptance test.
TYPE:
|
|
List of metrics to use for the acceptance test.
TYPE:
|
|
Name of the acceptance test.
TYPE:
|
|
ID of the input set to use for the underlying batch experiment, in case it hasn't been started.
TYPE:
|
|
Description of the acceptance test.
TYPE:
|
|
Options to use when polling for the acceptance test result.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AcceptanceTest
|
The completed acceptance test with results. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
TimeoutError
|
If the acceptance test does not succeed after the polling strategy is exhausted based on time duration. |
RuntimeError
|
If the acceptance test does not succeed after the polling strategy is exhausted based on number of tries. |
Examples:
>>> test = app.new_acceptance_test_with_result(
... candidate_instance_id="candidate-123",
... baseline_instance_id="baseline-456",
... id="test-789",
... metrics=[Metric(name="objective", type="numeric")],
... name="Performance Test",
... input_set_id="input-set-123"
... )
>>> print(test.status)
'completed'
Source code in nextmv/nextmv/cloud/application.py
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 |
|
new_batch_experiment
¶
new_batch_experiment(
name: str,
input_set_id: Optional[str] = None,
instance_ids: Optional[list[str]] = None,
description: Optional[str] = None,
id: Optional[str] = None,
option_sets: Optional[dict[str, dict[str, str]]] = None,
runs: Optional[
list[Union[BatchExperimentRun, dict[str, Any]]]
] = None,
type: Optional[str] = "batch",
) -> str
Create a new batch experiment.
PARAMETER | DESCRIPTION |
---|---|
|
Name of the batch experiment.
TYPE:
|
|
ID of the input set to use for the batch experiment.
TYPE:
|
|
List of instance IDs to use for the batch experiment.
This argument is deprecated, use
TYPE:
|
|
Optional description of the batch experiment.
TYPE:
|
|
ID of the batch experiment. Will be generated if not provided.
TYPE:
|
|
Option sets to use for the batch experiment. This is a dictionary where the keys are option set IDs and the values are dictionaries with the actual options.
TYPE:
|
|
List of runs to use for the batch experiment.
TYPE:
|
|
Type of the batch experiment. This is used to determine the experiment type. The default value is "batch". If you want to create a scenario test, set this to "scenario".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
ID of the batch experiment. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Source code in nextmv/nextmv/cloud/application.py
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 |
|
new_batch_experiment_with_result
¶
new_batch_experiment_with_result(
name: str,
input_set_id: Optional[str] = None,
instance_ids: Optional[list[str]] = None,
description: Optional[str] = None,
id: Optional[str] = None,
option_sets: Optional[dict[str, dict[str, str]]] = None,
runs: Optional[
list[Union[BatchExperimentRun, dict[str, Any]]]
] = None,
type: Optional[str] = "batch",
polling_options: PollingOptions = _DEFAULT_POLLING_OPTIONS,
) -> BatchExperiment
Convenience method to create a new batch experiment and poll for the result.
This method combines the new_batch_experiment
and
batch_experiment_with_polling
methods, applying polling logic to
check when the experiment succeeded.
PARAMETER | DESCRIPTION |
---|---|
|
Name of the batch experiment.
TYPE:
|
|
ID of the input set to use for the batch experiment.
TYPE:
|
|
List of instance IDs to use for the batch experiment. This argument
is deprecated, use
TYPE:
|
|
Optional description of the batch experiment.
TYPE:
|
|
ID of the batch experiment. Will be generated if not provided.
TYPE:
|
|
Option sets to use for the batch experiment. This is a dictionary where the keys are option set IDs and the values are dictionaries with the actual options.
TYPE:
|
|
List of runs to use for the batch experiment.
TYPE:
|
|
Type of the batch experiment. This is used to determine the experiment type. The default value is "batch". If you want to create a scenario test, set this to "scenario".
TYPE:
|
|
Options to use when polling for the batch experiment result.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BatchExperiment
|
The completed batch experiment with results. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Source code in nextmv/nextmv/cloud/application.py
1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 |
|
new_input_set
¶
new_input_set(
id: str,
name: str,
description: Optional[str] = None,
end_time: Optional[datetime] = None,
instance_id: Optional[str] = None,
maximum_runs: Optional[int] = None,
run_ids: Optional[list[str]] = None,
start_time: Optional[datetime] = None,
inputs: Optional[list[ManagedInput]] = None,
) -> InputSet
Create a new input set. You can create an input set from three different methodologies:
- Using
instance_id
,start_time
,end_time
andmaximum_runs
. Instance runs will be obtained from the application matching the criteria of dates and maximum number of runs. - Using
run_ids
. The input set will be created using the list of runs specified by the user. - Using
inputs
. The input set will be created using the list of inputs specified by the user. This is useful for creating an input set from a list of inputs that are already available in the application.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the input set
TYPE:
|
|
Name of the input set.
TYPE:
|
|
Optional description of the input set.
TYPE:
|
|
End time of the input set. This is used to filter the runs associated with the input set.
TYPE:
|
|
ID of the instance to use for the input set. This is used to
filter the runs associated with the input set. If not provided,
the application's
TYPE:
|
|
Maximum number of runs to use for the input set. This is used to filter the runs associated with the input set. If not provided, all runs are used.
TYPE:
|
|
List of run IDs to use for the input set.
TYPE:
|
|
Start time of the input set. This is used to filter the runs associated with the input set.
TYPE:
|
|
List of inputs to use for the input set. This is used to create the input set from a list of inputs that are already available in the application.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
InputSet
|
The new input set. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Source code in nextmv/nextmv/cloud/application.py
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 |
|
new_instance
¶
new_instance(
version_id: str,
id: str,
name: str,
description: Optional[str] = None,
configuration: Optional[InstanceConfiguration] = None,
exist_ok: bool = False,
) -> Instance
Create a new instance and associate it with a version.
This method creates a new instance associated with a specific version of the application. Instances are configurations of an application version that can be executed.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the version to associate the instance with.
TYPE:
|
|
ID of the instance. Will be generated if not provided.
TYPE:
|
|
Name of the instance. Will be generated if not provided.
TYPE:
|
|
Description of the instance.
TYPE:
|
|
Configuration to use for the instance. This can include resources, timeouts, and other execution parameters.
TYPE:
|
|
If True and an instance with the same ID already exists, return the existing instance instead of creating a new one.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Instance
|
The newly created (or existing) instance. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
ValueError
|
If exist_ok is True and id is None. |
Examples:
>>> # Create a new instance for a specific version
>>> instance = app.new_instance(
... version_id="version-123",
... id="prod-instance",
... name="Production Instance",
... description="Instance for production use"
... )
>>> print(instance.name)
'Production Instance'
Source code in nextmv/nextmv/cloud/application.py
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 |
|
new_managed_input
¶
new_managed_input(
id: str,
name: str,
description: Optional[str] = None,
upload_id: Optional[str] = None,
run_id: Optional[str] = None,
format: Optional[Union[Format, dict[str, Any]]] = None,
) -> ManagedInput
Create a new managed input. There are two methods for creating a managed input:
- Specifying the
upload_id
parameter. You may use theupload_url
method to obtain the upload ID and theupload_large_input
method to upload the data to it. - Specifying the
run_id
parameter. The managed input will be created from the run specified by therun_id
parameter.
Either the upload_id
or the run_id
parameter must be specified.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the managed input.
TYPE:
|
|
Name of the managed input.
TYPE:
|
|
Optional description of the managed input.
TYPE:
|
|
ID of the upload to use for the managed input.
TYPE:
|
|
ID of the run to use for the managed input.
TYPE:
|
|
Format of the managed input. Default will be formatted as
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ManagedInput
|
The new managed input. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
ValueError
|
If neither the |
Source code in nextmv/nextmv/cloud/application.py
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 |
|
new_run
¶
new_run(
input: Union[
Input, dict[str, Any], BaseModel, str
] = None,
instance_id: Optional[str] = None,
name: Optional[str] = None,
description: Optional[str] = None,
upload_id: Optional[str] = None,
options: Optional[
Union[Options, dict[str, str]]
] = None,
configuration: Optional[
Union[RunConfiguration, dict[str, Any]]
] = None,
batch_experiment_id: Optional[str] = None,
external_result: Optional[
Union[ExternalRunResult, dict[str, Any]]
] = None,
json_configurations: Optional[dict[str, Any]] = None,
input_dir_path: Optional[str] = None,
) -> str
Submit an input to start a new run of the application. Returns the
run_id
of the submitted run.
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:
|
|
ID of the instance to use for the run. If not provided, the default
instance ID associated to the Class (
TYPE:
|
|
Name of the run.
TYPE:
|
|
Description of the run.
TYPE:
|
|
ID to use when running a large input. If the
TYPE:
|
|
Options to use for the run. This can be a
TYPE:
|
|
Configuration to use for the run. This can be a
TYPE:
|
|
ID of a batch experiment to associate the run with. This is used when the run is part of a batch experiment.
TYPE:
|
|
External result 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. If specified, the
function will package the files in the directory into a tar file
and upload it as a large input. This is useful for input formats
like
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
ID ( |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
ValueError
|
If the |
Source code in nextmv/nextmv/cloud/application.py
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 |
|
new_run_with_result
¶
new_run_with_result(
input: Union[
Input, dict[str, Any], BaseModel, str
] = None,
instance_id: Optional[str] = None,
name: Optional[str] = None,
description: Optional[str] = None,
upload_id: 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,
batch_experiment_id: Optional[str] = None,
external_result: Optional[
Union[ExternalRunResult, 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 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 run succeeded.
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:
|
|
ID of the instance to use for the run. If not provided, the default
instance ID associated to the Class (
TYPE:
|
|
Name of the run.
TYPE:
|
|
Description of the run.
TYPE:
|
|
ID to use when running a large input. If the
TYPE:
|
|
Options to use for the run. This can be a
TYPE:
|
|
Options to use when polling for the run result. This is a
convenience method that combines the
TYPE:
|
|
Configuration to use for the run. This can be a
TYPE:
|
|
ID of a batch experiment to associate the run with. This is used when the run is part of a batch experiment.
TYPE:
|
|
External result 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. If specified, the
function will package the files in the directory into a tar file
and upload it as a large input. 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. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the |
HTTPError
|
If the response status code is not 2xx. |
TimeoutError
|
If the run does not succeed after the polling strategy is exhausted based on time duration. |
RuntimeError
|
If the run does not succeed after the polling strategy is exhausted based on number of tries. |
Source code in nextmv/nextmv/cloud/application.py
2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 |
|
new_scenario_test
¶
new_scenario_test(
id: str,
name: str,
scenarios: list[Scenario],
description: Optional[str] = None,
repetitions: Optional[int] = 0,
) -> str
Create a new scenario test. The test is based on scenarios
and you
may specify repetitions
to run the test multiple times. 0 repetitions
means that the tests will be executed once. 1 repetition means that the
test will be repeated once, i.e.: it will be executed twice. 2
repetitions equals 3 executions, so on, and so forth.
For each scenario, consider the scenario_input
and configuration
.
The scenario_input.scenario_input_type
allows you to specify the data
that will be used for that scenario.
ScenarioInputType.INPUT_SET
: the data should be taken from an existing input set.ScenarioInputType.INPUT
: the data should be taken from a list of existing inputs. When using this type, an input set will be created from this set of managed inputs.ScenarioInputType.New
: a new set of data will be uploaded as a set of managed inputs. A new input set will be created from this set of managed inputs.
On the other hand, the configuration
allows you to specify multiple
option variations for the scenario. Please see the
ScenarioConfiguration
class for more information.
The scenario tests uses the batch experiments API under the hood.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the scenario test.
TYPE:
|
|
Name of the scenario test.
TYPE:
|
|
List of scenarios to use for the scenario test. At least one scenario should be provided.
TYPE:
|
|
Optional description of the scenario test.
TYPE:
|
|
Number of repetitions to use for the scenario test. 0 repetitions means that the tests will be executed once. 1 repetition means that the test will be repeated once, i.e.: it will be executed twice. 2 repetitions equals 3 executions, so on, and so forth.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
ID of the scenario test. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
ValueError
|
If no scenarios are provided. |
Source code in nextmv/nextmv/cloud/application.py
2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 |
|
new_scenario_test_with_result
¶
new_scenario_test_with_result(
id: str,
name: str,
scenarios: list[Scenario],
description: Optional[str] = None,
repetitions: Optional[int] = 0,
polling_options: PollingOptions = _DEFAULT_POLLING_OPTIONS,
) -> BatchExperiment
Convenience method to create a new scenario test and poll for the result.
This method combines the new_scenario_test
and
scenario_test_with_polling
methods, applying polling logic to
check when the test succeeded.
The scenario tests uses the batch experiments API under the hood.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the scenario test.
TYPE:
|
|
Name of the scenario test.
TYPE:
|
|
List of scenarios to use for the scenario test. At least one scenario should be provided.
TYPE:
|
|
Optional description of the scenario test.
TYPE:
|
|
Number of repetitions to use for the scenario test. 0 repetitions means that the tests will be executed once. 1 repetition means that the test will be repeated once, i.e.: it will be executed twice. 2 repetitions equals 3 executions, so on, and so forth.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BatchExperiment
|
The completed scenario test as a BatchExperiment. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
ValueError
|
If no scenarios are provided. |
Source code in nextmv/nextmv/cloud/application.py
2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 |
|
new_secrets_collection
¶
new_secrets_collection(
secrets: list[Secret],
id: str,
name: str,
description: Optional[str] = None,
) -> SecretsCollectionSummary
Create a new secrets collection.
This method creates a new secrets collection with the provided secrets. A secrets collection is a group of key-value pairs that can be used by your application instances during execution. If no secrets are provided, a ValueError is raised.
PARAMETER | DESCRIPTION |
---|---|
|
List of secrets to use for the secrets collection. Each secret should be an instance of the Secret class containing a key and value.
TYPE:
|
|
ID of the secrets collection.
TYPE:
|
|
Name of the secrets collection.
TYPE:
|
|
Description of the secrets collection.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SecretsCollectionSummary
|
Summary of the secrets collection including its metadata. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If no secrets are provided. |
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> # Create a new secrets collection with API keys
>>> from nextmv.cloud import Secret
>>> secrets = [
... Secret(
... location="API_KEY",
... value="your-api-key",
... secret_type=SecretType.ENV,
... ),
... Secret(
... location="DATABASE_URL",
... value="your-database-url",
... secret_type=SecretType.ENV,
... ),
... ]
>>> collection = app.new_secrets_collection(
... secrets=secrets,
... id="api-secrets",
... name="API Secrets",
... description="Collection of API secrets for external services"
... )
>>> print(collection.id)
'api-secrets'
Source code in nextmv/nextmv/cloud/application.py
2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 |
|
new_version
¶
new_version(
id: Optional[str] = None,
name: Optional[str] = None,
description: Optional[str] = None,
exist_ok: bool = False,
) -> Version
Create a new version using the current dev binary.
This method creates a new version of the application using the current development binary. Application versions represent different iterations of your application's code and configuration that can be deployed.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the version. If not provided, a unique ID will be generated.
TYPE:
|
|
Name of the version. If not provided, a name will be generated.
TYPE:
|
|
Description of the version. If not provided, a description will be generated.
TYPE:
|
|
If True and a version with the same ID already exists, return the existing version instead of creating a new one. If True, the 'id' parameter must be provided.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Version
|
The newly created (or existing) version. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If exist_ok is True and id is None. |
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> # Create a new version
>>> version = app.new_version(
... id="v1.0.0",
... name="Initial Release",
... description="First stable version"
... )
>>> print(version.id)
'v1.0.0'
>>> # Get or create a version with exist_ok
>>> version = app.new_version(
... id="v1.0.0",
... exist_ok=True
... )
Source code in nextmv/nextmv/cloud/application.py
2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 |
|
push
¶
push(
manifest: Optional[Manifest] = None,
app_dir: Optional[str] = None,
verbose: bool = False,
model: Optional[Model] = None,
model_configuration: Optional[
ModelConfiguration
] = None,
) -> None
Push an app to Nextmv Cloud.
If the manifest is not provided, an app.yaml
file will be searched
for in the provided path. If there is no manifest file found, an
exception will be raised.
There are two ways to push an app to Nextmv Cloud:
1. Specifying app_dir
, which is the path to an app's root directory.
This acts as an external strategy, where the app is composed of files
in a directory and those apps are packaged and pushed to Nextmv Cloud.
2. Specifying a model
and model_configuration
. This acts as an
internal (or Python-native) strategy, where the app is actually a
nextmv.Model
. The model is encoded, some dependencies and
accompanying files are packaged, and the app is pushed to Nextmv Cloud.
PARAMETER | DESCRIPTION |
---|---|
|
The manifest for the app. If None, an
TYPE:
|
|
The path to the app's root directory. If None, the current directory will be used. This is for the external strategy approach.
TYPE:
|
|
Whether to print verbose output during the push process.
TYPE:
|
|
The Python-native model to push. Must be specified together with
TYPE:
|
|
Configuration for the Python-native model. Must be specified together
with
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If neither app_dir nor model/model_configuration is provided correctly, or if only one of model and model_configuration is provided. |
TypeError
|
If model is not an instance of nextmv.Model or if model_configuration is not an instance of nextmv.ModelConfiguration. |
Exception
|
If there's an error in the build, packaging, or cleanup process. |
Examples:
- Push an app using an external strategy (directory-based):
>>> import os
>>> from nextmv import cloud
>>> client = cloud.Client(api_key=os.getenv("NEXTMV_API_KEY"))
>>> app = cloud.Application(client=client, id="<YOUR-APP-ID>")
>>> app.push() # Use verbose=True for step-by-step output.
- Push an app using an internal strategy (Python-native model):
>>> import os
>>> import nextroute
>>> import nextmv
>>> import nextmv.cloud
>>>
>>> # Define the model that makes decisions
>>> class DecisionModel(nextmv.Model):
... def solve(self, input: nextmv.Input) -> nextmv.Output:
... nextroute_input = nextroute.schema.Input.from_dict(input.data)
... nextroute_options = nextroute.Options.extract_from_dict(input.options.to_dict())
... nextroute_output = nextroute.solve(nextroute_input, nextroute_options)
...
... return nextmv.Output(
... options=input.options,
... solution=nextroute_output.solutions[0].to_dict(),
... statistics=nextroute_output.statistics.to_dict(),
... )
>>>
>>> # Define the options that the model needs
>>> opt = []
>>> default_options = nextroute.Options()
>>> for name, default_value in default_options.to_dict().items():
... opt.append(nextmv.Option(name.lower(), type(default_value), default_value, name, False))
>>> options = nextmv.Options(*opt)
>>>
>>> # Instantiate the model and model configuration
>>> model = DecisionModel()
>>> model_configuration = nextmv.ModelConfiguration(
... name="python_nextroute_model",
... requirements=[
... "nextroute==1.8.1",
... "nextmv==0.14.0.dev1",
... ],
... options=options,
... )
>>>
>>> # Push the model to Nextmv Cloud
>>> client = cloud.Client(api_key=os.getenv("NEXTMV_API_KEY"))
>>> app = cloud.Application(client=client, id="<YOUR-APP-ID>")
>>> manifest = nextmv.cloud.default_python_manifest()
>>> app.push(
... manifest=manifest,
... verbose=True,
... model=model,
... model_configuration=model_configuration,
... )
Source code in nextmv/nextmv/cloud/application.py
2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 |
|
run_input
¶
run_input(run_id: str) -> dict[str, Any]
Get the input of a run.
Retrieves the input data that was used for a specific run. This method handles both small and large inputs automatically - if the input size exceeds the maximum allowed size, it will fetch the input from a download URL.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the run to retrieve the input for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict[str, Any]
|
Input data of the run as a dictionary. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> input_data = app.run_input("run-123")
>>> print(input_data)
{'locations': [...], 'vehicles': [...]}
Source code in nextmv/nextmv/cloud/application.py
run_logs
¶
run_logs(run_id: str) -> RunLog
Get the logs of a run.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the run to get logs for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
RunLog
|
Logs of the run. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
Source code in nextmv/nextmv/cloud/application.py
run_metadata
¶
run_metadata(run_id: str) -> RunInformation
Get the metadata of a run.
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 |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> metadata = app.run_metadata("run-123")
>>> print(metadata.metadata.status_v2)
StatusV2.succeeded
Source code in nextmv/nextmv/cloud/application.py
run_result
¶
run_result(
run_id: str, output_dir_path: Optional[str] = "."
) -> RunResult
Get the result of a run.
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 |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
Source code in nextmv/nextmv/cloud/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 run with polling.
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/cloud/application.py
2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 |
|
scenario_test
¶
scenario_test(scenario_test_id: str) -> BatchExperiment
Get a scenario test.
Retrieves a scenario test by ID. Scenario tests are based on batch experiments, so this function returns the corresponding batch experiment associated with the scenario test.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the scenario test to retrieve.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BatchExperiment
|
The scenario test details as a batch experiment. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> test = app.scenario_test("scenario-123")
>>> print(test.name)
'My Scenario Test'
>>> print(test.type)
'scenario'
Source code in nextmv/nextmv/cloud/application.py
scenario_test_metadata
¶
scenario_test_metadata(
scenario_test_id: str,
) -> BatchExperimentMetadata
Get the metadata for a scenario test, given its ID.
Scenario tests are based on batch experiments, so this function returns the corresponding batch experiment metadata associated with the scenario test.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the scenario test to retrieve.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BatchExperimentMetadata
|
The scenario test metadata as a batch experiment. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> metadata = app.scenario_test_metadata("scenario-123")
>>> print(metadata.name)
'My Scenario Test'
>>> print(metadata.type)
'scenario'
Source code in nextmv/nextmv/cloud/application.py
scenario_test_with_polling
¶
scenario_test_with_polling(
scenario_test_id: str,
polling_options: PollingOptions = _DEFAULT_POLLING_OPTIONS,
) -> BatchExperiment
Get a scenario test with polling.
Retrieves the result of a scenario test. This method polls for the result until the test finishes executing or the polling strategy is exhausted.
The scenario tests uses the batch experiments API under the hood.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the scenario test to retrieve.
TYPE:
|
|
Options to use when polling for the scenario test result.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BatchExperiment
|
The scenario test details as a batch experiment. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> test = app.scenario_test_with_polling("scenario-123")
>>> print(test.name)
'My Scenario Test'
>>> print(test.type)
'scenario'
Source code in nextmv/nextmv/cloud/application.py
secrets_collection
¶
secrets_collection(
secrets_collection_id: str,
) -> SecretsCollection
Get a secrets collection.
This method retrieves a secrets collection by its ID. A secrets collection is a group of key-value pairs that can be used by your application instances during execution.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the secrets collection to retrieve.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SecretsCollection
|
The requested secrets collection, including all secret values and metadata. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> # Retrieve a secrets collection
>>> collection = app.secrets_collection("api-secrets")
>>> print(collection.name)
'API Secrets'
>>> print(len(collection.secrets))
2
>>> for secret in collection.secrets:
... print(secret.location)
'API_KEY'
'DATABASE_URL'
Source code in nextmv/nextmv/cloud/application.py
src
class-attribute
instance-attribute
¶
Source of the application, if initialized locally. This is the path to the application's source code.
track_run
¶
track_run(
tracked_run: TrackedRun,
instance_id: Optional[str] = None,
) -> str
Track an external run.
This method allows you to register in Nextmv a run that happened elsewhere, as though it were executed in the Nextmv platform. Having information about a run in Nextmv is useful for things like experimenting and testing.
PARAMETER | DESCRIPTION |
---|---|
|
The run to track.
TYPE:
|
|
Optional instance ID if you want to associate your tracked run with an instance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The ID of the run that was tracked. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
ValueError
|
If the tracked run does not have an input or output. |
Examples:
>>> from nextmv.cloud import Application
>>> from nextmv.cloud.run import TrackedRun
>>> app = Application(id="app_123")
>>> tracked_run = TrackedRun(input={"data": [...]}, output={"solution": [...]})
>>> run_id = app.track_run(tracked_run)
Source code in nextmv/nextmv/cloud/application.py
3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 |
|
track_run_with_result
¶
track_run_with_result(
tracked_run: TrackedRun,
polling_options: PollingOptions = _DEFAULT_POLLING_OPTIONS,
instance_id: Optional[str] = None,
output_dir_path: Optional[str] = ".",
) -> RunResult
Track an external run and poll for the result. This is a convenience
method that combines the track_run
and run_result_with_polling
methods. It applies polling logic to check when the run was
successfully registered.
PARAMETER | DESCRIPTION |
---|---|
|
The run to track.
TYPE:
|
|
Options to use when polling for the run result.
TYPE:
|
|
Optional instance ID if you want to associate your tracked run with an instance.
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. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
ValueError
|
If the tracked run does not have an input or output. |
TimeoutError
|
If the run does not succeed after the polling strategy is exhausted based on time duration. |
RuntimeError
|
If the run does not succeed after the polling strategy is exhausted based on number of tries. |
Source code in nextmv/nextmv/cloud/application.py
update_batch_experiment
¶
update_batch_experiment(
batch_experiment_id: str,
name: Optional[str] = None,
description: Optional[str] = None,
) -> BatchExperimentInformation
Update a batch experiment.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the batch experiment to update.
TYPE:
|
|
Optional name of the batch experiment.
TYPE:
|
|
Optional description of the batch experiment.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BatchExperimentInformation
|
The information with the updated batch experiment. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Source code in nextmv/nextmv/cloud/application.py
update_instance
¶
update_instance(
id: str,
name: Optional[str] = None,
version_id: Optional[str] = None,
description: Optional[str] = None,
configuration: Optional[InstanceConfiguration] = None,
) -> Instance
Update an instance.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the instance to update.
TYPE:
|
|
Optional name of the instance.
TYPE:
|
|
Optional ID of the version to associate the instance with.
TYPE:
|
|
Optional description of the instance.
TYPE:
|
|
Optional configuration to use for the instance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Instance
|
The updated instance. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Source code in nextmv/nextmv/cloud/application.py
3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 |
|
update_managed_input
¶
update_managed_input(
managed_input_id: str,
name: Optional[str] = None,
description: Optional[str] = None,
) -> ManagedInput
Update a managed input.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the managed input to update.
TYPE:
|
|
Optional new name for the managed input.
TYPE:
|
|
Optional new description for the managed input.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ManagedInput
|
The updated managed input. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Source code in nextmv/nextmv/cloud/application.py
update_scenario_test
¶
update_scenario_test(
scenario_test_id: str,
name: Optional[str] = None,
description: Optional[str] = None,
) -> BatchExperimentInformation
Update a scenario test.
Updates a scenario test with new name and description. Scenario tests
use the batch experiments API, so this method calls the
update_batch_experiment
method, and thus the return type is the same.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the scenario test to update.
TYPE:
|
|
Optional new name for the scenario test.
TYPE:
|
|
Optional new description for the scenario test.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BatchExperimentInformation
|
The information about the updated scenario test. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> info = app.update_scenario_test(
... scenario_test_id="scenario-123",
... name="Updated Test Name",
... description="Updated description for this test"
... )
>>> print(info.name)
'Updated Test Name'
Source code in nextmv/nextmv/cloud/application.py
update_secrets_collection
¶
update_secrets_collection(
secrets_collection_id: str,
name: Optional[str] = None,
description: Optional[str] = None,
secrets: Optional[list[Secret]] = None,
) -> SecretsCollectionSummary
Update a secrets collection.
This method updates an existing secrets collection with new values for name, description, and secrets. A secrets collection is a group of key-value pairs that can be used by your application instances during execution.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the secrets collection to update.
TYPE:
|
|
Optional new name for the secrets collection.
TYPE:
|
|
Optional new description for the secrets collection.
TYPE:
|
|
Optional list of secrets to update. Each secret should be an instance of the Secret class containing a key and value.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SecretsCollectionSummary
|
Summary of the updated secrets collection including its metadata. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If no secrets are provided. |
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> # Update an existing secrets collection
>>> from nextmv.cloud import Secret
>>> updated_secrets = [
... Secret(key="API_KEY", value="new-api-key"),
... Secret(key="DATABASE_URL", value="new-database-url")
... ]
>>> updated_collection = app.update_secrets_collection(
... secrets_collection_id="api-secrets",
... name="Updated API Secrets",
... description="Updated collection of API secrets",
... secrets=updated_secrets
... )
>>> print(updated_collection.id)
'api-secrets'
Source code in nextmv/nextmv/cloud/application.py
3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 |
|
upload_large_input
¶
upload_large_input(
input: Optional[Union[dict[str, Any], str]],
upload_url: UploadURL,
json_configurations: Optional[dict[str, Any]] = None,
tar_file: Optional[str] = None,
) -> None
Upload large input data to the provided upload URL.
This method allows uploading large input data (either a dictionary or string) to a pre-signed URL. If the input is a dictionary, it will be converted to a JSON string before upload.
PARAMETER | DESCRIPTION |
---|---|
|
Input data to upload. Can be either a dictionary that will be converted to JSON, or a pre-formatted JSON string.
TYPE:
|
|
Upload URL object containing the pre-signed URL to use for uploading.
TYPE:
|
|
Optional configurations for JSON serialization. If provided, these
configurations will be used when serializing the data via
TYPE:
|
|
If provided, this will be used to upload a tar file instead of a JSON string or dictionary. This is useful for uploading large files that are already packaged as a tarball.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method doesn't return anything. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> # Upload a dictionary as JSON
>>> data = {"locations": [...], "vehicles": [...]}
>>> url = app.upload_url()
>>> app.upload_large_input(input=data, upload_url=url)
>>>
>>> # Upload a pre-formatted JSON string
>>> json_str = '{"locations": [...], "vehicles": [...]}'
>>> app.upload_large_input(input=json_str, upload_url=url)
Source code in nextmv/nextmv/cloud/application.py
upload_url
¶
upload_url() -> UploadURL
Get an upload URL to use for uploading a file.
This method generates a pre-signed URL that can be used to upload large files to Nextmv Cloud. It's primarily used for uploading large input data, output results, or log files that exceed the size limits for direct API calls.
RETURNS | DESCRIPTION |
---|---|
UploadURL
|
An object containing both the upload URL and an upload ID for reference. The upload URL is a pre-signed URL that allows temporary write access. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> # Get an upload URL and upload large input data
>>> upload_url = app.upload_url()
>>> large_input = {"locations": [...], "vehicles": [...]}
>>> app.upload_large_input(input=large_input, upload_url=upload_url)
Source code in nextmv/nextmv/cloud/application.py
version
¶
version(version_id: str) -> Version
Get a version.
Retrieves a specific version of the application by its ID. Application versions represent different iterations of your application's code and configuration.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the version to retrieve.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Version
|
The version object containing details about the requested application version. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If the response status code is not 2xx. |
Examples:
>>> # Retrieve a specific version
>>> version = app.version("v1.0.0")
>>> print(version.id)
'v1.0.0'
>>> print(version.name)
'Initial Release'
Source code in nextmv/nextmv/cloud/application.py
version_exists
¶
version_exists(version_id: str) -> bool
Check if a version exists.
This method checks if a specific version of the application exists by attempting to retrieve it. It handles HTTP errors for non-existent versions and returns a boolean indicating existence.
PARAMETER | DESCRIPTION |
---|---|
|
ID of the version to check for existence.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the version exists, False otherwise. |
RAISES | DESCRIPTION |
---|---|
HTTPError
|
If an HTTP error occurs that is not related to the non-existence of the version. |
Examples:
>>> # Check if a version exists
>>> exists = app.version_exists("v1.0.0")
>>> if exists:
... print("Version exists!")
... else:
... print("Version does not exist.")
Source code in nextmv/nextmv/cloud/application.py
DownloadURL
¶
Bases: BaseModel
Result of getting a download URL.
You can import the DownloadURL
class directly from cloud
:
This class represents a download URL that can be used to fetch content from Nextmv Cloud, typically used for downloading large run results.
ATTRIBUTE | DESCRIPTION |
---|---|
url |
URL to use for downloading the file.
TYPE:
|
Examples:
>>> download_url = DownloadURL(url="https://example.com/download")
>>> response = requests.get(download_url.url)
PollingOptions
dataclass
¶
PollingOptions(
backoff: float = 0.9,
delay: float = 0.1,
initial_delay: float = 1,
max_delay: float = 20,
max_duration: float = -1,
max_tries: int = -1,
jitter: float = 1,
verbose: bool = False,
stop: Optional[Callable[[], bool]] = None,
)
Options to use when polling for a run result.
You can import the PollingOptions
class directly from cloud
:
The Cloud API will be polled for the result. The polling stops if:
- The maximum number of polls (tries) are exhausted. This is specified by
the
max_tries
parameter. - The maximum duration of the polling strategy is reached. This is
specified by the
max_duration
parameter.
Before conducting the first poll, the initial_delay
is used to sleep.
After each poll, a sleep duration is calculated using the following
strategy, based on exponential backoff with jitter:
Where: * i is the retry (poll) number. * Uniform is the uniform distribution.
Note that the sleep duration is capped by the max_delay
parameter.
PARAMETER | DESCRIPTION |
---|---|
|
Exponential backoff factor, in seconds, to use between polls.
TYPE:
|
|
Base delay to use between polls, in seconds.
TYPE:
|
|
Initial delay to use before starting the polling strategy, in seconds.
TYPE:
|
|
Maximum delay to use between polls, in seconds.
TYPE:
|
|
Maximum duration of the polling strategy, in seconds.
TYPE:
|
|
Maximum number of tries to use.
TYPE:
|
|
Jitter to use for the polling strategy. A uniform distribution is sampled between 0 and this number. The resulting random number is added to the delay for each poll, adding a random noise. Set this to 0 to avoid using random jitter.
TYPE:
|
|
Whether to log the polling strategy. This is useful for debugging.
TYPE:
|
|
Function to call to check if the polling should stop. This is useful for stopping the polling based on external conditions. The function should return True to stop the polling and False to continue. The function does not receive any arguments. The function is called before each poll.
TYPE:
|
Examples:
>>> from nextmv.cloud import PollingOptions
>>> # Create polling options with custom settings
>>> polling_options = PollingOptions(
... max_tries=50,
... max_duration=600,
... verbose=True
... )
backoff
class-attribute
instance-attribute
¶
Exponential backoff factor, in seconds, to use between polls.
delay
class-attribute
instance-attribute
¶
Base delay to use between polls, in seconds.
initial_delay
class-attribute
instance-attribute
¶
Initial delay to use before starting the polling strategy, in seconds.
jitter
class-attribute
instance-attribute
¶
Jitter to use for the polling strategy. A uniform distribution is sampled between 0 and this number. The resulting random number is added to the delay for each poll, adding a random noise. Set this to 0 to avoid using random jitter.
max_delay
class-attribute
instance-attribute
¶
Maximum delay to use between polls, in seconds.
max_duration
class-attribute
instance-attribute
¶
Maximum duration of the polling strategy, in seconds. A negative value means no limit.
max_tries
class-attribute
instance-attribute
¶
Maximum number of tries to use. A negative value means no limit.
stop
class-attribute
instance-attribute
¶
Function to call to check if the polling should stop. This is useful for stopping the polling based on external conditions. The function should return True to stop the polling and False to continue. The function does not receive any arguments. The function is called before each poll.
verbose
class-attribute
instance-attribute
¶
Whether to log the polling strategy. This is useful for debugging.
UploadURL
¶
Bases: BaseModel
Result of getting an upload URL.
You can import the UploadURL
class directly from cloud
:
This class represents an upload URL that can be used to send data to Nextmv Cloud, typically used for uploading large inputs for runs.
ATTRIBUTE | DESCRIPTION |
---|---|
upload_id |
ID of the upload, used to reference the uploaded content.
TYPE:
|
upload_url |
URL to use for uploading the file.
TYPE:
|
Examples:
poll
¶
poll(
polling_options: PollingOptions,
polling_func: Callable[[], tuple[Any, bool]],
__sleep_func: Callable[[float], None] = sleep,
) -> Any
Poll a function until it succeeds or the polling strategy is exhausted.
You can import the poll
function directly from cloud
:
This function implements a flexible polling strategy with exponential backoff and jitter. It calls the provided polling function repeatedly until it indicates success, the maximum number of tries is reached, or the maximum duration is exceeded.
The polling_func
is a callable that must return a tuple[Any, bool]
where the first element is the result of the polling and the second
element is a boolean indicating if the polling was successful or should be
retried.
PARAMETER | DESCRIPTION |
---|---|
|
Options for configuring the polling behavior, including retry counts, delays, timeouts, and verbosity settings.
TYPE:
|
|
Function to call to check if the polling was successful. Must return a tuple where the first element is the result value and the second is a boolean indicating success (True) or need to retry (False).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
Result value from the polling function when successful. |
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the polling exceeds the maximum duration specified in polling_options. |
RuntimeError
|
If the maximum number of tries is exhausted without success. |
Examples:
>>> from nextmv.cloud import PollingOptions, poll
>>> import time
>>>
>>> # Define a polling function that succeeds after 3 tries
>>> counter = 0
>>> def check_completion() -> tuple[str, bool]:
... global counter
... counter += 1
... if counter >= 3:
... return "Success", True
... return None, False
...
>>> # Configure polling options
>>> options = PollingOptions(
... max_tries=5,
... delay=0.1,
... backoff=0.2,
... verbose=True
... )
>>>
>>> # Poll until the function succeeds
>>> result = poll(options, check_completion)
>>> print(result)
'Success'
Source code in nextmv/nextmv/cloud/application.py
3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 |
|