Python Library

AsusRouter is a Python library that serves as a comprehensive API wrapper for interacting with ASUSWRT-powered routers. It communicates using HTTP(S) protocols and provides extensive control and monitoring capabilities. The library is compatible with both the stock AsusWRT firmware and AsusWRT-Merlin, making it a versatile tool for managing and monitoring ASUS network devices.

Installation

Prerequisites

AsusRouter requires Python 3.11 or higher and is tested with Python 3.11 and 3.12.

PyPI

The latest release of AsusRouter is available from PyPI.

pip install asusrouter

GitHub

The latest development version of AsusRouter is available from GitHub. Refer to the build instructions for more information.

Usage

AsusRouter is an asynchronous library. It is designed to be used with the asyncio module and the async/await syntax. Refer to the asyncio documentationopen in new window for more information.

Creating a router object

The AsusRouter class is the main class of the library. It represents a single router device and provides methods for interacting with it.

from asusrouter import AsusRouter

router = AsusRouter(
    hostname="192.168.1.1",     # Required - IP address or hostname of the router
    username="admin",           # Required
    password="admin",           # Required
    port=None,                  # Optional - default port would be selected based on use_ssl parameter
    use_ssl=False,              # Optional - use HTTPS instead of HTTP
)

Retrieving router data

The AsusRouter class provides a set of methods for retrieving data from the router. The library provides an easy to use AsusData enum that contains all the available data types. Refer to the data documentation for more information.

from asusrouter import AsusData

ram_info = await router.async_get_data(AsusData.RAM, force=False)
# `force` parameter is optional and defaults to False
# If set to True, the library will fetch the data from the router
# regardless of the cache state

print(ram_info)

Example output:

{
  "free": 504632,
  "total": 1048576,
  "used": 543944,
  "usage": 51.87
}

Available data types

AsusData enum covers all the currently available data types. Refer to the data documentation for more information.

Full list
AsusData typeDescription
AIMESHAiMesh information
BOOTTIMERouter boot time
CLIENTSConnected clients
CPUCPU usage
DEVICEMAPDevice map
FIRMWAREFirmware information
GWLANGuest WLAN
LEDLED state
NETWORKNetwork traffic / speed
NODE_INFOAiMesh Node information
OPENVPN_CLIENTOpenVPN clients
OPENVPN_SERVEROpenVPN servers
PARENTAL_CONTROLParental control
PORT_FORWARDINGPort forwarding
PORTSPort information (LAN, USB, WAN)
RAMRAM usage
SPEEDTESTSpeedtest information
SYSINFOSystem information (Merlin-only)
TEMPERATURETemperature
VPNCVPN Client
VPNC_CLIENTLISTVPN Client list
WANWAN information
WIREGUARD_CLIENTWireGuard clients
WIREGUARD_SERVERWireGuard servers
WLANWLAN information

Setting router state

AsusRouter implements async_set_state() method that allows to set the state of the router. Refer to the state documentation for more information.

from asusrouter.modules.port_forwarding import AsusPortForwarding

result = await router.async_set_state(AsusPortForwarding.ON)

print(result)

Example output:

True # If the state was set successfully
False # If the state was not set successfully

# AsusRouter is checking device response to determine if the state was
# set successfully. Device might return `True` even if the state was not
# changed (e.g. if the state is already set)

Setting router state with arguments

Some states require additional arguments to be set. The async_set_state() method accepts arguments parameter that should be a dictionary of arguments. Refer to the state documentation for more information.


result = await router.async_set_state(
    AsusWLAN.ON,
    arguments={
        "api_type": "gwlan",  # Guest WLAN
        "api_id": "0.2",      # Guest WLAN #2 on 2.4 GHz
    },
)

print(result)

Example output:

True # If the state was set successfully
False # If the state was not set successfully

Calling system services

Using special AsusSystem enum, it is possible to call system services. Refer to the system documentation for more information. System services are called using async_set_state() method.

from asusrouter.modules.system import AsusSystem

result await router.async_set_state(AsusSystem.RESTART_HTTPD)

print(result)

Example output:

True # If the service was called successfully
False # If the service was not called successfully

Available system services

AsusSystem enum covers all the currently available system services. Refer to the system documentation for more information.

Full list
AsusSystem typeDescription
REBOOTReboot router
RESTART_CHPASSRestart chpass
RESTART_DNSMASQRestart dnsmasq
RESTART_FIREWALLRestart firewall
RESTART_HTTPDRestart HTTP daemon
RESTART_LEDSRestart LEDs
RESTART_OPENVPNDRestart OpenVPN daemon
RESTART_SAMBARestart Samba server
RESTART_TIMERestart time
RESTART_USB_IDLERestart USB controller (if idle)
RESTART_VPNCRestart vpnc
RESTART_WGSRestart WireGuard server
RESTART_WIRELESSRestart WLAN modules
STOP_OPENVPNDStop OpenVPN daemon
STOP_VPNCStop vpnc
UPDATE_CLIENTSUpdate clients