Skip to main content

An experimental Python library for parsing GPX files fast.

Project description

fastgpx

An experimental Python library for parsing GPX files fast.

# Get the total length of the tracks in a GPX file:
import fastgpx

gpx = fastgpx.parse("example.gpx")
print(f'{gpx.length_2d()} m')
# Iterate over GPX file:
import fastgpx

gpx = fastgpx.parse("example.gpx")
for track in gpx.tracks:
    print(f'Track: {track.name}')
    print(f'Distance: {track.length_2d()} m')
    if not track.time_bounds.is_empty():
      print(f'Time: {track.time_bounds().start_time} - {track.time_bounds().end_time}')
    for segment in track.segments:
        print(f'Segment: {segment.name}')
        for point in segment.points:
            print(f'Point: {point.latitude}, {point.longitude}')
import fastgpx

locations = [
    fastgpx.LatLong(64, 10),
    fastgpx.LatLong(66, 11),
]
encoded = fastgpx.polyline.encode(locations, precision=6)

decoded = fastgpx.polyline.decode(encoded, precision=6)

Documentation

Requirements

  • Python 3.12+ (Tested with 3.12, 3.13, 3.14)
  • C++23 Compiler (For building fastgpx)

Windows

  • Tested with MSVC 17.12.4+ and Clang-cl 19+.

Linux (Tested on Ubuntu)

  • C++23 compatible runtime (GCC libstdc++ 14+ or Clang libc++ 18.1+)

GPX/XML Performance (Background)

This library came out of the need to extract information from many GPX files fast.

gpxpy is the most popular GPX library for Python. It is very versatile in manipulating GPX files.

However in benchmarking it doesn't perform well.

gpxpy docs says (at time of writing) that it uses lxml is available because it is faster than "minidom" (etree).

When benchmarking that was not the case. It appear that the stdlib XML library has gotten much better since gpxpy was created.

Reference: Open ticket on making etree default: https://github.com/tkrajina/gpxpy/issues/248

fastgpx is not intended as a replacement for gpxpy. It mainly focuses on extracting GPX data fast for performance critical tasks. For the few functionalities that does overlap with gpxpy compatible method calls has been added so that one can quickly swap between fastgpx and gpxy.

Benchmarks

Test machine:

  • AMD Ryzen 7 5800 8-Core, 3.80 GHz
  • 32 GB memory
  • m2 SSD storage

gpxpy benchmarks

Comparing getting the distance of a GPX file using gpxpy vs manually extracting the data using xml_etree, computing distance between points using gpxpy distance functions.

gpxpy without lxml

Running benchmark with 3 iterations...
gpxpy 5463041.784135511 meters
gpxpy 5463041.784135511 meters
gpxpy 5463041.784135511 meters
gpxpy: 11.497863 seconds (Average: 3.832621 seconds)

gpxpy with lxml

Running benchmark with 3 iterations...
gpxpy 5463041.784135511 meters
gpxpy 5463041.784135511 meters
gpxpy 5463041.784135511 meters
gpxpy: 37.803625 seconds (Average: 12.601208 seconds)

xml_etree data extraction

Running benchmark with 3 iterations...
xml_etree 5463043.740615641 meters
xml_etree 5463043.740615641 meters
xml_etree 5463043.740615641 meters
xml_etree: 2.333200 seconds (Average: 0.777733 seconds)

Even with gpxpy using etree to parse the XML it is paster to parse it directly with etree and use gpxpy.geo distance functions to compute the distance of a GPX file. Unclear what the extra overhead is, possibly the cost of extraction additional data. (Some minor difference in how the total distance is computed in this example. Using different options for computing the distance.)

C++ benchmarks

Since XML parsing itself appear to have a significant impact on performance some popular C++ XML libraries was tested:

tinyxml2

Total Length: 5456930.710560566
Elapsed time: 0.4980144 seconds

pugixml

Total Length: 5456930.710560566
Elapsed time: 0.1890089 seconds

C++ vs Python implementations

Running 5 benchmarks with 3 iterations...

Running gpxpy ...
gpxpy: 50.182288 seconds (Average: 16.727429 seconds)

Running xml_etree ...
xml_etree: 8.269050 seconds (Average: 2.756350 seconds)

Running lxml ...
lxml: 8.479702 seconds (Average: 2.826567 seconds)

Running tinyxml (C++) ...
tinyxml (C++): 2.699880 seconds (Average: 0.899960 seconds)

Running pugixml (C++) ...
pugixml (C++): 0.381095 seconds (Average: 0.127032 seconds)

For computing the length of a GPX file, pugixml in a Python C extension was ~140 times faster than using gpxpy.

Encoding/decoding polylines

fastgpx also provide faster alternatives to polyline.encode and polyline.decode:

> uv run benchmark_polyline.py
GPX path: ../gpx/2024 Great Roadtrip
GPX files: 24
Iterations: 10

benchmarking fastgpx.polyline.encode
2.988260000005539

benchmarking polyline.encode
7.145514600000752

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastgpx-0.7.0.tar.gz (87.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fastgpx-0.7.0-cp312-abi3-win_arm64.whl (393.3 kB view details)

Uploaded CPython 3.12+Windows ARM64

fastgpx-0.7.0-cp312-abi3-win_amd64.whl (370.2 kB view details)

Uploaded CPython 3.12+Windows x86-64

fastgpx-0.7.0-cp312-abi3-win32.whl (331.1 kB view details)

Uploaded CPython 3.12+Windows x86

fastgpx-0.7.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fastgpx-0.7.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

File details

Details for the file fastgpx-0.7.0.tar.gz.

File metadata

  • Download URL: fastgpx-0.7.0.tar.gz
  • Upload date:
  • Size: 87.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastgpx-0.7.0.tar.gz
Algorithm Hash digest
SHA256 df1ae1d1497b384d562c619e44f81b10946426f776d60c995ef4db433cf551c8
MD5 c964aa4a0836238ac784a258f6f028a2
BLAKE2b-256 bcf0769447f959b7c5ce212058525d47e29e074587aba0ebad81731e70a6b995

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastgpx-0.7.0.tar.gz:

Publisher: wheels.yml on thomthom/fastgpx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastgpx-0.7.0-cp312-abi3-win_arm64.whl.

File metadata

  • Download URL: fastgpx-0.7.0-cp312-abi3-win_arm64.whl
  • Upload date:
  • Size: 393.3 kB
  • Tags: CPython 3.12+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastgpx-0.7.0-cp312-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 06259fe32c44d0efe4a0149e321eaff9dd7b490881e6784b8769ce90d57c47a7
MD5 70676d7f0c55f8663e6649401f0ab307
BLAKE2b-256 3d48d645614cf7cc8057749d2beda023353fbcd5de6c48882ce2e640718098cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastgpx-0.7.0-cp312-abi3-win_arm64.whl:

Publisher: wheels.yml on thomthom/fastgpx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastgpx-0.7.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: fastgpx-0.7.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 370.2 kB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastgpx-0.7.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 faedf420d2d396c12efbc65dd35c29911f16fde776bcfbcd7312905a73c43de3
MD5 4968d3aeac4c0bd8e6d37a5c9f3b98b2
BLAKE2b-256 3ffcd5863278a4bab33026e54607ab621eefeac68dcdc7bc7858305a59cf6605

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastgpx-0.7.0-cp312-abi3-win_amd64.whl:

Publisher: wheels.yml on thomthom/fastgpx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastgpx-0.7.0-cp312-abi3-win32.whl.

File metadata

  • Download URL: fastgpx-0.7.0-cp312-abi3-win32.whl
  • Upload date:
  • Size: 331.1 kB
  • Tags: CPython 3.12+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastgpx-0.7.0-cp312-abi3-win32.whl
Algorithm Hash digest
SHA256 f0bf4628703a0b67df92ea278ae69c0475834ae59fe2a0aded94a4fbe8ff5596
MD5 8996d6f28f443d71ad2d2b28feefd6d1
BLAKE2b-256 41b263113fe93c7774541d54fd7b37b2441022ba071e88b975d46216dc7a8a80

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastgpx-0.7.0-cp312-abi3-win32.whl:

Publisher: wheels.yml on thomthom/fastgpx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastgpx-0.7.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastgpx-0.7.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6e35cd6df9e5f914500bfc848dedfb8341a6b07bb1dfe06b98dd2f7b5e4b1d1b
MD5 9e46cfbfa4cb760feff456d36d9e3c63
BLAKE2b-256 570017be412cc800cbbc45633a6d3b170694bfb657bcdcc755e56da455b506fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastgpx-0.7.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on thomthom/fastgpx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastgpx-0.7.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for fastgpx-0.7.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 52e8160043e5adf08d049945539cf8bebd680deaae5edbbfe81e5e4ac5e2c367
MD5 8b2ffb604bbaf0d712fa8a63cb211c57
BLAKE2b-256 701df26ba3be6df9135a02ffebe33774e14c8b44c78b578c1472c1098dabdd1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastgpx-0.7.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on thomthom/fastgpx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page