Wialon API Sessions
- class terminusgps.wialon.session.WialonSession(token: str | None = None, sid: str | None = None, scheme: str = 'https', host: str = 'hst-api.wialon.com', port: int = 443, log_level: int = 10, log_days: int = 10)[source]
Starts or continues a Wialon API session.
- Parameters:
token (
str
|None
) – An optional Wialon API token. Default isWIALON_TOKEN
.sid (
str
|None
) – An optional Wialon API session id. If provided, the session is continued.scheme (
str
) – HTTP request scheme to use. Default is"https"
.host (
str
) – Wialon API host url. Default is"hst-api.wialon.com"
.port (
int
) – Wialon API host port. Default is443
.log_level (
int
) – Level of emitted logs. Default is10
.
- Returns:
Nothing.
- Return type:
Public Data Attributes:
Whether or not the session is logged in.
Gis geocode URL.
Gis rendering URL.
Gis routing URL.
Gis search URL.
Gis session id.
IP of the client hosting the Wialon session.
Hardware gateway IP.
Hardware gateway domain name, should evaluate to
hw_gw_ip
if present.The Wialon Source Developer Kit (WSDK) version number of the session.
A Wialon user ID this session is operating as.
A Wialon username the session is operating as.
Shortcut property for
WialonSession.wialon_api.sid
.A Wialon API token set during
WialonSession.__init__()
.Public Methods:
__init__
([token, sid, scheme, host, port, ...])Starts or continues a Wialon API session.
__str__
()Return str(self).
__repr__
()Return repr(self).
__enter__
()Logs into the Wialon API using
login()
.__exit__
(exc_type, exc_value, exc_traceback)Logs out of the session by calling
logout()
.login
(token[, flags])Logs into the Wialon API and starts a new session.
logout
()Logs out of the Wialon API session.
Private Methods:
_set_login_response
(login_response)Sets the Wialon API session's attributes based on a login response.
- property hw_gw_dns: str | None
Hardware gateway domain name, should evaluate to
hw_gw_ip
if present.
- property id: str | None
Shortcut property for
WialonSession.wialon_api.sid
.Returns
None
if the session wasn’t logged in.
- login(token: str, flags: int = 35) str [source]
Logs into the Wialon API and starts a new session.
- Parameters:
- Raises:
WialonError – If the login fails.
AssertionError – If the login token was not set.
- Returns:
The new session id.
- Return type:
- property token: str
A Wialon API token set during
WialonSession.__init__()
.Default token value is
WIALON_TOKEN
.- Type:
- Value:
Usage
from terminusgps.wialon.session import WialonSession
# Create a session and login to it
session = WialonSession()
session.login(token="my_secure_token")
# Use the logged in session to perform API actions
session.wialon_api.core_search_item(**{"id": "123", "flags": 1})
# Don't forget to logout of the session
# Sessions are destroyed after 5min of inactivity
session.logout()
# Alternatively, use a context manager
# The context manager handles logging in and out of the session.
with WialonSession() as session:
session.wialon_api.core_search_item(**{"id": "123", "flags": 1})
# If you already have a session id, no need to login again
session = WialonSession(sid="my_valid_session_id")
session.wialon_api.core_search_item(**{"id": "123", "flags": 1})