Skip to main content
http://img.shields.io/pypi/v/polyline.svg?style=flat Documentation Status Build

polyline is a Python implementation of Google’s Encoded Polyline Algorithm Format. It is essentially a port of Mapbox polyline with some additional features.

Installation

polyline can be installed using pip:

$ pip install polyline

Starting from v2.0.0 only Python 3.7 and above is supported. For Python 2 support, please install v1.4.0:

$ pip install polyline==1.4.0

API Documentation

Encoding

To get the encoded polyline representation of a given set of (lat, lon) coordinates:

import polyline
polyline.encode([(38.5, -120.2), (40.7, -120.9), (43.2, -126.4)], 5)

This should return _p~iF~ps|U_ulL~ugC_hgN~eq`@.

You can set the required precision with the optional precision parameter. The default value is 5.

You can encode (lon, lat) tuples by setting geojson=True.

Decoding

To get a set of coordinates represented by a given encoded polyline string:

import polyline
polyline.decode('u{~vFvyys@fS]', 5)

This should return [(40.63179, -8.65708), (40.62855, -8.65693)] in (lat, lon) order.

You can set the required precision with the optional precision parameter. The default value is 5.

You can decode into (lon, lat) tuples by setting geojson=True.

Development

All installation and development dependencies are fully specified in pyproject.toml. The project.optional-dependencies object is used to specify optional requirements for various development tasks. This makes it possible to specify additional options when performing installation using pip:

python -m pip install .[dev]

Documentation

The documentation can be generated automatically from the source files using Sphinx:

python -m sphinx.cmd.build -b html docs docs/_build/html

Testing and Conventions

All unit tests are executed and their coverage is measured when using pytest:

python -m pytest

Style conventions are enforced using Pylint:

python -m pylint polyline

Contributions

In order to contribute to the source code, open an issue or submit a pull request on the GitHub page for this library.

Versioning

Beginning with version 0.1.0, the version number format for this library and the changes to the library associated with version number increments conform with Semantic Versioning 2.0.0.

Publishing

This library can be published as a package on PyPI by a package maintainer. Ensure that the correct version number appears in pyproject.toml, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an automation rule that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ?.?.? with the version number):

git tag ?.?.?
git push origin ?.?.?

Remove any old build/distribution files. Then, package the source into a distribution archive:

rm -rf build dist src/*.egg-info
python -m build --sdist --wheel .

Finally, upload the package distribution archive to PyPI:

python -m twine upload dist/*

Release files for polyline 2.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polyline 2.0.4
File Size Uploaded
polyline-2.0.4.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for polyline 2.0.4
File Interpreter ABI Platform
polyline-2.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 15.4 kB

Release files / polyline-2.0.4.tar.gz

Download URL polyline-2.0.4.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f05ade694522bf1720febebe1672f820f43a13c6a1664751e7769d47e8ca9b1b
BLAKE2b-256 checksum
How to use checksums
2cc11a6ee4f9f02a55b2a9241bbadd342970160f7e42423307f21ee8f5530d4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release files / polyline-2.0.4-py3-none-any.whl

Download URL polyline-2.0.4-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4e0c15b8ecb32915559f8cf210f1f8c2f5cc53d3cd32c91d7c1668d6e936e10
BLAKE2b-256 checksum
How to use checksums
34a84ebd3cb31d380e018efb1c8bf92664b196a41aba19506015b682af2587b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release history Release notifications | RSS feed

This release

2.0.4 This release

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.4.0

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3

2 release files

1.2.1

2 release files

1.2

2 release files

1.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page