fitbit-data-pipeline
A pipeline that automate Fitbit OAuth2 authorisation and collects sleep, activity and heart rate data from Fitbit devices
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.1%) to scientific vocabulary
Keywords
Scientific Fields
Repository
A pipeline that automate Fitbit OAuth2 authorisation and collects sleep, activity and heart rate data from Fitbit devices
Basic Info
- Host: GitHub
- Owner: sleepdetectives
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://zenodo.org/records/15351924
- Size: 509 KB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 1
Topics
Metadata Files
README.md
Fitbit Data Collector
This is a Python package that automate Fitbit OAuth2 authorisation and collect sleep, activity and heart rate data from fitbit devices
Features
- OAth2-based Fitbit authentication (per participant)
- Participant information supplied in a CSV file
- Device-to-participant assignment and session tracking
- Sleep, activity and heart rate data collection
- Save Sleep, activity and heart rate to csv
project structure
FitbitDataPipeline - fitbitpipeline - Classes - runner - Utility - logs/ # application logs - processeddata: Folder containing the pipeline output - Sleep Summary, Sleep Staging, Activity and Heartrate data - rawsleepdata : raw sleep json file from Fitbit Web API - tokens : Locally managed Fitbit user tokens - appserver - Flask app for the Fitbit OAuth2 - authcode - Application generated for the exchange of the redirect url after authentication - config - contain some user configurations and fitbit WebAPI endpoint URLs - License - participants.csv - readme - This file - requirements : Required packages to successfully run the application
Requirement
Aside the packages required as specified in the requirements file. The following are also needed to run this pipeline - Core - Python 3.8+ - Fitbit developer account - API client ID and secret (ensure intraday data access is enabled using require a separate application)
Getting Started
Running from the Source (GitHub)
- Clone the repository
git clone https://github.com/sleepdetectives/fitbit-data-pipeline.git cd FitbitDataPipeline - Set up a virtual environment (Optional)
python -m venv venv source venv/bin/activate - Install Dependencies
pip install -r requirements.txt## Running as a Python Package - Create a new project or use an existing one
- Head on to your terminal to install the package
pip install fitbit-data-pipeline - Install poetry package based on your platform(OS)
- After performing the preparing environment and configuration steps (See below):
- Start the app_server using
poetry run fitbit-auth - Start the main data collection process
poetry run fitbit-app
Preparing Environment and Configurations
- Add the participant file (participants.csv) to the project root folder with the following structure:
####### participants file
pid,age,fitbitid,devicemodel,studyperiod,collectiondates
ABC02,10,Z4XX11,Inspire 3,"2024-11-05,2024-11-13",2024-11-05;2024-11-06;2024-11-07;2024-11-08;2024-11-09;2024-11-10;2024-11-11;2024-11-12;2024-11-13
- create .env file in the project root and populate it with your fitbit developer account client id and secret
######### .env file
clientid = "XXXXX" clientsecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- Create a copy of sample_files\config.py file and place in the project root folder
Note: sample files needed for the above are included in the "sample_files" directory
Output Files
- allsleepdata :
....fig 1
The light green background columns are out-of-the-box while the light blue category are derived. Detailed as follows:
SOL - I looked at first sleep staging , if the first sleep staging is wake then followed by any of light, deep or REM then there is SOL, otherwise, no SOL
.....fig 2
WASO = MinutesAwake - SOL (Fitbit claimed that raw minutes awake does not include awake before first sleep episode or after wakeup) - sleeptime - From fig 2 above the sample from the left had the SOL hence differentiating "StartTime" from "sleeptime"
- wake_time - Checking the last two entry in the sleep staging could give an idea of actual wake time. If the last episode is wake, most likely, the participant spend some time in bed after wake

- TST = timediff(sleeptime, wake_time) - WASO
- SE = TST/TimeInBed * 100 Note: Fitbit advised that only SE from "classic log type" is valid and this should be ignored for stages log type (even though a value will be provided) # License This project is licensed under the MIT License
Contributing
Pull request are highly welcome! Please open an issue first to discuss your idea
Contact
For questions or support, reach out to: abiola.saka@bristol.ac.uk or sakbioonline@gmail.com
Owner
- Login: sleepdetectives
- Kind: user
- Repositories: 1
- Profile: https://github.com/sleepdetectives
Citation (citation.cff)
message: "If you use this pipeline, please cite it as below:" title: "An Open Pipeline for Longitudinal Sleep and Activity Extraction form Fitbit Devices" authors: - family-names: "Saka" given-names: "Abiola" affiliation: "University of Bristol" orcid: "https://orcid.org/0009-0002-0881-065X" date-released: 2025-04-29 version: 1.0.1 doi: 10.5281/zenodo.15351924
GitHub Events
Total
- Release event: 3
- Watch event: 1
- Push event: 6
- Create event: 3
Last Year
- Release event: 3
- Watch event: 1
- Push event: 6
- Create event: 3
Dependencies
- blinker 1.9.0
- certifi 2025.4.26
- cffi 1.17.1
- charset-normalizer 3.4.2
- click 8.1.8
- colorama 0.4.6
- cryptography 44.0.3
- exceptiongroup 1.2.2
- flask 3.1.0
- idna 3.10
- iniconfig 2.1.0
- itsdangerous 2.2.0
- jinja2 3.1.6
- markupsafe 3.0.2
- numpy 2.2.5
- oauthlib 3.2.2
- packaging 25.0
- pandas 2.2.3
- pluggy 1.5.0
- pycparser 2.22
- pytest 7.4.4
- python-dateutil 2.9.0.post0
- python-dotenv 1.1.0
- pytz 2025.2
- requests 2.32.3
- requests-oauthlib 2.0.0
- six 1.17.0
- tomli 2.2.1
- tzdata 2025.2
- urllib3 2.4.0
- werkzeug 3.1.3
- pytest ^7.0 develop
- Flask >=3.1,<4.0
- cffi >=1.17,<2.0
- cryptography >=44.0,<45.0
- numpy >=2.2,<3.0
- pandas >=2.2,<3.0
- python >=3.10,<3.13
- python-dateutil >=2.8
- python-dotenv >=1.0
- requests >=2.32,<3.0
- requests-oauthlib >=2.0,<3.0