Skip to main content

AsyncWebOSTV

An asynchronous Python library for controlling LG WebOS TVs. This is an async port of the popular pywebostv library.

Features

  • Asynchronous API for controlling LG WebOS TVs
  • WebSocket-based communication
  • Support for all major TV controls (media, system, input, applications, TV channels, sources, etc.)
  • Real-time event subscriptions (volume, channel, foreground app, power state, audio output)
  • SSDP-based network device discovery
  • Secure SSL/TLS connections with certificate handling
  • Modern Python async/await syntax
  • Type hints for better IDE support
  • Comprehensive test coverage

Requirements

  • Python 3.11+
  • aiohttp>=3.8.0
  • websockets>=15.0.1

Installation

pip install asyncwebostv

Quick Start

import asyncio
from asyncwebostv.connection import WebOSClient
from asyncwebostv.controls import (
    MediaControl, SystemControl, ApplicationControl, TvControl, InputControl, SourceControl
)

async def main():
    # Create a WebOS client
    client = WebOSClient("192.168.1.100")  # Replace with your TV's IP

    # Connect to TV
    await client.connect()

    # Register with the TV (if needed)
    store = {}  # Dictionary to receive the client key
    async for status in client.register(store):
        if status == WebOSClient.PROMPTED:
            print("Please accept the connection on your TV")
        elif status == WebOSClient.REGISTERED:
            print(f"Registration successful, client key: {store.get('client_key')}")

    # Use the client key for future sessions to avoid re-pairing
    # client_key = store.get("client_key")

    # Create control interfaces
    media = MediaControl(client)
    system = SystemControl(client)

    # Control TV
    await media.volume_up()
    await system.notify("Hello from AsyncWebOSTV!")

    # Close connection
    await client.close()

asyncio.run(main())

Subscriptions

AsyncWebOSTV supports real-time event subscriptions so you don't have to poll the TV. Six subscriptions are available: get_volume, get_audio_output, get_sound_output, get_current_channel, get_current (foreground app), and power_state.

import asyncio
from asyncwebostv.connection import WebOSClient
from asyncwebostv.controls import MediaControl, SystemControl

async def main():
    client = WebOSClient("192.168.1.100", client_key="your-client-key")
    await client.connect()

    media = MediaControl(client)
    system = SystemControl(client)

    async def on_volume(success, payload):
        if success:
            print(f"Volume: {payload.get('volume')} muted={payload.get('muted')}")

    async def on_power(success, payload):
        if success:
            print(f"Power state: {payload.get('state')}")

    await media.subscribe_get_volume(on_volume)
    await system.subscribe_power_state(on_power)

    try:
        await asyncio.sleep(60)  # receive events for a minute
    finally:
        await media.unsubscribe_get_volume()
        await system.unsubscribe_power_state()
        await client.close()

asyncio.run(main())

Reconnect note: after await client.close(), discard your control objects (MediaControl, SystemControl, etc.) and create fresh ones against the new client before resubscribing. See the subscription spec for the full reconnect contract and the complete list of event payloads.

Secure Connections

AsyncWebOSTV supports secure SSL/TLS connections to WebOS TVs. The library provides two classes for secure connections:

SecureWebOSClient

Low-level secure client with enhanced SSL certificate handling:

import asyncio
from asyncwebostv import SecureWebOSClient, extract_certificate

async def main():
    # Extract and save certificate from TV
    cert_file = "tv_cert.pem"
    await extract_certificate("192.168.1.100", 3001, cert_file)

    # Create secure client with certificate verification
    client = SecureWebOSClient(
        host="192.168.1.100",
        port=3001,
        secure=True,
        cert_file=cert_file,
        verify_ssl=True,
        client_key="your-client-key"  # Optional
    )

    # Connect and use as normal
    await client.connect()

    # Close connection
    await client.close()

asyncio.run(main())

SecureWebOSTV

High-level secure client with SSL certificate handling:

import asyncio
from asyncwebostv import SecureWebOSTV

async def main():
    # Create secure TV client
    tv = SecureWebOSTV(
        host="192.168.1.100",
        port=3001,
        cert_file="tv_cert.pem",  # Optional
        verify_ssl=True           # Set to False to skip verification
    )

    # Extract and save certificate
    # await tv.get_certificate("tv_cert.pem")

    # Connect and register if needed
    await tv.connect()
    if not tv.client_key:
        client_key = await tv.register()

    # Now use the client property to access lower-level API
    client = tv.client

    # Close connection
    await tv.close()

asyncio.run(main())

Certificate Utilities

The library includes utility functions for working with TV certificates:

from asyncwebostv import extract_certificate, verify_certificate

# Extract certificate from TV
cert_pem = await extract_certificate("192.168.1.100", 3001, "tv_cert.pem")

# Verify if a saved certificate matches the current one on the TV
matches = await verify_certificate("tv_cert.pem", "192.168.1.100", 3001)

Client Key Management

Unlike some other libraries, AsyncWebOSTV does not save client keys to disk by default. Instead, it returns the client key to the caller through a provided dictionary.

# During registration
store = {}
async for status in client.register(store):
    pass

# After registration, the client key is in the store dictionary
client_key = store.get("client_key")
print(f"Your client key: {client_key}")

# Save it however you want (database, config file, etc.)

For subsequent connections, you can provide the client key directly:

client = WebOSClient("192.168.1.100", client_key="your-client-key")

This approach gives you more control over how client keys are stored and managed in your application.

Documentation

Detailed documentation lives in the docs/ directory:

Development

  1. Clone the repository:
git clone https://github.com/droman42/asyncwebostv.git
cd asyncwebostv
  1. Install development dependencies:
pip install -e ".[dev]"
  1. Run tests:
pytest
  1. Format code:
black .
isort .

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Original pywebostv library for inspiration
  • LG for their WebOS platform

Metadata

Release files for asyncwebostv 0.4.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 asyncwebostv 0.4.0
File Size Uploaded Provenance Actions
asyncwebostv-0.4.0.tar.gz 32.1 kB With provenance Details for asyncwebostv-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 66.7 kB

Release files / asyncwebostv-0.4.0.tar.gz

Download URL asyncwebostv-0.4.0.tar.gz
Size 32.1 kB
Tags Source
SHA-256 checksum
How to use checksums
07ab92a461a32992b3bf9d9c54e76c27b0c42983de7e4747ba43223b0d005d84
BLAKE2b-256 checksum
How to use checksums
3a6a4013a7dcf256870cf8d188b0439f811f519d6a1d58e5e3d15359f385e3ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 9, 2026.

Transparency log

Release files / asyncwebostv-0.4.0-py3-none-any.whl

Download URL asyncwebostv-0.4.0-py3-none-any.whl
Size 34.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc679533b63b79d5582987bcfc756b56c7b45781c14d5519b1cdaa3509f6a151
BLAKE2b-256 checksum
How to use checksums
0c9c75190485765c3b8b9f89b3dcb290d21282adbbba1364b11bbc190acffdb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 9, 2026.

Transparency log

Security for asyncwebostv 0.4.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 asyncwebostv-0.4.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 Jun 9, 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