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)
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.

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.32.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.32.0
File Size Uploaded
plansolve-0.32.0.tar.gz 48.2 kB Details

Built distribution (wheel)

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

Total release size: 95.1 kB

Release files / plansolve-0.32.0.tar.gz

Download URL plansolve-0.32.0.tar.gz
Size 48.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3aff6cf80b4a6db216317e3a99a2b0a47ff15866ecbfaa56b2dd6e98b6b73ec2
BLAKE2b-256 checksum
How to use checksums
148082708e47ae6c770a0ba9bab9e71e18cc9c14434483fc92c0a5e5643ee285
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.32.0-py3-none-any.whl

Download URL plansolve-0.32.0-py3-none-any.whl
Size 46.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca94e55b05201657635d37e98633f2962ebe4862d2eee27760b14c9c187810ca
BLAKE2b-256 checksum
How to use checksums
a867a485c653668f02b47dc6d9dcefcbce77d28c35405c6618add4daec90d586
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.32.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