tcxfile
raw JSON → 1.0.4 verified Sat May 09 auth: no python
A library for reading and writing TCX (Training Center XML) files, commonly used for GPS fitness data. Current version 1.0.4, supports Python >=3.0, released under MIT license. Stable, low release cadence.
pip install tcxfile Common errors
error AttributeError: module 'tcxfile' has no attribute 'TcxReader' ↓
cause Using import tcxfile instead of from tcxfile import TcxReader
fix
Replace 'import tcxfile' with 'from tcxfile import TcxReader'
error TypeError: 'NoneType' object is not subscriptable ↓
cause Trying to read a non-existent or empty TCX file, read() returns None
fix
Check file path and existence before reading, or use tcx.read() or {}.
Warnings
gotcha TcxReader.read() returns a dictionary, not an object. Access data via dict keys like ['Activities']. ↓
fix Use tcx.read()['Activities'] to iterate over activities.
deprecated TcxWriter.write() expects a dict structure; providing an empty list will produce an invalid TCX file without an Activities element. ↓
fix Ensure the dict has an 'Activities' key containing a list of activity dicts.
gotcha TCX files may contain trackpoints with multiple extensions. tcxfile does not parse extensions by default. ↓
fix Access raw XML via TcxReader.tree if needed.
Imports
- TcxReader wrong
import tcxfile.TcxReadercorrectfrom tcxfile import TcxReader - TcxWriter wrong
import tcxfile.TcxWritercorrectfrom tcxfile import TcxWriter
Quickstart
from tcxfile import TcxReader
# Read a TCX file
tcx = TcxReader('path/to/activity.tcx')
print(tcx.read())
# Write a TCX file
from tcxfile import TcxWriter
tcx_writer = TcxWriter('output.tcx')
tcx_writer.write({'Activities': []})