Skip to content

A wrapper meant to be a starting point for Python applications using the Dexcom API.

License

Notifications You must be signed in to change notification settings

Prince25/Dexcom-API-Wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dexcom API Wrapper

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/

Features

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.

Setup

  1. Make a Dexcom Developer account.
  2. Create an app on Dexcom Developer to get CLIENT_ID and CLIENT_SECRET.
    1. Go to https://developer.dexcom.com/user/me/apps
    2. Click "Add an App ⊕"
    3. Name it whatever you like and click "Create"
    4. In the "Redirect URI" field, write https://localhost:8080and click "Save"
      (unless you'd like to use something else in particular)
    5. Under "Authentication", copy the CLIENT_ID and CLIENT_SECRET.
  3. Install rauth.
    pip install rauth
    OR
    pip install -r requirements.txt
  4. Enter CLIENT_ID and CLIENT_SECRET on lines 11 and 12 respectively of app.py.
    NOTE: If you entered a different "Redirect URI" than https://localhost:8080 on step 2.iv, then change line 16.
  5. Run application to generate tokens.
    1. Run python dexcom.py
    2. 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.
    3. Authorize the application to view your data. Check "Share Data", sign and click "Save and Continue".
    4. Copy the redirected URL and paste it into the console.
      It will look something like https://localhost:8080/?code=13d9f01422495234231233bfdb123351e0f.
    5. EGVs should be printed to your console!

Usage

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, or events. All endpoints besides dataRange require a time window indicated by the start and end parameters below.
    Default: egvs.
  • start: the beginning date of the time window. Use dataRange endpoint to get the earliest time.
    Default: 2022-02-27T00:30:00.
  • end: the ending date of the time window. Use dataRange 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.

Using Sandbox Data

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.

Limitations

  • 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!

License

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. :)

Paypal me

Buy Me A Coffee Paypal me

About

A wrapper meant to be a starting point for Python applications using the Dexcom API.

Topics

Resources

License

Stars

Watchers

Forks

Languages