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 is WIALON_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 is 443.

  • log_level (int) – Level of emitted logs. Default is 10.

Returns:

Nothing.

Return type:

None

Public Data Attributes:

active

Whether or not the session is logged in.

gis_geocode

Gis geocode URL.

gis_render

Gis rendering URL.

gis_routing

Gis routing URL.

gis_search

Gis search URL.

gis_sid

Gis session id.

host

IP of the client hosting the Wialon session.

hw_gw_ip

Hardware gateway IP.

hw_gw_dns

Hardware gateway domain name, should evaluate to hw_gw_ip if present.

wsdk_version

The Wialon Source Developer Kit (WSDK) version number of the session.

uid

A Wialon user ID this session is operating as.

username

A Wialon username the session is operating as.

id

Shortcut property for WialonSession.wialon_api.sid.

token

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 active: bool

Whether or not the session is logged in.

Type:

bool

Value:

False

property gis_geocode: str | None

Gis geocode URL.

Type:

str | None

Value:

None

property gis_render: str | None

Gis rendering URL.

Type:

str | None

Value:

None

property gis_routing: str | None

Gis routing URL.

Type:

str | None

Value:

None

Gis search URL.

Type:

str | None

Value:

None

property gis_sid: str | None

Gis session id.

Type:

str | None

Value:

None

property host: str | None

IP of the client hosting the Wialon session.

Type:

str | None

Value:

None

property hw_gw_dns: str | None

Hardware gateway domain name, should evaluate to hw_gw_ip if present.

Type:

str | None

Value:

None

property hw_gw_ip: str | None

Hardware gateway IP.

Type:

str | None

Value:

None

property id: str | None

Shortcut property for WialonSession.wialon_api.sid.

Returns None if the session wasn’t logged in.

Type:

str | None

Value:

None

login(token: str, flags: int = 35) str[source]

Logs into the Wialon API and starts a new session.

Parameters:
  • token (str) – An active Wialon API token.

  • flags (int) – A login response flag integer.

Raises:
Returns:

The new session id.

Return type:

str

logout() None[source]

Logs out of the Wialon API session.

Returns:

Nothing.

Return type:

None

property token: str

A Wialon API token set during WialonSession.__init__().

Default token value is WIALON_TOKEN.

Type:

str

Value:

WIALON_TOKEN

property uid: str | None

A Wialon user ID this session is operating as.

Type:

str | None

Value:

None

property username: str | None

A Wialon username the session is operating as.

Type:

str | None

Value:

None

property wsdk_version: str | None

The Wialon Source Developer Kit (WSDK) version number of the session.

Type:

str | None

Value:

None

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})