PyGPX is a Python package that brings support for reading, writing and converting GPX files.
PyGPX is available on PyPI. Install with pip
or your package manager of choice:
pip install gpx
If you'd like, you can also install PyGPX from source (with flit
):
git clone https://github.com/sgraaf/gpx.git
cd gpx
python3 -m pip install flit
flit install
Check out the PyGPX documentation for the User's Guide and API Reference.
>>> from gpx import GPX
>>> # read the GPX data from file
>>> gpx = GPX.from_file("path/to/file.gpx")
>>> # print the bounds of the GPX data
>>> print(gpx.bounds)
>>> from gpx import Waypoint
>>>
>>> # delete the last waypoint
>>> del gpx.waypoints[-1]
>>>
>>> # add a new waypoint
>>> wpt = Waypoint()
>>> wpt.latitude = 52.123
>>> wpt.longitude = 4.123
>>> gpx.waypoints.append(wpt)
>>> # write the GPX data to a file
>>> gpx.to_file("path/to/file.gpx")