A lightweight wrapper for Google Fleet Routing / OptimizeTours API.
Project description
gcp_route_optimizer
gcp_route_optimizer is a lightweight Python library that simplifies using the Google Fleet Routing / OptimizeTours API.
It automatically:
- Extracts the
project_idfrom your Google Service Account JSON - Generates OAuth tokens using the service account credentials
- Builds shipment and vehicle structures
- Sends requests to the OptimizeTours API
- Returns optimized route information (polyline + visit sequence)
This library contains no AWS, SSM, Flask, or database code, making it reusable in any project.
🚀 Features
- Simple and clean API
- Pure Google Route Optimization logic
- Auto token generation from service account JSON
- Zero cloud-specific dependencies
- Python 3.9+ compatible
📦 Installation
pip install gcp-route-optimizer
🔧 Basic Usage
python
Copy code
from gcp_route_optimizer import RouteOptimizer
# Google service account JSON (loaded from file, env, or SSM)
service_account_json = {
"type": "service_account",
"project_id": "your-project-id",
"private_key": "...",
"client_email": "...",
...
}
# Your warehouse or starting location
warehouse = {"lat": 11.01897, "lng": 77.00651}
# Orders to optimize
orders = [
{"delivery_lat": 11.05, "delivery_lng": 77.10},
{"delivery_lat": 11.02, "delivery_lng": 77.03}
]
optimizer = RouteOptimizer(
service_account_json=service_account_json,
warehouse_location=warehouse
)
result, success = optimizer.optimize(orders)
if success:
print("Polyline:", result["polyline"])
print("Visits:", result["visits"])
else:
print("Error:", result["error"])
📤 Result Format
The library returns:
python
Copy code
{
"polyline": "<encoded_polyline_string>",
"visits": [
{"shipmentLabel": "0", ...},
{"shipmentLabel": "1", ...}
]
}
📘 Requirements
Python 3.9+
Google Cloud project with Fleet Routing API enabled
A valid Google Service Account JSON
🧩 Why This Library?
Keeps your app code clean
Avoids rewriting token / optimizeTours logic
Works with any framework or cloud provider
Ideal for logistics, delivery apps, and fleet systems
📜 License
MIT License — free for personal and commercial use.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gcp_route_optimizer-1.0.0.tar.gz.
File metadata
- Download URL: gcp_route_optimizer-1.0.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c73b113e3e17ce4f167816717b9fa0a2007025ff0e107ec95009db6e7513b4a3
|
|
| MD5 |
64a6600176a943e13f7b28b2ede49bcf
|
|
| BLAKE2b-256 |
4f315cdb7416dad98c2a9158805285c1591535b5b87f45da55652c08630108c9
|
File details
Details for the file gcp_route_optimizer-1.0.0-py3-none-any.whl.
File metadata
- Download URL: gcp_route_optimizer-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4eaec79ee4b302e76121d3714f5c108dbefe52761efec514df92e0c823cd7acc
|
|
| MD5 |
75aff4819effb86c4d1b5494c6f2e5fd
|
|
| BLAKE2b-256 |
ed39b0ae567d7fc74646f1633a36f56e98549a12487fce9b938d1e09ce59025b
|