The fitparse API Documentation¶
The FitFile Object¶
-
class
fitparse.FitFile(fileish, check_crc=True, data_processor=None)¶ Interface for reading a
.FITfile.Provided a
.FITfile fileish, this is the main interface to parsing a.FITfile and reading its data.- Parameters
fileish –
A file path, file-like object, or a string of bytes representing FIT data to be read.
Note
Usage Notes
All of the following work with the fileish parameter:
# Specifying a file path fitfile = FitFile('/path.to/fitfile.fit') # Providing a file-like object file_obj = open('/path.to/fitfile.fit', 'rb') fitfile = FitFile(file_obj) # Providing a raw string of bytes file_obj = open('/path.to/fitfile.fit', 'rb') raw_fit_data = file_obj.read() fitfile = FitFile(raw_fit_data)
check_crc – Set to
Falseif to disable CRC validation while reading the current.FITfile.data_processor – Use this parameter to specify an alternate data processor object to use. If one is not provided, an instance of
FitFileDataProcessorwill be used.
- Raises
Creating a
FitFilemay raise aFitParseErrorexception. See the note on exceptions.
-
get_messages(name=None, with_definitions=False, as_dict=False)¶ TODO: document and implement
-
parse()¶ Parse the underlying FIT data completely.
- Raises
May raise a
FitParseErrorexception.
Warning
Note on Exceptions While Parsing a
.FITFileIn general, any operation on a that
FitFilethat results in parsing the underlying FIT data may throw aFitParseErrorexception when invalid data is encountered.One way to catch these before you start reading going through the messages contained in a
FitFileis to callparse()immediately after creating aFitFileobject. For example:import sys from fitparse import FitFile, FitParseError try: fitfile = FitFile('/path.to/fitfile.fit') fitfile.parse() except FitParseError, e: print "Error while parsing .FIT file: %s" % e sys.exit(1)
Any file related IO exceptions caught during a read() or close() operation will be raised as usual.
-
messages¶ The complete list of
DataMessagerecord objects that are contained in thisFitFile. This list is provided as a convenience attribute that wrapsget_messages(). It is functionally equivalent to:class FitFile(object): # ... @property def messages(self): return list(self.get_messages())
- Raises
Reading this property may raise a
FitParseErrorexception. See the note on exceptions.
-
profile_version¶ The profile version of the FIT data read (see ANT FIT SDK for)
-
protocol_version¶ The protocol version of the FIT data read (see ANT FIT SDK)
Record Objects¶
Common Used Record Objects¶
-
class
fitparse.DataMessage¶ A list of DataMessage objects are returned by
FitFile.get_messages()andFitFile.messages. These are not meant to be created directly.-
fields¶ A list of
FieldDataobjects representing the fields contained in this message.
-
get(field_name, as_dict=False)¶ Returns a
FieldDatafor field field_name if it exists, otherwise None. If as_dict is set to True, returns a dict representation of the field (seeFieldData.as_dict())
-
get_value(field_name)¶ Returns the value of field_name if it exists, otherwise None
-
get_values()¶ Return a dict mapping of field names to their values. For example:
>> data_message.get_values() { 'altitude': 24.6, 'cadence': 97, 'distance': 81.97, 'grade': None, 'heart_rate': 153, 'position_lat': None, 'position_long': None, 'power': None, 'resistance': None, 'speed': 7.792, 'temperature': 20, 'time_from_course': None, 'timestamp': datetime.datetime(2011, 11, 6, 13, 41, 50) }
-
as_dict()¶ TODO: document me
-