A simple Python API to interact with Dexcom Share service. Used to get real-time Dexcom CGM sensor data.
The Dexcom Share service requires setup of at least one follower to enable the share service, but pydexcom
will use your (or the dependent's) credentials, not the follower's or manager's.
[!CAUTION] With the release of the Dexcom G7, users are now able to sign up with a phone number or email address.
pydexcom
originally supported authentication with usernames only. However, in the recent days (July 22, 2024) some users have had success authenticating with their phone number and email address.While this is being investigated, try first authenticating with whatever user ID you signed up with (username, email address, phone number). If that doesn't work, authenticate using your account ID. You can find your account ID by logging in to uam1.dexcom.com for US users or uam2.dexcom.com for users outside of the US. After logging in, note the UUID in the URL -- this is your account ID.
Install the pydexcom
package.
pip3 install pydexcom
Profit.
[!IMPORTANT] See the caution above.
Format phone numbers with a
+
, your country code, then your phone number, e.g. a US phone number of(123)-456-7890
would be"+11234567890"
.Format account IDs with hyphens, e.g. an account ID of
1234567890abcdef1234567890abcdef
found in the URL after logging in would be supplied as12345678-90ab-cdef-1234-567890abcdef
.
>>> from pydexcom import Dexcom
>>> dexcom = Dexcom(username="username", password="password") # `ous=True` if outside of US
>>> dexcom = Dexcom(username="+11234567890", password="password") # phone number
>>> dexcom = Dexcom(username="user@email.com", password="password") # email address
>>> dexcom = Dexcom(account_id="12345678-90ab-cdef-1234-567890abcdef", password="password")
>>> glucose_reading = dexcom.get_current_glucose_reading()
>>> print(glucose_reading)
85
>>> glucose_reading.value
85
>>> glucose_reading.mmol_l
4.7
>>> glucose_reading.trend
4
>>> glucose_reading.trend_direction
'Flat'
>>> glucose_reading.trend_description
'steady'
>>> glucose_reading.trend_arrow
'→'
>>> print(bg.datetime)
2023-08-07 20:40:58
>>> glucose_reading.json
{'WT': 'Date(1691455258000)', 'ST': 'Date(1691455258000)', 'DT': 'Date(1691455258000-0400)', 'Value': 85, 'Trend': 'Flat'}
https://gagebenne.github.io/pydexcom/pydexcom.html
The Dexcom Share API understandably reports limited information during account validation. If anything is incorrect, the API simply reports back invalid password ( pydexcom.errors.AccountErrorEnum
). However, there could be many reasons you are getting this error:
If you are located outside of the United States, be sure to set ous=True
when initializing Dexcom
.
Use the same credentials used to login to the Dexcom mobile application publishing the glucose readings.
The Dexcom Share service requires setup of at least one follower to enable the service, as does this package.
There are two account types the Dexcom Share API uses: legacy username-based accounts, and newer email-based accounts. Be sure to use the correct authentication method.
Some individuals have had problems with connecting when their Dexcom Share passwords are entirely numeric. If you have connection issues, try changing your password to something with a mix of numbers and letters.
The Dexcom Share API sometimes changes. If you believe there is an issue with pydexcom
, feel free to create an issue if one has not been created yet already.
The official Dexcom API is a great tool to view trends, statistics, and day-by-day data, but is not suitable for real time fetching of glucose readings as it is a retrospective API.
By all means submit a pull request if you have a feature you would like to see in the next release. Alternatively, you may create an issue if you have a suggestion or bug you'd like to report.
Primarily this package is used in the Home Assistant Dexcom integration, but it's fantastic to see community projects involving pydexcom
: