Dexcom has recently released a new API that enables developers to use data from their glucose sensors to create innovative apps. To get you started, here is a wrapper meant to be a starting template for your app.
https://developer.dexcom.com/
This wrapper takes care of authentication, requests, and fetching data from the 5 GET
endpoints available:
calibrations
: user's calibration events.dataRange
: user's earliest and latest times for calibration, estimated glucose value (EGV), and event records. Useful for providing start and end dates for the other endpoints.devices
: user's device information, including G4, G5, and G6 standalone receivers, the G5 and G6 mobile apps, and transmitters.egvs
: user's estimated glucose values (EGVs), including trend and status information.events
: user's event records. This includes carbohydrate intake, insulin doses, exercise, and health events that are entered in the receiver interface or through the mobile app.
- Make a Dexcom Developer account.
- Create an app on Dexcom Developer to get
CLIENT_ID
andCLIENT_SECRET
.- Go to https://developer.dexcom.com/user/me/apps
- Click "Add an App ⊕"
- Name it whatever you like and click "Create"
- In the "Redirect URI" field, write
https://localhost:8080
and click "Save"
(unless you'd like to use something else in particular) - Under "Authentication", copy the
CLIENT_ID
andCLIENT_SECRET
.
- Install
rauth
.
pip install rauth
OR
pip install -r requirements.txt
- Enter
CLIENT_ID
andCLIENT_SECRET
on lines11
and12
respectively ofapp.py
.
NOTE: If you entered a different "Redirect URI" thanhttps://localhost:8080
on step 2.iv, then change line16
. - Run application to generate tokens.
- Run
python dexcom.py
- Open the URL that's printed in the console. Sign in to your Dexcom Account.
If you don't have a Dexcom account, refer to Using Sandbox Data and repeat step 5. - Authorize the application to view your data. Check "Share Data", sign and click "Save and Continue".
- Copy the redirected URL and paste it into the console.
It will look something likehttps://localhost:8080/?code=13d9f01422495234231233bfdb123351e0f
. - EGVs should be printed to your console!
- Run
Other than for setup and reference purposes, you don't need to access api.py
. Your application implementation will be done entirely in dexcom.py
. To use the API, use the dexcomAPI
function.
dexcomAPI
takes three arguments:
endpoint
: The endpoint to use:calibrations
,dataRange
,devices
,egvs
, orevents
. All endpoints besidesdataRange
require a time window indicated by thestart
andend
parameters below.
Default:egvs
.start
: the beginning date of the time window. UsedataRange
endpoint to get the earliest time.
Default:2022-02-27T00:30:00
.end
: the ending date of the time window. UsedataRange
endpoint to get the latest time.
Default:2022-02-27T02:35:00
.
dexcomAPI
returns a JSON object. Refer to the Features section for each endpoint details.
Dexcom has provided a sandbox environment containing simulated CGM data is available for all Registered Developers to test their applications. The data in the sandbox emulates real Dexcom data, and all of the endpoints available in the production environment are also available in the sandbox environment.
To use the Sandbox data, comment out line 10
and uncomment line 9
. This makes the endpoints use the base URL of https://sandbox-api.dexcom.com/v2/
instead of https://api.dexcom.com/v2/
.
During authentication, you will be asked to select a Sandbox user. Refer to the Users section of Dexcom Developer Docs to select data that works best for your application. Once you've chosen, type your (or any) name to authorize.
- According to Dexcom Developer FAQs, the Dexcom API does NOT provide real-time estimated glucose values. All values reported by the
/egvs
endpoint are intentionally delayed by 3 hours. If you'd like real-time values, I highly recommend checking out Nightscout. - This wrapper does NOT deal with the
/statistics
endpoint. You can find more information about endpoints on Dexcom Developer Docs. - This application is simply a wrapper. It does not manipulate or analyze the Dexcom API data in any way. That is left up to you. I got bulk of the work out of the way so read up on Dexcom Developer Docs and change this application to your liking. All the best!
See the LICENSE file for license rights and limitations (MIT).
Donate, buy me a Pizza or PayPal me if you'd like to see this project expanded and support me. :)