Skip to main content

gravi-model-client

Python client for Gravitate's demand and supply optimization models.

Installation

pip install gravi-model-client

Usage

from gravi_model_client import GraviModelClient, ModelRunRequest, OptimizationInput

async with GraviModelClient(api_key="your-api-key", base_url="https://...") as client:
    # Health check
    await client.health_check()

    # Run demand model inline — blocks for the whole solve
    result = await client.run_demand_model(request)

    # Run TSD (supply) model inline — blocks for the whole solve
    result = await client.run_tsd_model(optimization)

run_demand_model and run_tsd_model hold the HTTP request open for the length of the solve. They raise ModelRequestInvalid when the server rejects the body, with one readable line per field error in .issues.

Queue-based models

Every model can also be run through the job queue, where a worker picks the run up and the client polls for it. The run_*_model_async methods handle the whole queue → poll → fetch lifecycle and block until the result is ready:

from gravi_model_client import GraviModelClient

async with GraviModelClient(api_key="your-api-key") as client:
    demand = await client.run_demand_model_async(demand_request)  # -> ModelResultResponse
    ltl = await client.run_ltl_model_async(ltl_request)  # -> LtlModelResultResponse
    vrp = await client.run_vrp_model_async(vrp_request)  # -> VrpModelResultResponse
    osa = await client.run_osa_model_async(osa_input)  # -> OsaAPIResponse
    tsd = await client.run_tsd_model_async(tsd_input)  # -> OptimizationAPIResponse

They raise ModelRunError if the run fails or is cancelled, and ModelRunTimeout if it doesn't finish within timeout (default 300s, 900s for TSD; tune poll_interval too).

For fire-and-forget / webhook workflows, use the primitives instead. Each model has the same trio:

Model Queue Status Fetch result
Demand queue_demand_model get_demand_job_status get_demand_model_run_response
LTL queue_ltl_model get_ltl_job_status get_ltl_model_run_response
VRP queue_vrp_model get_vrp_job_status get_vrp_model_run_response
OSA queue_osa_model get_osa_job_status get_osa_model_run_response
TSD queue_tsd_model get_tsd_job_status get_tsd_model_run_response

The result fetch raises ModelResultNotReady while a run is still queued or running, and ModelRunError once it has ended failed or cancelled — so a caller polling the fetch directly can tell "come back later" from "this will never succeed".

Job administration

get_job_details, get_ltl_job_details and get_tsd_job_details return a JobDetails with the job's status alongside the request and response stored on the server — that is where to read back the input a finished run was given. cancel_demand_jobs, cancel_ltl_jobs, cancel_osa_jobs and cancel_tsd_jobs cancel every job under a history_id; get_queue_stats, get_ltl_queue_stats and get_tsd_queue_stats report queue depth; clear_files and clear_ltl_files delete the server's temporary request and response files.

Retries

Every request retries transient failures — connection errors, timeouts, 429 and 5xx — with jittered exponential backoff:

GraviModelClient(api_key, retries=3, retry_backoff=1.0, retry_backoff_max=20.0)

retries=0 disables it. The queue endpoints are deliberately more conservative: a failure that may have reached the server is not replayed, because that would enqueue the same solve twice. Only a connection failure, which provably never arrived, is retried there.

Models

This package is the single source of truth for all pydantic models used by both the client and the server. Import models directly:

from gravi_model_client.demand import ModelRunRequest, StoreRequest, TankRequest, VolumeRange
from gravi_model_client.tsd import OptimizationInput, Directive, Site, Tank

Metadata

Release files for gravi-model-client 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gravi-model-client 0.10.0
File Size Uploaded
gravi_model_client-0.10.0.tar.gz 44.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gravi-model-client 0.10.0
File Interpreter ABI Platform
gravi_model_client-0.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 77.3 kB

Release files / gravi_model_client-0.10.0.tar.gz

Download URL gravi_model_client-0.10.0.tar.gz
Size 44.8 kB
Tags Source
SHA-256 checksum
How to use checksums
532c978ca3ba9aa43477db595cf8455031cbbc6f05c855ccd15aeec0c31e5719
BLAKE2b-256 checksum
How to use checksums
c3448b8ad4cf836637926c3b86eab3d4ea1b909113f33b6273a9208ccbfe78f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Release files / gravi_model_client-0.10.0-py3-none-any.whl

Download URL gravi_model_client-0.10.0-py3-none-any.whl
Size 32.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31d90181411674b1dfbf002c0b1b1a3ad2708e04097582468ba86fe36c5d3591
BLAKE2b-256 checksum
How to use checksums
f6b3c48992ad9ae171a4ec7c7430c20129290a7a05b5a95df2f9373ac38c6503
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Release history Release notifications | RSS feed

0.11.0

2 release files

This release

0.10.0 This release

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page