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}')

Documentation

Requirements

  • Python 3.11+ (Tested with 3.11, 3.12)
  • C++23 Compiler

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)

gpxpy appear to be the most popular GPX library for Python.

gpxpy docs says that it uses lxml is available because it is faster than "minidom" (etree). When benchmarking that seemed not to be 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

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.

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.2.2.tar.gz (80.0 kB view details)

Uploaded Source

Built Distribution

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

fastgpx-0.2.2-cp311-cp311-win_amd64.whl (796.2 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

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

File metadata

  • Download URL: fastgpx-0.2.2.tar.gz
  • Upload date:
  • Size: 80.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for fastgpx-0.2.2.tar.gz
Algorithm Hash digest
SHA256 70b71d5917d03a7e481109b55d74ec267713a44779a543e3e0ad4f7139a866b4
MD5 10a615b0d141cb2f59e1c90c9606d353
BLAKE2b-256 2555397628b9c12126c8b48448bc8fd507da4e1395adbe998136b8e71f32002d

See more details on using hashes here.

File details

Details for the file fastgpx-0.2.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: fastgpx-0.2.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 796.2 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for fastgpx-0.2.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1e40a0105fe0230622ac4c8a7e8abcb1fc0a20d4a91378fb337091735c76f0d1
MD5 c294b510d80daf1264087ae1938de804
BLAKE2b-256 88dc4ab71d1d9b6fe761cde7e2b22c61346cfae57b158c4fdabdadd53d4b19e2

See more details on using hashes here.

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