Skip to main content

Python client to interact with SagemCom F@st routers via internal API's.

Project description

Sagemcom API Client in Python

(Unofficial) async Python client to interact with Sagemcom F@st routers via internal API's. This client offers helper functions to retrieve common used functions, but also offers functionality to do custom requests via XPATH notation.

Python 3.9+ required.

Features

  • Retrieve detailed information of your Sagemcom F@st device
  • Retrieve connected devices (wifi and ethernet)
  • Reboot Sagemcom F@st device
  • Retrieve and set all values of your Sagemcom F@st device

Supported devices

The Sagemcom F@st series is used by multiple cable companies, where some cable companies did rebrand the router. Examples are the b-box from Proximus, Home Hub from bell and the Smart Hub from BT.

Router Model Provider(s) Authentication Method Comments
Sagemcom F@st 3864 Optus sha512 username: guest, password: ""
Sagemcom F@st 3865b Proximus (b-box3) md5
Sagemcom F@st 3890V3 Delta / Zeelandnet md5
Sagemcom F@st 4360Air KPN md5
Sagemcom F@st 5250 Bell (Home Hub 2000) md5 username: guest, password: ""
Sagemcom F@st 5280 sha512
Sagemcom F@st 5364 BT (Smart Hub) md5 username: guest, password: ""
SagemCom F@st 5366SD Eir F3000 md5
Sagemcom F@st 5370e Telia sha512
Sagemcom F@st 5566 Bell (Home Hub 3000) md5 username: guest, password: ""
Sagemcom F@st 5655V2 MásMóvil md5
Sagemcom F@st 5657IL md5
Speedport Pro Telekom md5

Contributions welcome. If you router model is supported by this package, but not in the list above, please create an issue or pull request.

Installation

pip install sagemcom_api

Getting Started

Depending on the router model, Sagemcom is using different encryption methods for authentication, which can be found in the table above. This package supports MD5 and SHA512 encryption. If you receive a LoginTimeoutException, you will probably need to use another encryption type.

The following script can be used as a quickstart.

import asyncio
from sagemcom_api.enums import EncryptionMethod
from sagemcom_api.client import SagemcomClient

HOST = ""
USERNAME = ""
PASSWORD = ""
ENCRYPTION_METHOD = EncryptionMethod.MD5 # or EncryptionMethod.SHA512

async def main() -> None:
    async with SagemcomClient(HOST, USERNAME, PASSWORD, ENCRYPTION_METHOD) as client:
        try:
            await client.login()
        except Exception as exception:  # pylint: disable=broad-except
            print(exception)
            return

        # Print device information of Sagemcom F@st router
        device_info = await client.get_device_info()
        print(f"{device_info.id} {device_info.model_name}")

        # Print connected devices
        devices = await client.get_hosts()

        for device in devices:
            if device.active:
                print(f"{device.id} - {device.name}")

        # Retrieve values via XPath notation, output is a dict
        custom_command_output = await client.get_value_by_xpath("Device/UserInterface/AdvancedMode")
        print(custom_command_output)

        # Set value via XPath notation
        custom_command_output = await client.set_value_by_xpath("Device/UserInterface/AdvancedMode", "true")
        print(custom_command_output)

asyncio.run(main())

Functions

  • login()
  • get_device_info()
  • get_hosts()
  • get_port_mappings()
  • reboot()
  • get_value_by_xpath(xpath)
  • set_value_by_xpath(xpath, value)

Advanced

Determine the EncryptionMethod

(not supported yet)

Handle exceptions

Some functions may cause an error when an attempt is made to execute it. These exceptions are thrown by the client and need to be handled in your Python program. Best practice is to catch some specific exceptions and handle them gracefully.

from sagemcom_api.exceptions import *

try:
    await client.set_value_by_xpath("Device/UserInterface/AdvancedMode", "true")
except NonWritableParameterException as exception:
    print("You don't have rights to write to this parameter.")
except UnknownPathException as exception:
    print("The xpath does not exist.")

Run your custom commands

Not all values can be retrieved by helper functions in this client implementation. By using XPath, you are able to return all values via the API. The result will be a dict response, or an exception when the attempt was not successful.

try:
    result = await client.get_value_by_xpath("Device/DeviceSummary")
except Exception as exception:
    print(exception)

Use your own aiohttp ClientSession

ClientSession is the heart and the main entry point for all client API operations. The session contains a cookie storage and connection pool, thus cookies and connections are shared between HTTP requests sent by the same session.

In order to change settings like the time-out, it is possible to pass your custom aiohttp ClientSession.

from aiohttp import ClientSession, ClientTimeout

session = ClientSession(timeout=ClientTimeout(100))
client = SagemcomClient(session=session)

Inspired by

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

sagemcom_api-1.0.6.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

sagemcom_api-1.0.6-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file sagemcom_api-1.0.6.tar.gz.

File metadata

  • Download URL: sagemcom_api-1.0.6.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.2 Linux/5.11.0-1027-azure

File hashes

Hashes for sagemcom_api-1.0.6.tar.gz
Algorithm Hash digest
SHA256 3f0e978408717f268b6237b327c1c19e72c94580ff10578ad4fa09beb51bc775
MD5 f2c4c634b2e922018fd477bbdfdf3887
BLAKE2b-256 8c6765b0348394127b5336c7ac947781d9aa045b440b9c2f92f390db5d91b524

See more details on using hashes here.

File details

Details for the file sagemcom_api-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: sagemcom_api-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.2 Linux/5.11.0-1027-azure

File hashes

Hashes for sagemcom_api-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 71494940d8a11ed16ccd67765b6e529cb230d0f117241874b65107228914440f
MD5 957a6a68aaad11a7841beeeeefeb184e
BLAKE2b-256 8e90ff1fcf0c60d8d403ecd40531fa94d78853692e50d7a01844c58376705cda

See more details on using hashes here.

Supported by

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