Fast Google Polyline encoding and decoding using Rust
Actively maintained. Last release 7 weeks ago, commits in 13 of the last 26 weeks. A safe choice.
pip install pypolylineFast Google Polyline Encoding and Decoding
Installation
uv add pypolyline
pip install pypolyline
Installing for local development
- Ensure you have a Rust toolchain installed
- run
uv sync --dev(this builds the extension using maturin) - run
uv run pytest
Changes to Cargo.toml, Cargo.lock, or any .rs file will bust the cache, triggering a rebuild when uv commands are run.
Supported Python Versions
All currently supported Python versions.
Binary wheels target the CPython Stable ABI (abi3): a single abi3 wheel per platform covers CPython 3.11 and later.
Supported Platforms
- Linux (
manylinux*-compatible, x86_64 and aarch64) - macOS (x86_64 and arm64)
- Windows 64-bit
Usage
Coordinates must be in (Longitude, Latitude) order, and can be any sequence of (x, y) pairs, or an (N, 2) NumPy array (or any other object supporting the buffer protocol). Polylines can be bytes or str. NumPy is not required.
from pypolyline.cutil import encode_coordinates, decode_polyline
coords = [
[52.64125, 23.70162],
[52.64938, 23.70154],
[52.64957, 23.68546],
[52.64122, 23.68549],
[52.64125, 23.70162]
]
# precision is 5 for Google Polyline, 6 for OSRM / Valhalla
polyline = encode_coordinates(coords, 5)
# polyline is 'ynh`IcftoCyq@Ne@ncBds@EEycB'
decoded_coords = decode_polyline(polyline, 5)