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. Call await client.logout() when done — it sends the gateway's logout (DELETE /user/<id>/token/<token>) and frees the single slot immediately, so the web UI and other clients can log straight back in. client.close() logs out for you. A login attempt while another session is active raises CompalSessionBusyError instead of failing confusingly; if a client exits without logging out, the router still releases the slot on its own after ~15 minutes.
  • 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. Call await client.logout() (or client.close()) when finished to free the slot right away; otherwise 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.2.0.tar.gz (18.4 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.2.0-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for compalf3896lg-1.2.0.tar.gz
Algorithm Hash digest
SHA256 446cecb7e36c1dbbdd4c7217e9dbad6d72ae221746070e00170a99af8a1f7ed9
MD5 25401ca4e862bdbb4e8358a01c4e0863
BLAKE2b-256 52afaa8a5388fb789e93d4f84f7b491309b6c5b5d280a90c91beac85848673b7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: compalf3896lg-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.8 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c1310e34e688e5c94cc0a3981a1769ca2977d66c73c35e6f9226cd3f4b5359ad
MD5 0971b9907291f02ed8789c295e33d7e4
BLAKE2b-256 f1f0dcab8a80ae9837f19f9abec5282b03b7aead5134ccdc816affd115dd2a5c

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