Gaggiuino REST API Wrapper for Python
- Repository: https://github.com/ALERTua/gaggiuino_api
- Changelog: https://github.com/ALERTua/gaggiuino_api/releases
- PyPi: https://pypi.org/project/gaggiuino_api/
- Home Assistant HACS Integration: https://github.com/ALERTua/hass-gaggiuino
- Gaggiuino REST API Documentation: https://github.com/GAGGIUINO/gaggiuino.github.io/tree/main/docs/rest-api
gaggiuino_api is an async Python client for the REST API of the firmware of a Gaggiuino espresso machine. It uses aiohttp and typed models.
The client covers the live status, the saved profiles, the shot history, the settings, the maintenance history, the firmware update and the health check. Each failure raises an exception. No method returns None for a failure.
Requirements
- Python 3.14.2 or newer.
- A Gaggiuino machine on your network. The default address is
http://gaggiuino.local. - Firmware
c929939or newer. Get it from the releasemain-c929939.
One version of this library supports one iteration of the REST API of the firmware. It does not support each firmware. Version 1.0 supports the iteration of firmware c929939. When the firmware author changes the REST API, a new version of the library follows. That version names the newer firmware and requires it. The package has the constant MINIMUM_FIRMWARE with this value. Pin an exact version of the library in an application that must keep working with one firmware. The Home Assistant integration hass-gaggiuino does this.
Install
pip install gaggiuino_api
Quick start
import asyncio
from gaggiuino_api import GaggiuinoClient
async def main():
async with GaggiuinoClient("http://gaggiuino.local") as machine:
status = await machine.status()
print(
f"{status.profile_name}: {status.temperature:.1f} C, {status.pressure:.1f} bar"
)
asyncio.run(main())
Output:
Morning blend: 23.1 C, 0.1 bar
Use the client as an async context manager. You can also call await machine.connect() and await machine.close() yourself. The client keeps no cached state of the machine. Each call asks the machine.
Examples
Status
status() returns a Status with 46 fields. A few of them are temperature, pressure, weight, operation_mode, brew_active, profile_id and profile_name. See the Status class for the full list.
status = await machine.status()
print(status.operation_mode, status.brew_active, status.weight)
Output:
HOME False 0.0
Profiles
profiles = await machine.profiles.list()
for summary in profiles:
print(summary.id, summary.name, summary.selected)
profile = await machine.profiles.get(profiles[0].id)
for phase in profile.phases:
print(phase.type, phase.target)
Output:
7 Morning blend False
12 Flush True
FLOW PhaseTarget(start=None, end=0.0, curve=<CurveType.LINEAR: 'LINEAR'>, time=None, volume=None)
profiles.list() returns ProfileSummary objects with id, name and selected. Only profiles.get() returns the phases. Select, create and delete a profile:
await machine.profiles.select(7)
created = await machine.profiles.create(profile)
print(created.id, created.name)
await machine.profiles.delete(created.id)
profiles.select() and profiles.delete() take an id or a model that has an id. profiles.get() takes an id. profiles.create() always saves a new profile with a new id and does not select it.
Warning about the delete: firmware c929939 answers HTTP 200 to a delete of an id that it does not have. In a test, such a request removed another saved profile. So profiles.delete() reads the list of the profiles first. For an id that the list does not have, it raises GaggiuinoNotFoundError and sends no delete request. A profiles.select() of a missing profile raises GaggiuinoResponseError with status 500, because the machine does not answer 404 there.
Shots
latest_id = await machine.shots.latest_id()
shot = await machine.shots.get(latest_id)
print(shot.id, shot.duration / 10, "s", shot.profile.name)
print(max(shot.datapoints.pressure) / 10, "bar at peak")
Output:
580 74.1 s Morning blend
9.3 bar at peak
The duration and each datapoint value are integers scaled by 10. To delete the data of a shot, call await machine.shots.delete(latest_id). This cannot be undone.
Settings
settings = await machine.settings.get()
print(settings.display.lcd_brightness)
boiler = await machine.settings.boiler.get()
print(boiler.steam_set_point)
versions = await machine.settings.versions()
print(versions.core_version)
Output:
61
125
c929939
The groups are boiler, system, led, scales, display and theme. Each group has get(), update() and update_from():
await machine.settings.boiler.update(steam_set_point=130)
boiler = await machine.settings.boiler.get()
await machine.settings.boiler.update_from(boiler)
An update reads the whole group from the machine, changes only the fields that you name, and sends the whole group back. Two concurrent updates of the same group of one client run one after the other, so no change is lost between them. A write of another client or of the web UI of the machine between the read and the send can still lose a change. Keys that the library does not know stay as they are. A name that the group model does not have raises TypeError before any request. The group webUi is read-only inside settings.get(). See UNSUPPORTED.md.
Maintenance
maintenance = await machine.maintenance()
print(maintenance.shots_since_descale, maintenance.shots_since_backflush)
Output:
11 11
Firmware
progress = await machine.firmware.progress()
print(progress.status, progress.type, progress.progress)
Output:
IDLE C_FW 0
await machine.firmware.update() starts an update of the firmware and returns at once. It sends no body. The machine restarts during the update. The call starts a real update, so use it with care.
Health
print(await machine.healthy())
Output:
True
healthy() raises GaggiuinoConnectionError or GaggiuinoConnectionTimeoutError when the machine does not answer. Catch these two errors to poll a machine through a restart.
Errors
GaggiuinoError is the base class of each error that the library raises.
| Exception | When |
|---|---|
GaggiuinoConnectionError |
The connection to the machine failed. |
GaggiuinoConnectionTimeoutError |
The machine did not answer in time. |
GaggiuinoResponseError |
The machine answered with an HTTP error status. It has status and body. |
GaggiuinoNotFoundError |
A subclass of GaggiuinoResponseError for HTTP 404. |
GaggiuinoCommandError |
The machine answered with "success": false, or with the string "false" in any letter case. It has status, the HTTP status of the answer. |
GaggiuinoResponseFormatError |
The answer does not have the expected format. |
from gaggiuino_api import (
GaggiuinoClient,
GaggiuinoConnectionError,
GaggiuinoNotFoundError,
GaggiuinoResponseError,
)
try:
async with GaggiuinoClient("http://gaggiuino.local") as machine:
await machine.shots.get(999999)
except GaggiuinoNotFoundError as err:
print("No such shot:", err.status)
except GaggiuinoResponseError as err:
print("The machine answered", err.status)
except GaggiuinoConnectionError:
print("The machine is not reachable")
Output:
No such shot: 404
Shared session and timeout
Give your own aiohttp session to share it with the rest of your application. The client does not close a session that you give. The timeout is in seconds, or an aiohttp.ClientTimeout. The default is 5 seconds. The timeout of the client replaces the timeout of a session that you give. A number of zero or less, or a number that is not finite, raises ValueError; an aiohttp.ClientTimeout object passes unchanged. The client maps each error status itself, so a raise_for_status setting or hook of your session does not run for its requests. A call after close() opens a new own session, so call close() again after it.
import aiohttp
async with aiohttp.ClientSession() as session:
machine = GaggiuinoClient("http://gaggiuino.local", session=session, timeout=10)
print(await machine.healthy())
print((await machine.status()).core_version)
Output:
True
c929939
More documents
- MIGRATION.md lists each name that changed since version 0.x.
- UNSUPPORTED.md lists the features that the library leaves out on purpose.
- docs/firmware-undocumented-fields.md lists the keys that the firmware sends and the upstream documentation does not describe.
- docs/firmware-ambiguous-fields.md lists the keys with an unclear meaning and the differences between the documentation and the machine.
Tests
Run the unit tests:
uv run pytest test
The end-to-end tests need a real machine. They are deselected by default. Set GAGGIUINO_BASE_URL if the machine is not at http://gaggiuino.local.
uv run pytest -m e2e test/e2e
These tests write only the led and display settings groups. They delete only the profile copy that they created. They never send a delete for an id that the machine does not have. They never call firmware.update() and never delete a shot.
Metadata
Release files for gaggiuino_api 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gaggiuino_api-1.0.0.tar.gz | 38.1 kB | Without provenance | Details for gaggiuino_api-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gaggiuino_api-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for gaggiuino_api-1.0.0-py3-none-any.whl |
Total release size: 80.0 kB
Release files / gaggiuino_api-1.0.0.tar.gz
| Download URL | gaggiuino_api-1.0.0.tar.gz |
|---|---|
| Size | 38.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cf4c18435bf2637482c705544d473afbe2d82c17ed818aa2947819459d2b4f28
|
|
BLAKE2b-256 checksum How to use checksums |
450d1406100519893ed65daf14eaccbc4fb0ea2c145c771d8adf0e3bf599eae4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / gaggiuino_api-1.0.0-py3-none-any.whl
| Download URL | gaggiuino_api-1.0.0-py3-none-any.whl |
|---|---|
| Size | 41.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7071f3af022c13f701bd17bb45e368720c5f89a8813eb092f9dd264bad738030
|
|
BLAKE2b-256 checksum How to use checksums |
a5be9e2be646a089d489a061475aea3de10e3cf5297056dc505718ce7b92249f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for gaggiuino_api 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.