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.

To upgrade an existing installation:

pip install --upgrade herohealth

Quick start

1. Configure your credentials

Create a .env file in your working directory:

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 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. Automatic account discovery is limited to observed API behavior.

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.1.1

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.1.1
File Size Uploaded Provenance Actions
herohealth-0.1.1.tar.gz 26.5 kB With provenance Details for herohealth-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 55.2 kB

Release files / herohealth-0.1.1.tar.gz

Download URL herohealth-0.1.1.tar.gz
Size 26.5 kB
Tags Source
SHA-256 checksum
How to use checksums
06157a0a297d3287f7251047c4934068472d5d65d05e93a0bc1bd68abdbcb4ab
BLAKE2b-256 checksum
How to use checksums
ab7bfdbdd13817415cd1075166c696fada5166d87ac2710fc548f18c9e0cf2ac
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.1.1-py3-none-any.whl

Download URL herohealth-0.1.1-py3-none-any.whl
Size 28.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ec18fe6275601b98dd3e7d932f3d327712a2761a014c8f4dcc62444f81aa256
BLAKE2b-256 checksum
How to use checksums
901bb0012222b6f974bc49e0da8fc599b8b3a8982bb315bd18a121af615d77a9
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.1.1

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.1.1.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