Philips Hue API V2 Async Client
Project description
pyhuec
Python Hue Client
Python client for interfacing with Philips Hue API v2, supports REST and Event streaming
[!NOTE] This is very much a work in progress. API features have not been fully implemented. If you stumble upon this looking for a working hue client, it's not that yet. Feel free to contribute!
What's it do?
- Auto-Discovery - Automatically finds your Hue Bridge on the network
- Auto-Authentication - Generates and saves API keys with guided setup
- Event Streaming - Real-time updates via Server-Sent Events (SSE)
- State Caching - Cache synchronized with REST API and events
- Asynchronous - It's async
Quick Start
import asyncio
from pyhuec.hue_client_factory import HueClientFactory
async def main():
# use HueClientFactory.create_client(auto_authenticate=False)
# to disable auto fetching api key
client = await HueClientFactory.create_client()
await client.start_event_stream()
# Enable in memory caching, optional
await client.initialize_cache()
lights = await client.get_lights()
await client.turn_on_light(lights[0].id, brightness=100)
# Get events from bridge and update state
await client.subscribe_to_light_events(
lambda event: print(f"Light changed: {event}")
)
await client.stop_event_stream()
asyncio.run(main())
[!NOTE] More example code can be found in example.py
On first run, you'll be prompted to press the button on your bridge. The API key is saved automatically for future use.
Installation
[!NOTE] Will add here when published to pypi
Developing
This project using uv for handling dependencies and build scripts. See Instructions on Installing
Sync the project
❯ uv sync
Run tests
❯ uv run tests
Run Sample
❯ uv run example.py
Connecting to your bridge
[!Note] This client only uses mDNS for automatic bridge discovery. If you are having trouble finding your bridge with mDNS, feel free to follow Hue's guide on finding your bridge ip.
Automatic Setup (Recommended)
The easiest way is to let pyhuec handle everything:
client = await HueClientFactory.create_client(auto_authenticate=True)
This will:
- Discover your bridge via mDNS
- Check for existing API key in
.envfile - Prompt you to press the bridge button if needed
- Generate and save a new API key
- Connect to your bridge automatically
Manual Setup
If you prefer manual configuration:
client = await HueClientFactory.create_client(
bridge_ip="<bridge-ip-address>",
api_key="<your-api-key-here>"
)
Environment Variables
Set these in your .env file:
HUE_USER=your-api-key-here
TARGET_MDNS=_hue._tcp.local. # Optional, has default
The HUE_USER variable is automatically created when you use auto-authentication.
Contributing
Feel free to fork or open a PR. Will not be looking at issues until feature complete.
This project uses pre-commit for managing git-hooks, and is included as part of the dev dependences. To use it you'll still need to run a single command to install the hooks in your local branch
❯ pre-commit install
Current hooks run tests and ruff linting as pre-commits.
Any additional dev/testing dependencies should be add to the dev group.
❯ uv add <some-dev-package> --dev
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyhuec-0.1.0.tar.gz.
File metadata
- Download URL: pyhuec-0.1.0.tar.gz
- Upload date:
- Size: 34.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83be27649fef75a4a78d3c227d89c805496526ada40a8ace26497ee30ae92563
|
|
| MD5 |
59f819e027ecb4bed0feeaa10961b6fa
|
|
| BLAKE2b-256 |
d5e65ecdbc6da5dc8f71876aa157afb45b16de5c73fa463502b7a19bbb78b376
|
Provenance
The following attestation bundles were made for pyhuec-0.1.0.tar.gz:
Publisher:
python-publish.yml on dewskii/pyhuec
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyhuec-0.1.0.tar.gz -
Subject digest:
83be27649fef75a4a78d3c227d89c805496526ada40a8ace26497ee30ae92563 - Sigstore transparency entry: 845425813
- Sigstore integration time:
-
Permalink:
dewskii/pyhuec@d7ad925c5410dd07d81f3d318dc03d615457488f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dewskii
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d7ad925c5410dd07d81f3d318dc03d615457488f -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyhuec-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyhuec-0.1.0-py3-none-any.whl
- Upload date:
- Size: 58.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c90a94eddff39d5afde10d68e1fe9da4eb4c430f783d6bb1d060ad669dfcc57f
|
|
| MD5 |
1f49105da8621adb443bca5112291ac6
|
|
| BLAKE2b-256 |
51b49ad5d71bc9542b45d869b25265ffedad560c5e7237647f2c709475623f4d
|
Provenance
The following attestation bundles were made for pyhuec-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on dewskii/pyhuec
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyhuec-0.1.0-py3-none-any.whl -
Subject digest:
c90a94eddff39d5afde10d68e1fe9da4eb4c430f783d6bb1d060ad669dfcc57f - Sigstore transparency entry: 845425822
- Sigstore integration time:
-
Permalink:
dewskii/pyhuec@d7ad925c5410dd07d81f3d318dc03d615457488f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dewskii
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d7ad925c5410dd07d81f3d318dc03d615457488f -
Trigger Event:
release
-
Statement type: