Skip to main content

PlanSolve for Python

Official Python client for the PlanSolve optimization API. One typed client covers three solvers (field service routing, professional-services task assignment, and shift scheduling) with built-in polling and clean error messages.

Installation

pip install plansolve

Requires Python 3.8+ and requests 2.31+. Type hints are bundled.

Quick start

from plansolve import PlanSolveClient

client = PlanSolveClient(api_key="YOUR_API_KEY")

request = {
    "vehicles": [
        {
            "id": "tech1",
            "location": [40.7128, -74.0060],
            "skills": ["repair"],
            "shifts": [
                {"id": "morning", "minStartTime": "2026-04-02T08:00:00", "maxEndTime": "2026-04-02T17:00:00"}
            ],
        }
    ],
    "visits": [
        {
            "id": "visit1",
            "name": "AC Repair - Downtown Office",
            "location": [40.7589, -73.9851],
            "serviceDuration": "PT60M",
            "priority": "HIGH",
            "requiredSkills": ["repair"],
            "timeWindows": [
                {"minStartTime": "2026-04-02T09:00:00", "maxEndTime": "2026-04-02T17:00:00"}
            ],
        }
    ],
}

# Submit and block until the optimized plan is ready
result = client.field_service.start_and_wait_for_completion(request)

for vehicle in result.vehicles:
    print(f"Vehicle {vehicle.id}: {len(vehicle.visits)} visits")

Requests accept a plain dict (as above) or the typed dataclasses (FieldServiceRequest, Vehicle, Visit, ...).

Solvers

One client, three solvers. All share the same submit, poll, result workflow:

Solver Accessor Use for
Field Service client.field_service Vehicle routing with travel time, time windows, and skills
Professional Services client.professional_services Task assignment by skill, availability, priority, and deadlines
Shift client.shift Shift scheduling across contracts, availability, and fairness

Every solver client exposes the same methods:

Method HTTP Returns
start(request) POST /api/v1/{solver} Start response with job_id (solver_job_id and result are None unless the server provides them)
get_status(job_id) GET /api/v1/{solver}/{job_id}/status Status dict (jobId, solverStatus, score, feasible, solving) — score here is still the raw wire value, not a Score; see Score below
get_result(job_id) GET /api/v1/{solver}/{job_id} The solver's result type
stop(job_id) DELETE /api/v1/{solver}/{job_id} Stops the solve and returns the best solution found so far (same type as get_result)
analyze(job_id) GET /api/v1/{solver}/{job_id}/analyze Constraint analysis as a dict
wait_for_completion(job_id, poll_interval_ms=5000, max_attempts=150) polls status, then fetches the result The solver's result type
start_and_wait_for_completion(request, poll_interval_ms=5000, max_attempts=150) start + wait_for_completion The solver's result type

{solver} is fieldservice, professionalservices or shift. The result types are FieldServiceResultResponse, ProfessionalServicesResultResponse and ShiftResultResponse; each gets a client-side job_id stamped after parsing.

Score

Score is an exported dataclass with hard, medium and soft levels (arbitrary-precision int); a solution is feasible when hard >= 0. Use Score.parse(value) to parse the canonical "Xhard/Ymedium/Zsoft" string, Score.from_wire(value) to normalize either wire form (and None/"" into None), score.to_wire_object() to render the object form back out, and str(score) for the canonical string.

On get_result, stop and wait_for_completion, the score field on the typed result dataclasses is Optional[Score]: None while the job is still solving, and also for a job the solver has not scored yet.

get_status is the one exception. SolverStatusResponse is just a Dict[str, Any] type alias, not a model, so it is never run through Score.from_wire. Its score key is still the raw string or object the server sent, exactly like before this change — unlike every other SDK's status response, and unlike this SDK's own typed result responses. Parse it yourself:

from plansolve import Score

status = client.field_service.get_status(job_id)
score = Score.from_wire(status.get("score"))  # None while solving or unscored
if score is not None:
    print(f"{score} (feasible: {score.hard >= 0})")

Polling

The wait helpers sleep poll_interval_ms before each status check and stop as soon as the status reports solving false and solverStatus NOT_SOLVING (a score is not required). The defaults are 5000 ms between polls and 150 polls (12.5 minutes), which covers the server's 10-minute cap on a solve. A value of 0 or less for either argument falls back to the default.

# Stop early and keep the best plan found so far
best = client.shift.stop(job_id)

# Inspect which constraints drive the score
analysis = client.field_service.analyze(job_id)

Unassigned work parses cleanly: a field service visit the solver could not place comes back with vehicle, arrival_time, departure_time, start_service_time and driving_time_seconds_from_previous_standstill set to None.

Configuration

Pass your API key to the constructor: PlanSolveClient(api_key="..."). It is sent as the X-API-KEY header on every request.

Error handling

The SDK never prints to stdout or stderr; everything is reported through exceptions:

Exception When
requests.HTTPError Any non-2xx response. The message is HTTP <status>: <detail>, built from the error body (validation errors, error, detail or title), e.g. HTTP 400: vehicles: At least one vehicle is required. The original response is on e.response. A failed solve answers the status endpoint with HTTP 422, so the wait helpers raise this too.
ValueError("JobId was not returned from wait_for_completion.") wait_for_completion was called with an empty job id, or the start response carried none.
ValueError("Solver still running after N polls; raise max_attempts or lower options.spent_limit") The solver was still running after max_attempts status polls.
requests.RequestException Network failures (connection errors, timeouts) raised by requests.
import requests

try:
    result = client.field_service.start_and_wait_for_completion(request)
except requests.HTTPError as e:
    print(e.response.status_code, e)
except ValueError as e:
    print(e)

Documentation

Full guides, per-solver data models, and parameter reference live on the docs site:

Package: PyPI

License

Apache-2.0. See LICENSE.

Metadata

Release files for plansolve 0.33.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 plansolve 0.33.0
File Size Uploaded
plansolve-0.33.0.tar.gz 49.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for plansolve 0.33.0
File Interpreter ABI Platform
plansolve-0.33.0-py3-none-any.whl Python 3 none any Details

Total release size: 97.3 kB

Release files / plansolve-0.33.0.tar.gz

Download URL plansolve-0.33.0.tar.gz
Size 49.8 kB
Tags Source
SHA-256 checksum
How to use checksums
30ec1d7451c97e472cde1121289eeecf226c05e0f96265849dd97b60dd576df6
BLAKE2b-256 checksum
How to use checksums
ad80ac923f9bbb192226f3a5fe97e3120d3f22cef46bb43cac0f3fce13779803
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 Oct 3, 2026.

Transparency log

Release files / plansolve-0.33.0-py3-none-any.whl

Download URL plansolve-0.33.0-py3-none-any.whl
Size 47.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eac5850bf711ce7711cefaa877d2e560ab38366d3a424154752cbefc0006c731
BLAKE2b-256 checksum
How to use checksums
d4b50f7003a7a3b586c799620668a78b5241a14a3d21bbd568544c1fbe11630d
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 Oct 3, 2026.

Transparency log

Release history Release notifications | RSS feed

0.37.0

2 release files

0.36.0

2 release files

0.35.0

2 release files

0.34.0

2 release files

This release

0.33.0 This release

2 release files

0.29.0

2 release files

0.28.0

2 release files

0.27.0

2 release files

0.26.0

2 release files

0.25.8

2 release files

0.25.7

2 release files

0.25.6

2 release files

0.25.5

2 release files

0.25.4

2 release files

0.25.3

2 release files

0.25.2

2 release files

0.25.1

2 release files

0.25.0

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