{"id":25999550,"url":"https://github.com/tomtana/python-glinet","last_synced_at":"2025-06-25T16:07:10.521Z","repository":{"id":55338247,"uuid":"523011850","full_name":"tomtana/python-glinet","owner":"tomtana","description":"Python3 GL-Inet client for json-rpc","archived":false,"fork":false,"pushed_at":"2024-03-17T23:09:28.000Z","size":2326,"stargazers_count":16,"open_issues_count":3,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-10T23:02:53.640Z","etag":null,"topics":["api","axt-1800","gl-inet","glinet","json-rpc","python","python3"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/python-glinet/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomtana.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-09T15:42:37.000Z","updated_at":"2025-02-18T13:21:47.000Z","dependencies_parsed_at":"2022-08-14T21:30:28.561Z","dependency_job_id":null,"html_url":"https://github.com/tomtana/python-glinet","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/tomtana/python-glinet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomtana%2Fpython-glinet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomtana%2Fpython-glinet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomtana%2Fpython-glinet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomtana%2Fpython-glinet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomtana","download_url":"https://codeload.github.com/tomtana/python-glinet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomtana%2Fpython-glinet/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261906847,"owners_count":23228356,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","axt-1800","gl-inet","glinet","json-rpc","python","python3"],"created_at":"2025-03-05T18:29:13.750Z","updated_at":"2025-06-25T16:07:10.488Z","avatar_url":"https://github.com/tomtana.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub Workflow Status\n(event)](https://img.shields.io/github/workflow/status/tomtana/python-glinet/Python%20package)](https://github.com/tomtana/python-glinet/actions/workflows/python-package.yml)\n[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/tomtana/python-glinet/Deploy%20static%20content%20to%20Pages?label=docs)](https://tomtana.github.io/python-glinet/)\n[![PyPI - Python\nVersion](https://img.shields.io/pypi/pyversions/python-glinet)](https://pypi.org/project/python-glinet)\n[![PyPI](https://img.shields.io/pypi/v/python-glinet)](https://pypi.org/project/python-glinet)\n[![Code\nCov](https://codecov.io/gh/tomtana/python-glinet/branch/main/graph/badge.svg?token=976L8ESH8K)](https://codecov.io/gh/tomtana/python-glinet)\n\npython-glinet - A Python3 Client for GL.Inet Router\n===================================================\n\n-   **Python3 client providing full access to the GL.Inet Luci API.**\n-   **Supported firmware versions: 4.0 onwards**\n-   **Dynamic method creation including docstring from the gl.inet\n    online documentation**\n-   **Api responses are recursively build as objects, such that you can\n    access all properties via \\'.\\'**\n-   **Cache for api description and hashed login**\n-   **Configurable background thread to keep connection alive**\n\n![image](https://github.com/tomtana/python-glinet/raw/main/ressources/python_glinet_demo.gif)\n\n**Note:**\n\n-   GL.Inet changed the api mechanism from REST to JSON-RPC with the\n    introduction of the firmware 4.0. Therefore, older versions are not\n    supported.\n-   There is no official English api documentation. The client parses\n    the Chinese documentation from\n    [here](https://dev.gl-inet.cn/docs/api_docs_page) and dynamically\n    creates the api methods. Once it is available, the repo will be\n    updated.\n-   The best way to navigate and explore the api is within an ipython\n    shell. A wrapper for ipython and terminal is on the roadmap.\n\nInstallation\n------------\n\n### PIP\n\n``` {.sourceCode .sh}\npip install python-glinet\n```\n\n### From Repo\n\n``` {.sourceCode .sh}\n#clone repository\ngit clone https://github.com/tomtana/python-glinet.git\ncd python-glinet\n```\n\nIt is strongly recommended to install the package inside an python\nvirtual environment (see\n[here](https://docs.python.org/3/tutorial/venv.html) for more infos).\nThe pip parameter `-e` is optional and gives you the possibility to edit\nthe `python-glinet` directly in the folder.\n\n``` {.sourceCode .sh}\npython3 -m venv venv\nsource venv/bin/activate\npip install -e .\n```\n\nGetting Started\n---------------\n\nThe heart piece of `python-glinet` is the `GlInet` class. It is manages\nauthentication, session and communication with the api. In case you\nmodified the router default settings such as ip-address or username you\nneed to pass them as parameter (see the documentation of the\n[GlInet](https://tomtana.github.io/python-glinet/glinet.html) class for\nmore details).\n\nFor browsing the api using the dynamically created api\\_client, it is\nassumed that the commands are executed in an ipython shell.\n\n**Warning:**\n\nEven though possible, it is strongly discouraged to pass the password as\na parameter.\n\n**Note:**\n\n-   The constructor is checking if a api description is already in the\n    persistence and will load it from the gl.inet online documentation\n    if not.\n-   Make sure you check and understand the default settings\n\n``` {.sourceCode .python}\nfrom pyglinet import GlInet\nglinet = GlInet()\n```\n\n### Login\n\n``` {.sourceCode .python}\nglinet.login()\n```\n\nThe login method call has deliberately not been integrated into the\nconstructor. For convenience it is possible to instantiate the object\nand login as shown below.\n\n``` {.sourceCode .python}\n# one liner: instantiation and login\nglinet = GlInet().login()\n```\n\n**Note:**\n\n-   if no password is passed as parameter in the constructor, `login()`\n    will try to load login data from persistence\n-   if no success ask via prompt and persist settings\n-   start background thread to keep connection alive\n\n### API Access Via Dynamically Created Client\n\nMake sure you are in an ipython shell and logged in. Then, generate the\n`api_client`.\n\n``` {.sourceCode .python}\napi_client = glinet.get_api_client()\n```\n\nYou have also direct access to the api via the `api` property of the\n`GlInet` instance.\n\n#### General\n\n-   The api structure is as follow:\n    **client.\\\u003cfunctionial\\_group\\\u003e.\\\u003cmethod\\\u003e**\n-   Due to python naming rules for variables, all \\\"-\\\" are replaced\n    with \\\"\\_\\\" for the api method construction. **e.g. wg-client\n    becomes wg\\_client.**\n-   Use code completion and docstring to intuitively navigate the api\n\n#### Functional Groups\n\nJust call your client to see all available api function groups.\n\n    api_client\n\nOr same result with\n\n    glinet.api\n\n``` {.sourceCode .bash}\nOut[11]:\nFunction\n------------------\nrepeater\nrs485\nqos\nacl\nmodem\nlogread\nigmp\ncustom_dns\ndns\ndlna\nnas_web\nadguardhome\ns2s\nsamba\nswitch_button\ndiag\nrtty\nnetwork\nupgrade\nreboot\nwg_server\nfirewall\novpn_server\nvpn_policy\nfan\nsystem\nwg_client\ncable\nled\nui\nnetmode\nddns\nipv6\novpn_client\nplugins\ntethering\nmacclone\nlan\nedgerouter\nclients\nwifi\ncloud\ncloud_batch_manage\n```\n\n#### Methods\n\nTo explore the methods of a function group, just select it and hit\nenter.\n\n``` {.sourceCode .python}\napi_client.wg_client\n```\n\n``` {.sourceCode .bash}\nOut[6]:\nFunction\n--------------------\nget_recommend_config\nget_third_config\nadd_config\nset_config\nremove_config\nclear_config_list\nget_config_list\nstart\nstop\nget_status\ncheck_config\nconfirm_config\nadd_group\nremove_group\nset_group\nget_group_list\nget_all_config_list\nset_proxy\nadd_route\nset_route\nget_route_list\nremove_route\n```\n\n#### Parameters\n\nSelect your method and press enter. A list for all possible parameters\nare printed. A parameter prepended with `?` is optional.\n\n``` {.sourceCode .python}\napi_client.wg_client.set_config\n```\n\n``` {.sourceCode .bash}\nOut[8]:\nParameter              Type    Description\n---------------------  ------  ------------------\nname                   string  节点名\naddress_v4             string  节点IPv4子网\n?address_v6            string  节点IPv6子网\nprivate_key            string  节点私钥\nallowed_ips            string  节点的allowedips\nend_point              string  节点的endpoint\npublic_key             string  节点公钥\n?dns                   string  节点的dns\n?preshared_key         string  预分享密钥\n?ipv6_enable           bool    是否启用IPv6\npresharedkey_enable    bool    是否使用预分享密钥\ngroup_id               number  组ID\npeer_id                number  配置ID\n?listen_port           number  监听端口\n?persistent_keepalive  number  节点保活\n?mtu                   number  节点的mtu\n```\n\n#### Docstring\n\nYou can also show the docstring by appending a `?` to the method. It\nwill show all the parameters and usage examples.\n\n``` {.sourceCode .text}\napi_client.wg_client.set_config?\n```\n\n``` {.sourceCode .text}\nSignature: api.wg_client.set_config(params=None)\nType:      GlInetApiCall\nFile:      ~/.local/lib/python3.10/site-packages/pyglinet/api_helper.py\nDocstring:\nAvailable parameters (?=optional):\nParameter              Type    Description\n---------------------  ------  ------------------\nname                   string  节点名\naddress_v4             string  节点IPv4子网\n?address_v6            string  节点IPv6子网\nprivate_key            string  节点私钥\nallowed_ips            string  节点的allowedips\nend_point              string  节点的endpoint\npublic_key             string  节点公钥\n?dns                   string  节点的dns\n?preshared_key         string  预分享密钥\n?ipv6_enable           bool    是否启用IPv6\npresharedkey_enable    bool    是否使用预分享密钥\ngroup_id               number  组ID\npeer_id                number  配置ID\n?listen_port           number  监听端口\n?persistent_keepalive  number  节点保活\n?mtu                   number  节点的mtu\n\nExample request:\n{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"call\\\",\\\"params\\\":[\\\"\\\",\\\"wg-client\\\",\\\"set_config\\\",{\\\"group_id\\\":3212,\\\"peer_id\\\":1254,\\\"name\\\":\\\"test\\\",\\\"address_v4\\\":\\\"10.8.0.0/24\\\",\\\"address_v6\\\":\\\"fd00:db8:0:123::/64\\\",\\\"private_key\\\":\\\"XVpIdr+oYjTcgDwzSZmNa1nSsk8JO+tx1NBo17LDBAI=\\\",\\\"allowed_ips\\\":\\\"0.0.0.0/0,::/0\\\",\\\"end_point\\\":\\\"103.231.88.18:3102\\\",\\\"public_key\\\":\\\"zv0p34WZN7p2vIgehwe33QF27ExjChrPUisk481JHU0=\\\",\\\"dns\\\":\\\"193.138.219.228\\\",\\\"presharedkey_enable\\\":false,\\\"listen_port\\\":22536,\\\"persistent_keepalive\\\":25,\\\"mtu\\\":1420,\\\"ipv6_enable\\\":true}],\\\"id\\\":1}\n\nExample response:\n{\\\"jsonrpc\\\": \\\"2.0\\\", \\\"id\\\": 1, \\\"result\\\": {}}\n```\n\n#### Method call\n\nJust call the method as usual. Check the usage examples to understand\nhow parameters need to be passed.\n\n    api_client.wg_client.get_all_config_list()\n\n``` {.sourceCode .bash}\nOut[12]: {'name': 'wg_client__get_all_config_list', 'config_list': [{'name': 'wg_client__get_all_config_list', 'username': '', 'group_name': 'AzireVPN', 'peers': [], 'password': '', 'auth_type': 1, 'group_id': 9690}]}\n```\n\n#### API Response Processing\n\nThe API json responses are recursively converted into objects. This\nprovides convenient access with code completion and point access to the\ndata.\n\n### API Access Via Direct Request\n\nInstead of using the dynamically created api\\_client, it is also\npossible to use the `GlInet` instance to make api requests. In fact, the\napi\\_client uses the `GlInet` session under the hood.\n\nOnce logged in, you simply can use the `glinet.request(method, params)`\nmethod to access or retrieve data from the api. Information about the\nmethod and the parameters can either be found in the\n[documentation](https://dev.gl-inet.cn/docs/api_docs_page) or via the\napi\\_client.\n\ne.g.\n\n    glinet.request(\"call\", [\"adguardhome\", \"get_config\"])\n\n``` {.sourceCode .bash}\nOut[12]: {'name': 'adguardhome__get_config', 'id': 13, 'jsonrpc': '2.0', 'result': {'name': 'adguardhome__get_config', 'enabled': False}}\n```\n\nis equivalent to\n\n    api_client.adguardhome.get_config()\n\n``` {.sourceCode .bash}\nOut[13]: {'name': 'adguardhome__get_config', 'enabled': False}\n```\n\n**Note:**\n\nThe output of the `request` method returns the whole response body\nwhereas the api\\_client just returns the result dict.\n\nRoadmap\n-------\n\n### V1.0.0\n\n-   ☒ Add dynamically docstring for API calls\n-   ☒ Create pip compliant package\n-   ☒ Publish pip package\n-   ☒ Add tests\n-   ☒ Improve documentation\n-   ☒ Increase test coverage\n-   ☒ replace crypt dependency to allow also Windows execution\n-   ☐ Add wrapper for execution via terminal\n\n### V2.0.0\n\n-   ☐ Add asyncio support\n-   ☐ \\...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomtana%2Fpython-glinet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomtana%2Fpython-glinet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomtana%2Fpython-glinet/lists"}