Skip to main content

A Python library to extract FitBit Google Takeout data.

Project description

FitOut

GitHub license PyPI - Python Version semver GitHub tag (latest SemVer) Code style: autopep8

The FitOut project is an open source Python library for extracting FitBit data from Google Takeout.

Installation

Use pip to install:

pip install fitout

Example

How to use FitOut:

Export

Export your FitBit data, using Google Takeout.

Once the export is complete, download the zip file. I use C:/Dev/Fitbit/Google/. This directory is the takeout_dir.

Trivial Example

import fitout as fo
from datetime import date

def main():
    # Specify the location where the Takeout zip files was extracted
    takeout_dir = 'C:/Dev/Fitbit/Google/'
    # Use the NativeFileLoader to load the data from the extracted files
    # data_source = fo.NativeFileLoader(takeout_dir)
    # Use the ZipFileLoader to load data from the ZIP file directly.
    data_source = fo.ZipFileLoader(takeout_dir+"takeout-20260320T162823Z-3-001.zip")
    
    # Specify the desired date range.
    start_date = date(2024, 10, 1)
    end_date = date(2024, 10, 31)
    
    # Generate a list of dates for the date range, for informational or plotting purposes.
    dates = fo.dates_array(start_date, end_date)
    print("Dates:", dates)
    
    # Create the breathing rate importer and fetch the data.
    breather_importer = fo.BreathingRate(data_source, 1)
    breathing_data = breather_importer.get_data(start_date, end_date)
    print("Breathing rate:", breathing_data)
    
    # Create the heart rate variability importer and fetch the data.
    hrv_importer = fo.HeartRateVariability(data_source)
    hrv_data = hrv_importer.get_data(start_date, end_date)
    print("HRV:", hrv_data)
    
    # Create the resting heart rate importer and fetch the data.
    rhr_importer = fo.RestingHeartRate(data_source)
    rhr_data = rhr_importer.get_data(start_date, end_date)
    print("RHR:", rhr_data)


if __name__ == "__main__":
    main()

Plotting Example with Numpy and Matplotlib

Note: To run this example, you will need to install the dependencies:

pip install matplotlib numpy
from datetime import date
import numpy as np
import matplotlib.pyplot as plt
import fitout as fo

def main():
    # Specify the location where the Takeout zip files was extracted
    takeout_dir = 'C:/Dev/Fitbit/Google/'
    # Use the NativeFileLoader to load the data from the extracted files
    # data_source = fo.NativeFileLoader(takeout_dir)
    # Use the ZipFileLoader to load data from the ZIP file directly.
    data_source = fo.ZipFileLoader(takeout_dir+"takeout-20260320T162823Z-3-001.zip")

    # Specify the desired date range.
    start_date = date(2024, 10, 1)
    end_date = date(2024, 10, 31)

    # Generate a list of dates for the date range, for informational or plotting purposes.
    dates = fo.dates_array(start_date, end_date)

    # Create the breathing rate importer and fetch the data.
    breather_importer = fo.BreathingRate(data_source, 1)
    breathing_data = breather_importer.get_data(start_date, end_date)

    # Create the heart rate variability importer and fetch the data.
    hrv_importer = fo.HeartRateVariability(data_source)
    hrv_data = hrv_importer.get_data(start_date, end_date)

    # Create the resting heart rate importer and fetch the data.
    rhr_importer = fo.RestingHeartRate(data_source)
    rhr_data = rhr_importer.get_data(start_date, end_date)

    # Fill in missing values with the mean of the neighbouring values
    breathing_data = fo.fill_missing_with_neighbours(breathing_data)
    hrv_data = fo.fill_missing_with_neighbours(hrv_data)
    rhr_data = fo.fill_missing_with_neighbours(rhr_data)

    # Adjust buggy data (typically values that are too high or too low) to the mean of the neighbouring values
    # These values depend on your personal ranges.
    breathing_data = fo.fix_invalid_data_points(breathing_data, 10, 20)
    hrv_data = fo.fix_invalid_data_points(hrv_data, 20, 50)
    rhr_data = fo.fix_invalid_data_points(rhr_data, 46, 54)

    # Convert lists to numpy arrays
    dates_array = np.asarray(dates)
    breathing_data_array = np.array(breathing_data).astype(float)
    hrv_data_array = np.array(hrv_data).astype(float)
    rhr_data_array = np.array(rhr_data).astype(float)


    # Create a combined calmness index as follows: 100-(RHR/2 + breathing rate*2 - HRV)
    calmness_index = 100 - (rhr_data_array / 2. + breathing_data_array * 2. - hrv_data_array)

    # Plot the calmness index
    plt.figure(figsize=(10, 6))
    plt.plot(dates_array, calmness_index, marker='o', linestyle='-', color='b')
    plt.xlabel('Date')
    plt.ylabel('Calmness Index')
    plt.title('Calmness Index Over Time')
    plt.ylim(60, 95)  # Set the y-range
    plt.grid(True)
    plt.xticks(rotation=45)
    plt.tight_layout()  
    # Fit a 4th order polynomial to the calmness index data
    dates_axis = np.arange(len(dates_array))
    polynomial_coefficients = np.polyfit(dates_axis, calmness_index, 4)
    polynomial = np.poly1d(polynomial_coefficients)
    fitted_calmness_index = polynomial(dates_axis)

    # Plot the fitted polynomial
    plt.plot(dates_array, fitted_calmness_index, linestyle='--', color='r', label='4th Order Polynomial Fit')
    plt.legend()

    plt.show()

    plt.show()
if __name__ == "__main__":
    main()

More Examples

For more examples, see the examples directory.

Contributing

If you'd like to contribute to FitOut, follow the guidelines outlined in the Contributing Guide.

License

See LICENSE.txt for more information.

Contact

For inquiries and discussion, use FitOut Discussions.

Issues

For issues related to this Python implementation, visit the Issues page.

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

fitout-0.3.1.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

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

fitout-0.3.1-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file fitout-0.3.1.tar.gz.

File metadata

  • Download URL: fitout-0.3.1.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fitout-0.3.1.tar.gz
Algorithm Hash digest
SHA256 b56f7785e72ddbb5d524086551ffacbc29ca90c2e7d0bd37c95088df94ab9e3f
MD5 f2f60ea96f5e0d4169804ad6fe937bcb
BLAKE2b-256 67f44774d6d669d60e88c7af1f7c191bfd184cb5dc46736ea149a5dfd49acc28

See more details on using hashes here.

Provenance

The following attestation bundles were made for fitout-0.3.1.tar.gz:

Publisher: python-publish.yml on kev-m/FitOut

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fitout-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: fitout-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fitout-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 41713129ac6945d67ebefe482d4b3b38816a0d5322b7010f03362553a96499ca
MD5 ac12883fb884417736a422ad32bd0ad9
BLAKE2b-256 5a24fddb0d5ca95d7e72764137d9efdecd7fb6c3dc3a52b4f75b176f2b601c7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fitout-0.3.1-py3-none-any.whl:

Publisher: python-publish.yml on kev-m/FitOut

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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