Repository navigation
This is the first release since 0.1.7.0, and the first on PyPI since 0.0.7.1 in 2020.
It fixes every open bug report (#19, #26, #30–#43, #124–#135), adds 216 API methods for the operations the coverage issues list (#44–#107), and hardens how the SDK handles the API key. It also adds an offline test suite of 1,422 tests behind a request guard. Several fixes change behaviour that code may rely on, so read Breaking changes before upgrading.
Breaking changes
Requirements
- Python 3.9 or later. Python 2 and the
sixdependency are gone. - The dependency floors follow security fixes:
- Python 3.10 and later:
requests>=2.33.0andurllib3>=2.8.0. - Python 3.9:
requests>=2.32.5andurllib3>=2.6.3. SeeSECURITY.md.
- Python 3.10 and later:
Transport
- Requests time out after
(6.05, 30.0)seconds (connect, read) by default.- A long call now raises
requests.ReadTimeoutorConnectTimeout, which resource methods do not catch. - Pass
timeout=Nonefor the old unbounded behaviour. - The route update methods also take a per-call
timeout=.
- A long call now raises
- API V5 requests send the key as
Authorization: Bearer <key>instead of theapi_keyquery parameter, so the key no longer appears in URLs. V4 requests are unchanged. - API V5 requests send
Accept: application/json, */*;q=0.8. With*/*, API V5 answered errors with an HTML page, so their messages were lost. File exports still work, and anAcceptyou set on the client is kept. - Each client uses one pooled
requests.Session.- Patching
requests.get,postorrequestno longer intercepts the SDK's calls. Patchrequests.Session.send, or useresponses. - Cookies now persist for the life of a client.
- Patching
- Retries stay off by default.
- With
retry_countset, only GET, HEAD, OPTIONS and DELETE are retried. - POST and PUT are never retried, because replaying them can create or insert things twice.
- Cloudflare's 520–524 errors now count as retryable.
- With
redirects=Falsenow also applies to PUT and DELETE.- Boolean query values are sent as
1and0.requestssent them as"True"and"False"; PHP reads"False"as true, and the API V5 validation rejects both strings.get_address_notes()now sendsnotes=1. - API V5 list and dict query values are sent with bracketed keys, for example
ids[]=1&ids[]=2andfilters[status]=1. PHP keeps only the last value of a repeated plain key, andrequestscould not send a dict or a nested list at all.
Errors and return values
-
APIException.to_dict()["errors"]is always a non-empty list of strings. It holds:- the V4
errors; - the flattened V5
messages; - the
messagevalue; - or
["Unexpected server response"].
It used to be a string for a non-JSON reply, and
Nonewhen the reply had noerrors, so". ".join(result["errors"])printed letter by letter or raised. The API V5errormessage (for example "the required feature is not enabled") is read too. - the V4
-
APIException.urland.responseare redacted, which changesstr(exc)andexc.args. -
re_optimization()raisesAPIExceptionon an HTTP error. -
get_optimization()andparse_response()return the payload; they used to returnNone. -
route_start_date_local()raises on an invalid date, including a date with a time part. -
Membersvalidation errors name the missing parameters; they used to always name"order". -
Address.fix_geocode()copies onlylatandlngfrom the first geocoder result. An API error, or a reply without coordinates, is reported as a failure. -
Address.batch_fix_geocodes()returns(geocoding_error, addresses)in the documented order, and reports unmatched results instead of raisingKeyError.
API surface
- Setters on resources take one positional value.
opt.route_name(...)and similar are now descriptors.opt.route_name(route_name=...)now raisesTypeError.- The 0/1 fields reject floats such as
1.0.
from route4me.api import AvoindanceZonesno longer works. ImportAvoidanceZones, or the aliasAvoindanceZones, fromroute4me.avoidance_zones.AdvancedConstraintandBundlingare dataclasses: they compare by value and are no longer hashable.ServiceTimeRuleskeeps its rules as dict items instead of class attributes. Attribute access still works.Bundling.to_dict()returns a snapshot, not the live__dict__. Itsservice_time_rulesholds only the rules that are set.clean_dict(), and soAdvancedConstraint.to_dict(), keeps0,0.0andFalse.- Per-call values no longer stick to a resource (#36). A
route_idpassed toget_route(), a vendor ID, orredirect=0used to stay in the resource'sparamsand travel with later requests. Code that relied on that must pass the value on every call. - The internal
_request_get,_request_post,_request_putand_request_deletehelpers take keyword-only options. Theroute4me._api_methodmodule is gone;Base._call_apireplaces it. Route4Me(headers=...)defaults toNone, which still meansHEADERS.- The library logs through
loggingand warns throughwarningsinstead of printing.
Security
- The API key goes only to
api.route4me.comandwh.route4me.com. A request to any other host carries no key, even if a caller putapi_keyin its parameters. The deprecated vendor methods (telematics.route4me.com, retired) and street-data methods (rapid.route4me.com/street_data, gone) no longer send a request at all: they warn and return an{"errors": [...]}dict. Before, they sent the key in the query string to an endpoint that no longer works, the class of bug behind the PHP SDK's PR #41. - Route IDs in URL paths are percent-encoded.
RouteStatusandRoute.export_route_v5insertedroute_idraw.requestsresolves dot segments, soroute-status/../secretreached/modules/api/v5.0/secretwith the caller's key.- The
rapid_addresspath components are now encoded the same way.
- The API key stays out of request bodies.
Optimization.update_optimizationandActivityFeed.log_specific_messagecopied it there. - Credential-like query parameters are redacted by name, not only the known list. Any name ending in
api_key,apikey,_token,_secretorpasswordis redacted, soorganization_api_key(API V5 member configuration settings) never reaches a traceback. - The API key stays out of URLs, tracebacks and logs:
- URLs, for API V5, which now uses a bearer token;
- tracebacks:
APIExceptionredacts URLs and bodies, including those of the V4 endpoints that echo parameters back; - logs.
- No request state is shared between calls (#36). This is the class of bug that sent the PHP SDK's requests to the wrong host.
- A guard checks every test request: https only, Route4Me hosts only, registered endpoints only, and the key only in its expected place and only to the API hosts.
- CI hardening.
- CI actions are pinned to commit SHAs and use read-only tokens.
- gitleaks runs in CI and as a pre-commit hook.
SECURITY.mddescribes how to report a vulnerability.
Added
- API coverage: 216 new methods (#44–#107). They cover the Route4Me API V4 and V5 operations the coverage issues list. Every request shape comes from the OpenAPI specs, then the C# SDK; the issues' own paths were often wrong. Each method has a unit test and a runnable example.
- New resources on the client:
- Address book:
address_book_v5,address_barcodes. - Vehicles:
vehicles_v5,vehicle_profiles,vehicle_capacity_profiles. - Routes:
routes_v5,route_destinations_v5. - Team and account:
team_v5,account_profile,auth_history,configuration_settings,configuration_settings_v5. - Orders and schedules:
orders_v5,recurring_routes. - Notes and proof of delivery:
notes,driver_reviews,pod_workflows. - Places:
customers,facilities,locations(with location types),territories_v5. - Tracking:
tracking_history,route_breaks,asset_tracking. - Lookups:
distance,drivers,autocomplete.
- Address book:
- Existing resources gain methods:
AddressBook: groups, search by filter, saving geocoded addresses.Address: move a destination to another route, delete destinations, mark visited or departed.Route.rename_route.RouteStatus:set_route_stop_status,update_route_status_as_planned, and cancel reasons inset_route_status.Members: create, update and delete users, and member capabilities.Order: filter, updates and custom user fields.Optimization: hybrid optimizations and time prediction.OptimizationProfiles: CRUD and entities.GPS: batch pings, user locations and vehicle locations.FileUploading: the JSON upload for bulk geocoding.
- Not implemented, with the reason recorded on each issue:
- operations on retired hosts or 404 endpoints;
- the MyQ and OCR operations, which are not Route4Me APIs;
expire_session.php, which ends a browser session and is not an API-key call.
- New resources on the client:
- PATCH requests (
Base._call_api(..., "patch", ...)), used by API V5 partial updates. Like PUT, they are never retried. Telematics.get_vendors_v5(**filters)andTelematics.get_vendor_v5(vendor_id), onGET /modules/api/v5.0/telematics/vendors(/all).Optimization.reset()clears a staged optimization, so one client can build another (#26).Base.validated_params(**kwargs)runs the field setters on a copy.- A
timeout=argument onRoute.insert_address_into_route,move_addresses_from_route,update_route_parametersandupdate_route. Optimization.bundling()accepts aBundlingobject (#43), andadvanced_constraints()acceptsAdvancedConstraintobjects.Route.merge_routes(route_ids=...)accepts a list of IDs.- Connection pooling, plus opt-in retry and an opt-in circuit breaker, mirroring the C# SDK.
- Retry uses exponential backoff.
- Options:
retry_count,retry_initial_delay,enable_circuit_breaker,circuit_breaker_failure_threshold,circuit_breaker_duration,on_retry,on_circuit_breaker_open,use_sessionandsession. Retry-Afteris honoured, capped at 120 s.
Route4Me.close(), and use as a context manager (with Route4Me(key) as r4m:).CircuitBreaker.state:"closed","open"or"half-open".route4me.config.Route4MeConfigfor process-wide defaults. Precedence: per call, then constructor, then global, then default.route4me/_redact.pyandroute4me/_url.py, the redaction and URL helpers.APIException.get_url().Telematics.pp_response()takes afile=stream.AvoidanceZones, the correctly spelled name.AvoindanceZonesremains as an alias.- Docstrings on every public module, class and method.
Deprecated
Telematics.get_vendors,get_vendor,search_vendorandcompare_vendors:telematics.route4me.comis retired. They send no request and return an error dict. Useget_vendors_v5andget_vendor_v5.Telematics.pp_vendor_comparison: it prints the features of the retiredcompare_vendorsreply, and API V5 vendors have none.RapidAddress.get_street_data,get_street_data_zipandget_street_data_service: the street-data endpoints return 404 and have no replacement. They still check their arguments, then send no request and return an error dict.Route.export_route: the V4 export endpoint returns 404. Useexport_route_v5.- Operations the C# SDK marks obsolete. They still work, but warn, and will be removed in the next major version:
Members.get_api_key_users,create_user,user_updateanduser_delete(/api.v4/user.php): useTeamV5.get_team_membersorget_team_member_by_id,create_team_member,update_team_memberandremove_team_member;AddressBook.get_addressbook_contacts,create_contact,update_contactanddelete_addressbook_contact(/api.v4/address_book.php): useAddressBookV5.get_address_book_contacts,add_address_book_contact,update_address_book_contactandremove_address_book_contacts.get_addressbook_contactandsearch_address_book_contacts_by_filterare not deprecated;Route.resequence_route_all(/api.v3/route/reoptimize_2.php): useRoute.update_routewithreoptimize=1.
Members.webinar_registration(webiinar_date=...): passwebinar_date.
Removed
- Python 2 support and
six. - The
route4me._api_methodmodule. - Configs for dead services: Travis, AppVeyor, Scrutinizer, Codebeat (115 pragmas) and Codecov.
- Tests that called the live API. The suite is offline;
pytest-socketblocks any connection. - The seven
examples/rapid_addressexamples, whose endpoints are gone.
Fixed
- #19: four route methods sent their body as form data from 0.1.6.0 on, which the API cannot read for nested values. They send JSON again. The methods are
insert_address_into_route,move_addresses_from_route,update_route_parametersandupdate_route. A slow insert no longer risks a duplicating retry. - #26: a reused client accumulated addresses. Use
Optimization.reset(). - #30, #125:
get_optimization()raisedTypeErrorfor every real response, so it never returned the optimization. - #31:
route_start_date_local()silently accepted an invalid date (a missingraise). - #32:
Telematics.delete_connection()swallowed errors (a missingreturn). - #33, #40:
ServiceTimeRulesshared its lists between instances, and its rules never reached the API. - #34:
Route4Me(proxies=...)andRoute4Me(headers=...)shared one dict between clients. - #35:
OrdersGroup.get_orders_group()raisedTypeErrorinstead ofParamValueException. - #36: per-call parameters leaked into later requests, at nine sites.
_make_requestalso changed theparamsdict it was given. - #37:
export_result_to_json()had never worked, and both JSON exporters failed on non-ASCII text on Windows. - #38: transport errors in
OrdersGroupandOptimizationProfilessurfaced asUnboundLocalError, and so did errors inRapidAddress. - #39:
Route.delete_route()raisedAttributeErrorfrom its own error handler. The same pattern is fixed inAddress.get_address()andget_address_notes(). - #41:
clean_dict()dropped0andFalse, corrupting time windows such as[0, 3600]. - #42:
RapidAddress.get_street_data()returnedNonewhen givenoffsetandlimit, or no arguments. It now returns an error dict on every branch, since the endpoint is gone (see Deprecated). - #43:
Optimization.bundling()rejected theBundlingobject its error message asked for. - #126: the
lat,lng,altitude,cached_latandcached_lngsetters rejected whole numbers such as10. They take any number except a boolean. - #127:
RapidAddressput its arguments into the URL unescaped. Its methods now send no request at all (see Deprecated). - #128: PUT and DELETE ignored
redirects=False, and DELETE ignoredproxies. - #129:
cached_latandcached_lngwrotelatandlng, overwriting the coordinates. They writecached_latandcached_lng. - #135:
Telematics.register_connection()andupdate_connection()overwrote avalidate_remote_credentialsgiven by the caller with"true"."true"is now only the default. - Optimization:
update_optimization()sent its addresses as unreadable form data, andreoptimize=Trueas"True".re_optimization()never raised on an HTTP error.
- Routes:
delete_routes()split a single route ID string into one ID per character.merge_routes()form-encoded a list of IDs as one field per ID.export_route_v5()sent form data where the API takes JSON.
- Address:
get_route_id()andget_route_destination_id()called a method that did not exist.- #124:
add_address_notes()raisedKeyErrorwithoutactivity_type. geocode()sent the address list in the URL.batch_fix_geocodes()returned its two values swapped.request_address()changed the caller's dict.
Members.webinar_registration()required and sent the misspelledwebiinar_date.- #132:
export_request_to_json()had the same encoding problem as #37, and both exporters left the file open when serialisation failed. - #134:
APIException.to_dict()raised onNone, bytes or list bodies, and discarded V5 error messages. - The circuit breaker's half-open state let every request through, and a failed probe did not re-open the breaker.
SlowdownsacceptedTrueandFalseas integers.- #130:
json2objraised on empty keys and on keys that are not identifiers. - #133: several setter error messages named the wrong type or values;
truck_hazardous_goodssaid "Must be MI or KM". - #131:
Base.validate_params()raisedTypeErrorfor a name that is not a setter, such asdata, and reported SDK bugs as "Not supported". Telematics.pp_vendor_comparison()raisedKeyErrorfor a vendor withoutfeatures.
Examples
- 339 examples, one per method, including 216 for the new API coverage. Every example has a docstring saying what it shows, which SDK method it calls, the request it sends, and how to run it. All of them pass pylint.
- The vendor examples use API V5.
- New examples:
- Broken examples are fixed:
- wrong argument names or shapes;
- the sixth item picked instead of the first;
- a depot moved out of first place;
update_route_parametersreassigning the route to member 1;- error checks that could never be true.
- The member and share-route examples use
example.comaddresses.
Internal
- Packaging moved to
pyproject.toml(hatchling);setup.pyis a shim. - 1,422 offline tests with 97% line and branch coverage, and a 90% floor. Every request is checked against an endpoint registry built from the Route4Me OpenAPI specs.
- pylint gives zero messages on the package, the tests and the examples. ruff formats the code. mypy passes, with strict checks on the tier-A modules, and blocks CI.
- CI runs Python 3.9–3.14 on Linux, and Python 3.12 on macOS and Windows.