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:
- Field Service: https://getplansolve.com/docs/fieldservice/sdk/python
- Professional Services: https://getplansolve.com/docs/professionalservices/sdk/python
- Shift: https://getplansolve.com/docs/shiftsolver/sdk/python
Package: PyPI
License
Apache-2.0. See LICENSE.
Metadata
Release files for plansolve 0.30.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| plansolve-0.30.0.tar.gz | 46.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| plansolve-0.30.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 92.4 kB
Release files / plansolve-0.30.0.tar.gz
| Download URL | plansolve-0.30.0.tar.gz |
|---|---|
| Size | 46.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
770039cd1908ab1bc72d8fd33a9c2d083013a0ca98d920622c1cc2dbf17f4fbf
|
|
BLAKE2b-256 checksum How to use checksums |
57c49441d1f4f0c95b5831ebf1e6aa93b030ed4a13104fe313a6f7270369e81c
|
| 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 logRelease files / plansolve-0.30.0-py3-none-any.whl
| Download URL | plansolve-0.30.0-py3-none-any.whl |
|---|---|
| Size | 45.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b01892676d141fa06828c59bb90a6d6a775ac88870aaaca9cb4f88858953ef02
|
|
BLAKE2b-256 checksum How to use checksums |
2fc32dca89ba8a3d3bf7c78f4d6f54136306deece2df0cae1fd08d0f0c7dabdf
|
| 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