aiowebostv
Python library to control LG webOS based TV devices.
Based on:
aiopylgtvlibrary at https://github.com/bendavid/aiopylgtvbscpylgtvlibrary at https://github.com/chros73/bscpylgtv
Requirements
- Python >= 3.12
Install
pip install aiowebostv
Install from Source
Run the following command inside this folder
pip install --upgrade .
Prepare the development environment
Run the following commands inside this folder (requires uv)
uv sync --all-groups
uv run prek install
Run all checks (lint, type checking and tests) with
uv run tox
Examples
Basic Example
import asyncio
from pprint import pprint
from aiowebostv import WebOsClient
HOST = "192.168.1.39"
# For first time pairing set key to None
CLIENT_KEY = "140cce792ae045920e14da4daa414582"
async def main():
"""Basic webOS client example."""
client = WebOsClient(HOST, CLIENT_KEY)
await client.connect()
# Store this key for future use
print(f"Client key: {client.client_key}")
pprint(client.tv_info)
pprint(client.tv_state)
await client.disconnect()
if __name__ == "__main__":
asyncio.run(main())
Subscribed State Updates Example
import asyncio
import dataclasses
import signal
from datetime import UTC, datetime
from pprint import pprint
from aiowebostv import WebOsClient
from aiowebostv.models import WebOsTvState
HOST = "192.168.1.39"
# For first time pairing set key to None
CLIENT_KEY = "140cce792ae045920e14da4daa414582"
async def on_state_change(tv_state: WebOsTvState) -> None:
"""State changed callback."""
now = datetime.now(UTC).astimezone().strftime("%H:%M:%S.%f")[:-3]
print(f"[{now}] State change:")
# for the example, remove apps and inputs to make the output more readable
state = dataclasses.replace(tv_state, apps={}, inputs={})
pprint(state)
async def main():
"""Subscribed State Updates Example."""
client = WebOsClient(HOST, CLIENT_KEY)
await client.register_state_update_callback(on_state_change)
await client.connect()
# Store this key for future use
print(f"Client key: {client.client_key}")
# Change something using the remote to get updates or ctrl-c to exit
sig_event = asyncio.Event()
signal.signal(signal.SIGINT, lambda _exit_code, _frame: sig_event.set())
await sig_event.wait()
await client.disconnect()
if __name__ == "__main__":
asyncio.run(main())
Errors
All errors derive from WebOsTvError:
| Exception | Raised by | Meaning |
|---|---|---|
WebOsTvConnectionError |
connect() |
Connecting failed, other than pairing: TV unreachable, timeout, invalid handshake, the TV closed the connection or a request failed while connecting. The original error is the cause. |
WebOsTvRegistrationError |
connect() |
A WebOsTvConnectionError: an already paired TV rejected the registration, e.g. while booting. The next connect usually succeeds. |
WebOsTvPairError |
connect() |
Pairing failed: the prompt was rejected or ignored, or the client key was revoked. Pair again. |
WebOsTvCommandError |
Requests and commands | A request or command failed: not connected, the connection closed, a timeout or an error response. |
WebOsTvServiceNotFoundError |
Requests and commands | A WebOsTvCommandError: the TV does not support the service or method. |
WebOsTvWakeError |
turn_on() |
Wake-on-LAN failed: no MAC address is known or the packets could not be sent. |
try:
await client.connect()
except WebOsTvPairError:
... # pair again
except WebOsTvConnectionError:
... # TV is off or unreachable, try again later
try:
await client.set_volume(10)
except WebOsTvCommandError:
...
Turning on the TV
turn_on() sends Wake-on-LAN magic packets to the TV's wired and Wi-Fi MAC
addresses, also when the TV is still connected in standby. It does nothing if
the TV is connected and on.
# MAC addresses reported by the TV on connect, store them for later use
macs = client.mac_addresses # {"wired": "...", "wifi": "..."}
# Later, while the TV is off
await client.turn_on(macs.values())
Without mac_addresses, client.mac_addresses is used. It keeps the MAC
addresses the TV reported on connect, also after the TV disconnects.
WebOsTvWakeError is raised when no MAC address is known.
Wake-on-LAN requirements and limitations:
- webOS 3.0 (2016) and newer, older TVs (webOS 1.x/2.0) do not support it and do not report their MAC addresses.
- It must be enabled on the TV: "Mobile TV On" / "Turn on via Wi-Fi", on some older models also "LG Connect Apps". The menu location varies by model year.
- A wired connection is more reliable, some TVs stop responding to Wake-on-LAN over Wi-Fi after some time in standby.
- Magic packets get no reply,
turn_on()returning does not mean the TV turned on.
Examples can be found in the examples folder
Metadata
Release files for aiowebostv 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiowebostv-2.0.0.tar.gz | 45.7 kB | With provenance | Details for aiowebostv-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aiowebostv-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for aiowebostv-2.0.0-py3-none-any.whl |
Total release size: 73.0 kB
Release files / aiowebostv-2.0.0.tar.gz
| Download URL | aiowebostv-2.0.0.tar.gz |
|---|---|
| Size | 45.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
afcc36ac739f17fb1a58815d107fb6be847d25e4049f34b9603d2176841e4138
|
|
BLAKE2b-256 checksum How to use checksums |
9255785d0b6effda2aa437345b6a792dcd731847d3c0a468eba8ca00767d7492
|
| 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 26, 2026.
Transparency logRelease files / aiowebostv-2.0.0-py3-none-any.whl
| Download URL | aiowebostv-2.0.0-py3-none-any.whl |
|---|---|
| Size | 27.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e7797f4b5bb1e8a441656f6ddc6ebd4fa5ce704fa6cd931702456be7d3193a53
|
|
BLAKE2b-256 checksum How to use checksums |
bbd6184e551d0e928c76de36d30490b8a3baea163fafbc2aceb71d57cb951021
|
| 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 26, 2026.
Transparency logSecurity for aiowebostv 2.0.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.
Attestation for aiowebostv-2.0.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 Nov 26, 2026.
Transparency logA 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.