Skip to main content

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:

  1. Discover your bridge via mDNS
  2. Check for existing API key in .env file
  3. Prompt you to press the bridge button if needed
  4. Generate and save a new API key
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhuec-0.1.0.tar.gz (34.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhuec-0.1.0-py3-none-any.whl (58.5 kB view details)

Uploaded Python 3

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

Hashes for pyhuec-0.1.0.tar.gz
Algorithm Hash digest
SHA256 83be27649fef75a4a78d3c227d89c805496526ada40a8ace26497ee30ae92563
MD5 59f819e027ecb4bed0feeaa10961b6fa
BLAKE2b-256 d5e65ecdbc6da5dc8f71876aa157afb45b16de5c73fa463502b7a19bbb78b376

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhuec-0.1.0.tar.gz:

Publisher: python-publish.yml on dewskii/pyhuec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pyhuec-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c90a94eddff39d5afde10d68e1fe9da4eb4c430f783d6bb1d060ad669dfcc57f
MD5 1f49105da8621adb443bca5112291ac6
BLAKE2b-256 51b49ad5d71bc9542b45d869b25265ffedad560c5e7237647f2c709475623f4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhuec-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on dewskii/pyhuec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page