Skip to main content

An unofficial async Python client for the Compal F3896LG (Ziggo) cable gateway

Project description

PyPI - Downloads PyPI - Downloads

Unofficial Compal F3896LG API Client

Disclaimer: this is an unofficial Python client for the Compal F3896LG cable gateway's local admin API. It is not affiliated with, endorsed by, or in any way connected to Compal, Liberty Global, Ziggo, or VodafoneZiggo. Use it on your own gateway, at your own risk.

Introduction

The Compal F3896LG is the DOCSIS 3.1 cable gateway that Liberty Global / Ziggo ship to customers in the Netherlands (it also appears elsewhere in the Liberty Global footprint). Its web UI is a single-page app that talks to a small REST API under https://<router>/rest/v1.

This library is an asynchronous Python wrapper around that API. It reads system/firmware info, DOCSIS downstream/upstream channels, cable-modem registration state, provisioned service flows (your plan's rate caps), Wi-Fi configuration/state and the connected-hosts table — and can reboot the gateway. Every response is parsed into a documented dataclass, with the raw payload kept on .raw.

Features

  • Single-session handling: the F3896LG allows exactly one authenticated session and has no logout endpoint. The client logs in, reads in a burst, and drops the token; the router frees the slot once the token idles out. A login attempt while another session is active raises CompalSessionBusyError instead of failing confusingly.
  • Lockout-aware login: the password endpoint locks out after a handful of contiguous wrong attempts. Before each login the client reads the unauthenticated login status and refuses to try while a lockout is active, so it never makes things worse.
  • DOCSIS diagnostics: downstream power/SNR/modulation/error counters per channel, upstream power/modulation, and provisioned service-flow rates.
  • Connected devices: the DHCP/association table with hostname, IP, interface, Wi-Fi band and RSSI — handy for presence detection.
  • Typed models: every response becomes a dataclass; the Wi-Fi PSK is deliberately kept out of the modelled fields (it stays in .raw) so it isn't surfaced by accident.

Installation

Requires Python 3.11 or newer.

pip install compalf3896lg

Or from a checkout:

pip install -r requirements.txt

Authentication

The gateway uses a password-only login (no username): POST /rest/v1/user/login with {"password": "..."} returns a bearer token that is valid for a single session. The admin certificate is self-signed, so TLS verification is off by default.

One session at a time. Close the router's web UI before using this library, or expect a CompalSessionBusyError. There is no logout call — the router releases the session on its own roughly 15 minutes after the last request.

Usage

The client manages its own aiohttp session (pass your own via session= if you prefer) and works as an async context manager.

import asyncio
from compalf3896lg import CompalClient

async def main():
    async with CompalClient("192.168.178.1", "your-admin-password") as client:
        await client.login()

        info = await client.get_system_info()
        print(info.model_name, info.software_version)

        state = await client.get_cable_modem_state()
        print(f"DOCSIS {state.docsis_version}: {state.status}, uptime {state.uptime}s")

        for flow in await client.get_service_flows():
            print(flow.direction, flow.max_traffic_rate_mbps, "Mbps")

        for ch in await client.get_downstream_channels():
            print(ch.channel_id, ch.power, "dBmV", ch.snr, "dB", ch.modulation)

        for host in await client.get_hosts():
            print(host.ip_address, host.name, host.interface)

asyncio.run(main())

Checking lockout state without logging in

async with CompalClient("192.168.178.1", "your-admin-password") as client:
    failures, lockout_seconds = await client.get_lockout()
    print(f"{failures} contiguous failures, locked out for {lockout_seconds}s")

Rebooting

async with CompalClient("192.168.178.1", "your-admin-password") as client:
    await client.login()
    await client.reboot()   # drops the WAN for a minute or two — deliberate action

Example

examples/quickstart.py prints a status summary using COMPAL_HOST / COMPAL_PASSWORD from the environment:

COMPAL_HOST=192.168.178.1 COMPAL_PASSWORD='your-admin-password' python examples/quickstart.py

Home Assistant

A companion Home Assistant integration built on this library lives at HA-Compal-F3896LG — install it via HACS to get DOCSIS signal, connected-device and gateway-status sensors, plus a reboot button.

Notes

  • TLS: the admin cert is self-signed; verification is off by default. Pass verify_ssl=True if you have installed the cert.
  • /network/ipv4/info returns the LAN address/subnet, not the WAN IP — the stock firmware does not expose the public WAN address over this API.
  • Errors: the package raises CompalAuthError (wrong password), CompalLockoutError (login locked out), CompalSessionBusyError (another session active), CompalAPIError (bad response, carries status_code/error_code), CompalNetworkError (timeout/connection/TLS) and CompalValidationError (bad arguments) — all subclasses of CompalError.

License

MIT — see LICENSE.

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

compalf3896lg-1.1.0.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

compalf3896lg-1.1.0-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file compalf3896lg-1.1.0.tar.gz.

File metadata

  • Download URL: compalf3896lg-1.1.0.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for compalf3896lg-1.1.0.tar.gz
Algorithm Hash digest
SHA256 14040a1518b5b101175b07b284cbbaa91d0ae6569c750cc399e0167b2ab6aa46
MD5 682379d7a304ed949c5f6920a3226d2a
BLAKE2b-256 37bf72ba12fab57f094b4cac2cc8726f21794fc1858a0b02386c902e662a4ad9

See more details on using hashes here.

File details

Details for the file compalf3896lg-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: compalf3896lg-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for compalf3896lg-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93481d54a556a9bc39bab20ef01eda243c763a55c85fc50a903a96b567db2d29
MD5 8620ef00aadacc0d9fd8562eea2aafc8
BLAKE2b-256 fc7dbc8e71c76b672702691fc84725cba85640a0f454cf5f0465f21c16c32bda

See more details on using hashes here.

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