huawei-lte-api

SalamekLGPL-3.0活跃维护

用 Python 调用华为 LTE 路由器(LAN/WAN)的接口,读取信号、流量、设备状态等信息,省去自己抓包逆向的麻烦。

API For huawei LAN/WAN LTE Modems

2.0.0发布于 2026-08-13 22:02 UTC539star112fork同步于 2026-11-10 23:56 UTC

怎么上手

由 README 提炼,执行前请确认
pip install huawei-lte-api
硬件要求按 README 说明

README 未说明运行本库的硬件要求;它通过 HTTP 访问华为 LTE 设备,USB 上网卡需支持 HiLink(NETWork)模式,串口模式不可用。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用 Python 调用华为 LTE 路由器和上网卡,收发短信、查流量和信号

用 Python 调用华为 LTE 路由器(LAN/WAN)的接口,读取信号、流量、设备状态等信息,省去自己抓包逆向的麻烦。

核心能力

  • 通过 HTTP 连接路由器,按 API 分组调用设备接口
  • 读取信号强度、设备信息、流量用量等状态
  • 支持发送和接收短信
  • 提供 Client 封装,简化对各 API 分组的访问
  • 已有 TypeScript 和 PHP 移植版本可参考

容易踩的坑

USB 上网卡必须处于 HiLink/NETWork 模式,串口模式无法使用;B2368-22 和 B593s-22 因固件不兼容明确不支持;调用需要授权的接口时,要在连接 URL 中带上用户名和密码,否则会抛异常。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本2.0.0
  1. 2.0.0huawei-lte-api 2.0.0最新正式版2026-08-13 · 2026-08-13 22:02 UTC

    huawei-lte-api 2.0.0

    This major release adds support for supplementary Unicode characters, new API endpoints and examples, modernizes the development toolchain, and removes APIs that have been deprecated for several years.

    Breaking changes

    AuthorizedConnection removed

    Replace:

    from huawei_lte_api.AuthorizedConnection import AuthorizedConnection
    
    connection = AuthorizedConnection(url, username, password)
    

    with:

    from huawei_lte_api.Connection import Connection
    
    connection = Connection(url, username, password)
    

    login_on_demand removed

    The deprecated login_on_demand argument had no effect and has been removed from Connection.

    Deprecated device methods removed

    Replace:

    device.control(mode)
    device.reboot()
    

    with:

    device.set_control(mode)
    device.set_control(ControlModeEnum.REBOOT)
    

    Integer SMS sort types removed

    Sms.get_sms_list(sort_type=...) now requires SortTypeEnum:

    from huawei_lte_api.enums.sms import SortTypeEnum
    
    messages = client.sms.get_sms_list(sort_type=SortTypeEnum.DATE)
    

    Unicode support

    Requests containing characters outside the Basic Multilingual Plane, including emoji, are now encoded using CESU-8 for compatibility with Huawei routers.

    CESU-8 surrogate pairs in router responses are converted to standard UTF-8 before XML parsing.

    New API endpoints

    • Diagnosis.wan_service_name()
    • Monitoring.onekey_diag()
    • Security.acl()
    • User.rule()
    • Voice.volte()
    • WLan.guesttime_setting()

    Fixes and improvements

    • Fixed the TimeRule API endpoint.
    • Added request and response debug logging.
    • Improved readable signal-mode handling.
    • Improved the data-dump example and error reporting.
    • Added Huawei 5G CPE6 to the supported-device list.
    • Added documentation for API endpoints.

    New examples

    • device_signal.py — display detailed signal information.
    • read_sms.py — read SMS messages from the router.

    Development and compatibility

    • Added Python 3.13 and Python 3.14 testing.
    • Migrated package configuration to pyproject.toml.
    • Migrated linting and formatting to Ruff.
    • Expanded strict mypy checking.
    • Added core tests for requests, responses, CSRF handling, authentication, error mapping, and CESU-8.
    • The test suite now contains 50 tests.

    New Contributors

    Full Changelog: https://github.com/Salamek/huawei-lte-api/compare/1.11.0...2.0.0

  2. 1.11.02025-03-15 · 2025-03-15 20:00 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/Salamek/huawei-lte-api/compare/1.10...1.11.0

  3. 1.102024-08-22 · 2024-08-22 00:07 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/Salamek/huawei-lte-api/compare/1.9.3...1.10

  4. 1.8.1New release2024-01-07 · 2024-01-07 15:20 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/Salamek/huawei-lte-api/compare/1.7.3...1.8.1

  5. 1.7New release2023-06-13 · 2023-06-13 00:39 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/Salamek/huawei-lte-api/compare/1.6.11...1.7

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    huawei-lte-api

    API For huawei LAN/WAN LTE Modems, you can use this to simply send SMS, get information about your internet usage, signal, and tons of other stuff

    Tox tests

    Please consider sponsoring if you're using this package commercially, my time is not free :) You can sponsor me by clicking on "Sponsor" button in top button row. Thank You.

    Tested on:

    3G/LTE Routers:
    • Huawei B310s-22
    • Huawei B311-221
    • Huawei B315s-22
    • Huawei B525s-23a
    • Huawei B525s-65a
    • Huawei B715s-23c
    • Huawei B528s
    • Huawei B535-232
    • Huawei B628-265
    • Huawei B612-233
    • Huawei B818-263
    • Huawei E5180s-22
    • Huawei E5186s-22a
    • Huawei E5576-320
    • Huawei E5577Cs-321
    • Huawei E8231
    • Huawei E5573s-320
    • SoyeaLink B535-333
    3G/LTE USB sticks:

    (Device must support NETWork mode aka. "HiLink" version, it wont work with serial mode)

    • Huawei E3131
    • Huawei E8372h-608
    • Huawei E3372
    • Huawei E3531
    • Huawei E5530As-2
    5G Routers:
    • Huawei 5G CPE Pro 2 (H122-373)
    • Huawei 5G CPE Pro (H112-372)
    • Huawei 5G CPE6 (H165-383)

    (probably will work for other Huawei LTE devices too)

    Will NOT work on:

    LTE Routers:
    • Huawei B2368-22 (Incompatible firmware, testing device needed!)
    • Huawei B593s-22 (Incompatible firmware, testing device needed!)

    Installation

    PIP (pip3 on some distros)

    pip install huawei-lte-api
    

    Repository

    You can also use these repositories maintained by me

    Debian and derivatives

    Add repository by running these commands

    wget -O- https://repository.salamek.cz/deb/salamek.gpg | sudo tee /usr/share/keyrings/salamek-archive-keyring.gpg
    echo "deb     [signed-by=/usr/share/keyrings/salamek-archive-keyring.gpg] https://repository.salamek.cz/deb/pub all main" | sudo tee /etc/apt/sources.list.d/salamek.cz.list
    

    And then you can install a package python3-huawei-lte-api

    apt update && apt install python3-huawei-lte-api
    
    Archlinux

    Add repository by adding this at end of file /etc/pacman.conf

    [salamek]
    Server = https://repository.salamek.cz/arch/pub/any
    SigLevel = Optional
    

    and then install by running

    pacman -Sy python-huawei-lte-api
    
    Gentoo
    emerge dev-python/huawei-lte-api
    

    Usage

    from huawei_lte_api.Client import Client
    from huawei_lte_api.Connection import Connection
    
    # with Connection('http://192.168.8.1/') as connection: For limited access, I have valid credentials no need for limited access
    with Connection("http://admin:[email protected]/") as connection:
        client = Client(connection)  # This just simplifies access to separate API groups, you can use device = Device(connection) if you want
    
        print(client.device.signal())  # Can be accessed without authorization
        print(client.device.information())  # Needs valid authorization, will throw exception if invalid credentials are passed in URL
    
    
    # For more API calls just look on code in the huawei_lte_api/api folder, there is no separate DOC yet
    

    Result dict

    {
        "DeviceName": "B310s-22",
        "SerialNumber": "MY_SERIAL_NUMBER",
        "Imei": "MY_IMEI",
        "Imsi": "MY_IMSI",
        "Iccid": "MY_ICCID",
        "Msisdn": None,
        "HardwareVersion": "WL1B310FM03",
        "SoftwareVersion": "21.311.06.03.55",
        "WebUIVersion": "17.100.09.00.03",
        "MacAddress1": "EHM:MY:MAC",
        "MacAddress2": None,
        "ProductFamily": "LTE",
        "Classify": "cpe",
        "supportmode": None,
        "workmode": "LTE",
    }
    

    Code examples

    Some code examples are in /examples folder

    Monitoring

    SMS

    Ports to other languages

    Donations

    • 250 CZK (9.79 EUR) for B535-232 fund, thx @larsvinc !
    • 371,69 CZK (14.32 EUR) by Oleg Jusaew
    • 292 CZK (11.50 EUR) by Toth-Mate Akos
    • 441 CZK (18.12 EUR) by Olexandr Shamin