Metadata-Version: 2.5
Name: herohealth
Version: 0.1.2
Summary: An unofficial Python SDK and CLI for the Hero Health smart medication dispenser and HeroConnect cloud API.
Project-URL: Homepage, https://github.com/andrewtryder/py-herohealth
Project-URL: Repository, https://github.com/andrewtryder/py-herohealth
Project-URL: PyPI, https://pypi.org/project/herohealth/
Project-URL: Issues, https://github.com/andrewtryder/py-herohealth/issues
Project-URL: Documentation, https://github.com/andrewtryder/py-herohealth#readme
Project-URL: Changelog, https://github.com/andrewtryder/py-herohealth/blob/main/CHANGELOG.md
License-Expression: MIT
License-File: LICENSE
Keywords: api-client,healthcare,heroconnect,herohealth,home-automation,iot,medication-dispenser,oauth2,python-library,python-sdk,reverse-engineering,smart-home
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: <3.15,>=3.12
Requires-Dist: filelock<5,>=4.3.1
Requires-Dist: httpx<1,>=0.29.0
Requires-Dist: python-dotenv<2,>=1.2.4
Requires-Dist: websockets<18,>=17.4
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: mypy==2.4.1; extra == 'dev'
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: pytest-cov>=7.1.0; extra == 'dev'
Requires-Dist: pytest>=9.2.0; extra == 'dev'
Requires-Dist: ruff==0.17.6; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Requires-Dist: zizmor==1.33.1; extra == 'dev'
Description-Content-Type: text/markdown

# herohealth

[![PyPI](https://img.shields.io/pypi/v/herohealth)](https://pypi.org/project/herohealth/)
[![Python](https://img.shields.io/pypi/pyversions/herohealth)](https://pypi.org/project/herohealth/)
[![CI](https://github.com/andrewtryder/py-herohealth/actions/workflows/ci.yml/badge.svg)](https://github.com/andrewtryder/py-herohealth/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/andrewtryder/py-herohealth/blob/main/LICENSE)
[![Typed](https://img.shields.io/badge/typing-PEP%20561-blue)](https://peps.python.org/pep-0561/)
[![Status](https://img.shields.io/badge/status-alpha-orange)](https://pypi.org/project/herohealth/)

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](https://pypi.org/project/herohealth/)** · **[Source code](https://github.com/andrewtryder/py-herohealth)** · **[Changelog](https://github.com/andrewtryder/py-herohealth/blob/main/CHANGELOG.md)** · **[Report an issue](https://github.com/andrewtryder/py-herohealth/issues)**

## 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:

```sh
pip install herohealth
```

Requires Python 3.12, 3.13, or 3.14.

To upgrade an existing installation:

```sh
pip install --upgrade herohealth
```

## Quick start

### 1. Configure your credentials

Create a `.env` file in your working directory:

```dotenv
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

```python
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

```python
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:

```sh
herohealth --help
```

Authenticate and cache your tokens:

```sh
herohealth login
```

Retrieve account information:

```sh
herohealth whoami
```

Retrieve scheduled doses:

```sh
herohealth home
```

Retrieve device configuration:

```sh
herohealth device-config
```

You can also call individual SDK methods:

```sh
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:

```text
~/.cache/herohealth/tokens.json
```

Treat this file like a password.

You can customize the cache location:

```python
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.

```python
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

- [Usage guide](https://github.com/andrewtryder/py-herohealth/blob/main/docs/usage.md)
- [Changelog](https://github.com/andrewtryder/py-herohealth/blob/main/CHANGELOG.md)
- [Contributing guide](https://github.com/andrewtryder/py-herohealth/blob/main/CONTRIBUTING.md)
- [Security policy](https://github.com/andrewtryder/py-herohealth/blob/main/SECURITY.md)
- [Protocol research](https://github.com/andrewtryder/py-herohealth/tree/main/docs/research)

## Development

Clone the repository and install the development dependencies:

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

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

Run the quality checks:

```sh
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](https://github.com/andrewtryder/py-herohealth/security/advisories/new).

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

## License

Released under the [MIT License](https://github.com/andrewtryder/py-herohealth/blob/main/LICENSE).

---

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