Python library
The hamapi Python package downloads the historical data (datalogs) of your devices.
It reads the rows for you and gives one list of values for each reading.
You can use it freely (MIT license).
Install
Section titled “Install”pip install hamapiYou need Python 3.6 or later. The package also installs requests and brotli.
Example
Section titled “Example”import timeimport hamapi
ham = hamapi.hamapi(api_key='YOUR_API_KEY')
end = int(time.time())start = end - 7 * 86400
data = ham.get_datalog_data('e11:123', start, end, averaging_step=120)print(list(data.keys()))print(data['timestamp'][:5])api_key: you get it from the Account page of the app. See the REST API.'e11:123': the serial number of the device. You need read permission on the device.start,end: Unix time in seconds.averaging_step: optional. The package gives one average value for each step of this many seconds. With0(the default) you get all the rows.
The result
Section titled “The result”get_datalog_data returns a dictionary:
timestamp: the time of each value, in Unix seconds.- One list for each reading and each output of the device, with the reading code as the key (for example
T). The codes are in the Readings dictionary.
All lists have the same length. Without averaging_step, the lists have one more point just before each change, so that a plot shows steps.
Other functions
Section titled “Other functions”ham.get_user_devices(): the devices of your account, the same data asget_user_devices.php.
- The package keeps the downloaded past days in the file
.cached.db, in the current folder. It does not download these days again. To download them again, delete the file. - The package reads only the history. For live data, use the WebSocket.
- The package contains the device definitions of its version. For new device types, update it with
pip install -U hamapi. - Package page: pypi.org/project/hamapi.

