Skip to main content

herohealth

PyPI Python CI License: MIT Typed Status

An unofficial Python SDK and command-line interface for the Hero Health smart medication dispenser.

Access your HeroConnect account, retrieve medication schedules, inspect device information, and build your own integrations using Python.

PyPI · Source code · Changelog · Report an issue

Features

  • Authentication — Sign in using your Hero account or existing OAuth tokens.
  • Medication information — Retrieve medication configurations and scheduled doses.
  • Device information — Inspect available device configuration data.
  • Account information — Access user status and available account information.
  • Automatic token refresh — Reuse cached credentials and refresh expired access tokens when possible.
  • Command-line interface — Access common functionality directly from your terminal.
  • Python typing — Includes type annotations and PEP 561 package metadata.
  • Experimental API interfaces — Explore additional observed HeroConnect endpoints.

Installation

Install from PyPI:

pip install herohealth

Requires Python 3.12, 3.13, or 3.14.

For local development, create a virtual environment and install the package in editable mode:

python3.13 -m venv .venv
source .venv/bin/activate
python -m pip install -e '.[dev]'

Copy .env.example when configuring credentials locally. Environment variables take precedence over .env.

To upgrade an existing installation:

pip install --upgrade herohealth

Quick start

1. Configure your credentials

Create a .env file in your working directory (see .env.example):

HERO_EMAIL=your-email@example.com
HERO_PASSWORD=your-password

Use your existing Hero account credentials.

Alternatively, set these values as environment variables. Existing environment variables take precedence over values in .env.

Never commit your .env file or share your credentials.

2. Connect to your account

from herohealth import HeroClient

with HeroClient() as hero:
    hero.login()

    status = hero.user.status()
    print(status)

The client automatically caches authentication tokens and manages token refresh when possible.

3. Retrieve medication information

from herohealth import HeroClient

with HeroClient() as hero:
    print(hero.home.doses())
    print(hero.meds.config_current())

These methods return data from the observed HeroConnect cloud API.

Common operations

Operation Python method
Authenticate hero.login()
Retrieve user status hero.user.status()
Retrieve scheduled doses hero.home.doses()
Retrieve medication configuration hero.meds.config_current()
Retrieve device configuration hero.device.last_d2d_config()

Additional endpoint wrappers are available as experimental interfaces. Their behavior and response schemas are not guaranteed.

Command-line interface

The herohealth command is installed automatically with the package.

Display the installed package version (no network or credentials required):

herohealth --version

Display available commands:

herohealth --help

Authenticate and cache your tokens:

herohealth login

Retrieve account information:

herohealth whoami

Retrieve scheduled doses:

herohealth home

Retrieve device configuration:

herohealth device-config

You can also call individual SDK methods:

herohealth call home.doses

Command output may contain sensitive personal or health information. Do not publish or share unredacted output.

Authentication and configuration

Configuration can be supplied through environment variables or a local .env file.

Variable Description
HERO_EMAIL Hero account email address
HERO_USERNAME Alternative to HERO_EMAIL
HERO_PASSWORD Hero account password
HERO_ACCESS_TOKEN Existing OAuth access token
HERO_REFRESH_TOKEN Existing OAuth refresh token
HERO_ACCOUNT_ID Explicit account selection

On login(), the client checks environment-provided tokens, then cached tokens at the default path, then account credentials—in that order.

Token storage

Authentication tokens are cached by default at:

~/.cache/herohealth/tokens.json

Treat this file like a password.

You can customize the cache location:

from pathlib import Path
from herohealth import HeroClient

with HeroClient(token_path=Path.home() / ".herohealth" / "tokens.json") as hero:
    hero.login()

Use a private directory and avoid storing credentials in shared or publicly accessible locations.

Multiple accounts

If your Hero account provides access to multiple accounts, configure HERO_ACCOUNT_ID or pass the account_id argument explicitly. Login raises AuthError when several accounts are visible and HERO_ACCOUNT_ID is unset.

Error handling

The library provides a shared exception hierarchy for authentication and device-operation errors.

from herohealth import AuthError, HeroClient, RateLimitError
import httpx

try:
    with HeroClient() as hero:
        status = hero.user.status()

except RateLimitError as exc:
    print("Rate limited. Stop requests until the limit clears.")
    print("Retry-After:", exc.retry_after)

except AuthError:
    print("Authentication failed.")

except httpx.HTTPError:
    print("A request to HeroConnect failed.")

Catch RateLimitError before AuthError, because it is a subclass.

Rate limits

The client does not automatically retry rate-limited requests.

If HeroConnect returns HTTP 429:

  • Respect the Retry-After value when available.
  • Otherwise, wait 15–60 minutes before making additional requests.
  • Avoid repeated authentication attempts or automated retry loops.

Requests use a 60-second timeout.

Documentation

Development

Clone the repository and install the development dependencies:

git clone https://github.com/andrewtryder/py-herohealth.git
cd py-herohealth

python -m pip install -e ".[dev]"

Run the quality checks:

make lint
make test

The test suite uses mocked services and controlled local integration tests. Automated tests must not contact live HeroConnect services or real medication dispensers.

Contributions are welcome. Please review the contributing and security policies before submitting changes.

Project status

herohealth is an early-stage, independently developed library based on observed behavior of the HeroConnect Android application.

The project aims to provide a maintainable Python interface for personal automation, integrations, and research.

Because the underlying API is unofficial and undocumented, endpoints and response formats may change without notice.

Medication and device-control operations are experimental, are not clinically validated, and must not be relied upon as the sole mechanism for medication management.

Dispensing defaults to preflight; a live start requires explicit confirmation. The dispense lock and journal only coordinate clients sharing the same private cache directory. Never automatically retry a device operation whose outcome is unknown.

Security

Please report suspected vulnerabilities privately using GitHub's vulnerability reporting.

Never include passwords, authentication tokens, account identifiers, personal health information, or unredacted network captures in public issues.

License

Released under the MIT License.


herohealth is an unofficial community project and is not affiliated with, endorsed by, or supported by Hero Health.

Metadata

Release files for herohealth 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for herohealth 0.2.0
File Size Uploaded Provenance Actions
herohealth-0.2.0.tar.gz 30.0 kB With provenance Details for herohealth-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for herohealth 0.2.0
File Interpreter ABI Platform Actions
herohealth-0.2.0-py3-none-any.whl Python 3 none any Details for herohealth-0.2.0-py3-none-any.whl

Total release size: 62.0 kB

Release files / herohealth-0.2.0.tar.gz

Download URL herohealth-0.2.0.tar.gz
Size 30.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ef20a6ff84adbbc9f708114ef1279fd46848ae3c703d77b3b878bc1d9eab9122
BLAKE2b-256 checksum
How to use checksums
8fb585bad91d293a235e5c61488cb86c0c9ef76b92a070f657759888d4988b4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / herohealth-0.2.0-py3-none-any.whl

Download URL herohealth-0.2.0-py3-none-any.whl
Size 32.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
629f16c4a5f3bd62bb4094b47474e67138ec06f9b64b8d90901c77afa84b5d2a
BLAKE2b-256 checksum
How to use checksums
b4be7016ef92df822b50f13ecb835b6ddb91c5d35f7bf3a422e55b1b2f7ef729
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for herohealth 0.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for herohealth-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page