### Install from GitHub Source: http://dtcooper.github.io/python-fitparse/index.html Clone the latest version from GitHub and install it. ```bash $ git clone git@github.com:dtcooper/python-fitparse.git $ cd python-fitparse $ python setup.py install ``` -------------------------------- ### Install using pip Source: http://dtcooper.github.io/python-fitparse/index.html The easiest way to install the fitparse library is by using pip. ```bash $ pip install fitparse ``` -------------------------------- ### Install using pip Source: http://dtcooper.github.io/python-fitparse/_sources/index.rst.txt The recommended way to install the fitparse library using pip. ```bash $ pip install fitparse ``` -------------------------------- ### FitFile Initialization Examples Source: http://dtcooper.github.io/python-fitparse/api.html Demonstrates different ways to initialize a FitFile object using a file path, a file-like object, or raw bytes. ```python # 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) ``` -------------------------------- ### Clone from GitHub Source: http://dtcooper.github.io/python-fitparse/_sources/index.rst.txt Instructions to clone the fitparse repository from GitHub and install it. ```bash $ git clone git@github.com:dtcooper/python-fitparse.git $ cd python-fitparse $ python setup.py install ``` -------------------------------- ### Usage Example Source: http://dtcooper.github.io/python-fitparse/index.html A simple program to print all record fields in an activity file. ```python from fitparse import FitFile fitfile = FitFile('/home/dave/garmin-activities/2012-12-19-16-14-54.fit') # Get all data messages that are of type record for record in fitfile.get_messages('record'): # Go through all the data entries in this record for record_data in record: # Print the records name and value (and units if it has any) if record_data.units: print(" * %s: %s %s" % ( record_data.name, record_data.value, record_data.units, )) else: print(" * %s: %s" % (record_data.name, record_data.value)) print() ``` -------------------------------- ### Exception Handling Example Source: http://dtcooper.github.io/python-fitparse/api.html Shows how to catch `FitParseError` exceptions that may occur during FIT file parsing. ```python 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) ``` -------------------------------- ### Example: Print record fields from a FIT file Source: http://dtcooper.github.io/python-fitparse/_sources/index.rst.txt A Python script to parse a FIT file and print all record fields. ```python from fitparse import FitFile fitfile = FitFile('/home/dave/garmin-activities/2012-12-19-16-14-54.fit') # Get all data messages that are of type record for record in fitfile.get_messages('record'): # Go through all the data entries in this record for record_data in record: # Print the records name and value (and units if it has any) if record_data.units: print(" * %s: %s %s" % ( record_data.name, record_data.value, record_data.units, )) else: print(" * %s: %s" % (record_data.name, record_data.value)) print() ``` -------------------------------- ### DataMessage get_values() Example Source: http://dtcooper.github.io/python-fitparse/api.html Illustrates the output of the `get_values()` method on a DataMessage object, showing field names and their corresponding values. ```python >> 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) } ``` -------------------------------- ### MIT License Source: http://dtcooper.github.io/python-fitparse/index.html The software is distributed under the MIT License. ```license MIT License Copyright (c) 2011-2020, David Cooper Copyright (c) 2017-2020, Carey Metcalfe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.