GlInet API
- class pyglinet.GlInet(url: str = 'https://192.168.8.1/rpc', username: str = 'root', password: Optional[str] = None, protocol_version: str = '2.0', keep_alive: bool = True, keep_alive_intervall: float = 30, verify_ssl_certificate: bool = False, update_api_reference_cache: bool = False, api_reference_url: str = 'https://dev.gl-inet.cn/docs/api_docs_api/', cache_folder: Optional[str] = None)[source]
This class manages the connection to a GL-Inet router and provides basic routines to send and receive data.
Important: Only works with firmware version >=4.0. The api has changed from REST api to json-rpc with the 4.0, so older firmware versions won’t work.
Before you can start making requests, you need to call the
login()
methodThe api calls can either be made via the GlInetApi object, which can be constructed via the get_api_client method, or via the request method directly.
- Parameters:
url – url to router rpc api
username – username, default is root.
password – password, if left empty, a prompt will ask you when login() is called. For security reasons, you should never pass your password here.
protocol_version – default 2.0
keep_alive – if set to True, a background thread will be started to keep the connection alive
keep_alive_intervall – intervall in which the background thread sends requests to the router
verify_ssl_certificate – either True/False or path to certificate.
update_api_reference_cache – if True, data is loaded from the web, otherwise application tries first to load data from cache.
api_reference_url – url to api description
cache_folder – folder where data is persisted. If left empty, default is $home/.python-pyglinet
- property api: GlInetApi
Method gives access to the autogenerated api functions. See also
get_api_client()
- Returns:
GlInetApi
- flush_cache() None [source]
Deletes the folder containing persisted login and api description as well as cached login data. It will NOT invalidate or reload api data. To achieve that see
get_api_client()
- Returns:
None
- get_api_client(update_description=False) GlInetApi [source]
Create GlInetApi object client to access api functions
- Parameters:
update_description – if True, api description is updated from web
- Returns:
GlInetApi
- login() GlInet [source]
Login and start background thread for keep_alive is configured. If password was set in constructor, cached values will be ignored. If password was not set (default) in
GlInet()
, you will be asked to enter the password the first time this function is called. If login was successful, the password hash is cashed.- Returns:
GlInet
- request(method: str, params: Union[Dict, List[str], str]) ResultContainer [source]
Send request. Function checks if method requires login and chooses the respective request wrapper. see
__request_with_sid()
and__request()
- Parameters:
method – api method call
params – params
- Returns:
ResultContainer