This is a Python project that allows you to pull your data from the Oura API using a personal access token, save it to a local PostgreSQL database, then use tools like Grafana to revisualise it.
This tool was created for PERSONAL USE and such is not intended as a production-quality community tool. Use at your own risk. In my configuration, all necessary programs are running under a Rapsberry Pi running . The tool should work on other platforms such as MacOS, Windows, other Linux distriubtions. Support for other platforms will not be provided at this stage.
- Python 3.x: The project requires Python 3.x to be installed. If Python is not installed, you can download it from the official Python website: https://www.python.org/downloads/
- PostGreSQL: The project attempts to connect to a Postgres database to store its data. https://www.postgresql.org/download/
-
Open a terminal.
-
Change to the directory where you want to clone the repository.
-
Run the following command to clone the repository:
git clone https://github.com/sam-roberts/Oura-data-visualiser.git
Setting up a virtual environment is recommended to keep the project dependencies isolated. Follow these steps to set up a virtual environment:
-
Change to the project directory:
cd your-repository
-
Create a virtual environment:
python3 -m venv venv
-
Activate the virtual environment:
source venv/bin/activate
-
Ensure that the virtual environment is activated (if you set up one).
-
Install the project dependencies by running the following command:
pip install -r requirements.txt
For proper documentation, follow instructions for your platform at: https://www.postgresql.org/download/ or General instructions:
-
Update your package list and install postgres
sudo apt update && sudo apt install postgresql
-
Switch to the postgres user using
sudo -i -u postgres
-
Access the PostgreSQL terminal by running:
psql
-
Create the database you will use to host the data (by default this tool calls it 'sleepdb')
CREATE DATABASE sleepdb;
- Open the
sleep-data-config.json
file in a text editor. - Modify the configuration settings as required (e.g., database credentials, API keys).
- Save the file.
python3 sleep-data.py
The main python file will create a table for you in your specified database, and set up the fields for it automatically.
python3 sleep-data.py
Grafana allows your to visualise data from a range of sources. Follow their guide at: https://grafana.com/docs/grafana/latest/setup-grafana/installation/
Follow this guide for connecting grafana to your postgres server https://grafana.com/docs/grafana/latest/datasources/postgres/
Create a new Visualization on your main Grafana dashboard. Set the data source to PostgreSQL. Under the 'code' query builder, you can now pull out the fields you need.
SELECT score as "Sleep Score", date FROM sleep_sessions WHERE $__timeFilter(date)
- Ensure that you have followed setup instructions (above)
- Run the Python script by executing the following command:
python3 sleep-data.py
You can use a tool like cron to run the script every day.
- Add installation shell script to speed up installation.
- Look at Docker container version of tool.
- Pull in more information from Oura. At the moment only sleep data is pulled.