Package: sagemcom_api
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.FeaturesRetrieve detailed information of your Sagemcom F@st deviceRetrieve connected devices (wifi and ethernet)Reboot Sagemcom F@st deviceRetrieve and set all values of your Sagemcom F@st deviceSupported devicesThe 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 ModelProvider(s)Authentication MethodCommentsSagemcom F@st 3864Optussha512username: guest, password: ""Sagemcom F@st 3865bProximus (b-box3)md5Sagemcom F@st 3890V3Delta / Zeelandnetmd5Sagemcom F@st 4360AirKPNmd5Sagemcom F@st 5250Bell (Home Hub 2000)md5username: guest, password: ""Sagemcom F@st 5280sha512Sagemcom F@st 5364BT (Smart Hub)md5username: guest, password: ""SagemCom F@st 5366SDEir F3000md5Sagemcom F@st 5370eTeliasha512Sagemcom F@st 5566Bell (Home Hub 3000)md5username: guest, password: ""Sagemcom F@st 5689Bell (Home Hub 4000)md5username: admin, password: ""Sagemcom F@st 5655V2MásMóvilmd5Sagemcom F@st 5657ILmd5Speedport ProTelekommd5username: adminContributions welcome. If you router model is supported by this package, but not in the list above, please createan issueor pull request.Installationpipinstallsagemcom_apiGetting StartedDepending on the router model, Sagemcom is using different encryption methods for authentication, which can be found inthe table above. This package supports MD5 and SHA512 encryption. If you receive aLoginTimeoutException, you will probably need to use another encryption type.The following script can be used as a quickstart.importasynciofromsagemcom_api.enumsimportEncryptionMethodfromsagemcom_api.clientimportSagemcomClientHOST=""USERNAME=""PASSWORD=""ENCRYPTION_METHOD=EncryptionMethod.MD5# or EncryptionMethod.SHA512asyncdefmain()->None:asyncwithSagemcomClient(HOST,USERNAME,PASSWORD,ENCRYPTION_METHOD)asclient:try:awaitclient.login()exceptExceptionasexception:# pylint: disable=broad-exceptprint(exception)return# Print device information of Sagemcom F@st routerdevice_info=awaitclient.get_device_info()print(f"{device_info.id}{device_info.model_name}")# Print connected devicesdevices=awaitclient.get_hosts()fordeviceindevices:ifdevice.active:print(f"{device.id}-{device.name}")# Retrieve values via XPath notation, output is a dictcustom_command_output=awaitclient.get_value_by_xpath("Device/UserInterface/AdvancedMode")print(custom_command_output)# Set value via XPath notationcustom_command_output=awaitclient.set_value_by_xpath("Device/UserInterface/AdvancedMode","true")print(custom_command_output)asyncio.run(main())Functionslogin()get_device_info()get_hosts()get_port_mappings()reboot()get_value_by_xpath(xpath)set_value_by_xpath(xpath, value)AdvancedDetermine the EncryptionMethod(not supported yet)Handle exceptionsSome functions may cause an error when an attempt is made to execute it. These exceptions are thrown by the client and need to behandled in your Python program. Best practice is to catch some specific exceptions and handle them gracefully.fromsagemcom_api.exceptionsimport*try:awaitclient.set_value_by_xpath("Device/UserInterface/AdvancedMode","true")exceptNonWritableParameterExceptionasexception:print("You don't have rights to write to this parameter.")exceptUnknownPathExceptionasexception:print("The xpath does not exist.")Run your custom commandsNot 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, oran exceptionwhen the attempt was not successful.try:result=awaitclient.get_value_by_xpath("Device/DeviceSummary")exceptExceptionasexception:print(exception)Use your own aiohttp ClientSessionClientSession 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 customaiohttp ClientSession.fromaiohttpimportClientSession,ClientTimeoutsession=ClientSession(timeout=ClientTimeout(100))client=SagemcomClient(session=session)Inspired bywuseman/SAGEMCOM-FAST-5370e-TELIAinsou22/optus-router-toolsonegambler/bthomehub_client