Registry / serialization / polyline

polyline

JSON →
library2.0.4pypypi✓ verified 25d ago

The `polyline` library is a Python implementation of Google's Encoded Polyline Algorithm Format. It provides functionality to encode a list of latitude/longitude coordinates into a compact polyline string and to decode such a string back into coordinates. The library is actively maintained, with the current stable version being 2.0.4, and is released on an as-needed basis for bug fixes and feature enhancements.

pip install polyline
INSTALL
IMPORT
SIG · POLYLINE
P
polyline
serializationpythonv2.0.4
Install
1.5s avg
Import
11ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.012s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.006s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

encode
from polyline import encode
import polyline
decode
from polyline import decode
import polyline

This quickstart demonstrates encoding a list of `(latitude, longitude)` tuples into a polyline string and then decoding it back. It also shows how to handle GeoJSON-style `(longitude, latitude)` order using the `geojson=True` parameter and how to specify a custom precision.

import polyline # Example coordinates: (latitude, longitude) coords = [ (38.5, -120.2), (40.7, -120.9), (43.2, -126.4) ] # Encode coordinates into a polyline string with default precision (5) encoded_polyline = polyline.encode(coords) print(f"Encoded Polyline: {encoded_polyline}") # Decode the polyline string back to coordinates decoded_coords = polyline.decode(encoded_polyline) print(f"Decoded Coordinates: {decoded_coords}") # Example with GeoJSON style (lon, lat) and custom precision geojson_coords = [ (-120.2, 38.5), (-120.9, 40.7), (-126.4, 43.2) ] encoded_geojson = polyline.encode(geojson_coords, precision=6, geojson=True) print(f"Encoded GeoJSON Polyline (precision 6): {encoded_geojson}") decoded_geojson = polyline.decode(encoded_geojson, precision=6, geojson=True) print(f"Decoded GeoJSON Coordinates (precision 6): {decoded_geojson}")
Debug
Known issues
breakingVersion 2.0.0 and above of `polyline` only supports Python 3.7+. For applications requiring Python 2 support, you must install version 1.4.0.
fix
Upgrade to Python 3.7+ or pin the `polyline` library version to 1.4.0 (e.g., `pip install polyline==1.4.0`).
affects: >=2.0.0
gotchaThe `polyline` library uses `(latitude, longitude)` order by default for `encode` input and `decode` output, which is common in GIS but differs from the `(longitude, latitude)` order used in GeoJSON standards.
fix
Use the `geojson=True` parameter in both `polyline.encode()` and `polyline.decode()` to work with `(longitude, latitude)` coordinate tuples.
affects: All
gotchaThe `precision` parameter (defaulting to 5) must be consistent between encoding and decoding operations to ensure accurate round-tripping of coordinates.
fix
Explicitly set the `precision` parameter during both `encode` and `decode` if a non-default precision is desired or expected.
affects: All
gotchaWhen loading polyline strings from external sources like CSV files, be mindful of backslash escaping. Python's CSV reader or other parsing mechanisms might interpret `\` differently, leading to corrupted polyline strings.
fix
Ensure that backslashes in the polyline string are correctly escaped or unescaped during parsing. For example, if a `\\` in a CSV becomes `\` in Python, you might need `.replace('\\','\')` before decoding.
affects: All
Upgrade
Version history
2.0.4latest on PyPI · released Dec 2, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Resources
polyline — pip install polyline · libregistry