Client and sessions

A Client opens maps as sessions. A Session is one map, loaded and ready; each Session.connect() opens a Gym on it. Both are context managers: a session closes itself, and every gym on it, at the end of its block.

from tickgym import Client, TelemetryGroup

with Client().open_map(r"C:\Maps\Example.Map.Gbx") as session:
    with session.connect(TelemetryGroup.RACE | TelemetryGroup.VEHICLE) as gym:
        ...
class Client(origin: str = 'http://127.0.0.1:46321', timeout: float = 120.0)

TICK on a machine, which opens maps as sessions.

Parameters:
  • origin – TICK’s address. The default is TICK on this machine.

  • timeout – Seconds to wait on TICK before giving up.

origin: str

TICK’s address.

timeout: float

Seconds to wait on TICK before giving up.

open_map(
path: Path | str,
laps: int | None = None,
) → Session

Opens a session on a map file of this machine. The first session on a map loads its world, which takes a few seconds; later sessions on the same map open at once.

Parameters:
  • path – The .Map.Gbx file.

  • laps – Laps to race on a multilap map; the map’s own count when None.

Returns:

The session, ready for Session.connect.

Raises:

TickError – TICK refused, for example because the file is not a map it can load.

open_map_bytes(data: bytes, laps: int | None = None) → Session

Opens a session on a map given as bytes, for a map that is not a file on this machine.

Parameters:
  • data – The contents of a .Map.Gbx file.

  • laps – Laps to race on a multilap map; the map’s own count when None.

Raises:

TickError – TICK refused the map.

sessions() → list[SessionSummary]

Every session open on the host.

session(session_id: int) → SessionDetail

One session and its open gyms.

Raises:

TickError – No session has that id.

close_session(session_id: int) → None

Closes a session and every gym on it.

status() → HostStatus

TICK’s capacity and state.

class Session

One map, loaded and ready on the server. Each connect() opens a gym on it, alive for as long as its connection; the session itself stays until close(), or until it has had no connection for the host’s idle timeout. A session is a context manager that closes itself.

client: Client

The client the session was opened through.

info: SessionInfo

The session as it was opened.

property id: int

The session’s id.

property endpoint: Endpoint

Where the session’s gym socket listens.

connect(
telemetry: TelemetryGroup,
lidar: Lidar | None = None,
timeout: float | None = 60.0,
) → Gym

Opens a gym on this map over its own connection.

Parameters:
  • telemetry – The groups every sample carries, combined with |.

  • lidar – The rays to cast on every sample. TelemetryGroup.LIDAR is its scan, and is in the telemetry exactly when a lidar is given.

  • timeout – Seconds to wait on the server before giving up, for connecting and for every read and write; None waits forever.

Returns:

The gym, a context manager that closes itself.

Raises:
gyms() → tuple[GymSummary, ...]

The gyms open on this session now.

close() → None

Closes the session and every gym on it.

Records

class SessionInfo

A session as it was opened.

endpoint: Endpoint

Where its gym socket listens.

map: MapSummary

The map it is on.

class SessionSummary

A session as Client.sessions lists it.

map: MapSummary

The map it is on.

gyms_open: int

Gyms open on it now; a connection is one gym.

created_at: datetime

When it was opened, UTC.

idle_ms: int

How long it has had no connection; the host closes it after its idle timeout.

class SessionDetail

A session and its open gyms, as Client.session returns it.

class GymSummary

One open gym of a session, as Session.gyms lists it.

telemetry: TelemetryGroup

The groups it samples, combined with |.

lidar_ray_count: int

Rays of its lidar, 0 for none.

ticks_simulated: int

Ticks it has simulated since it was opened.

snapshots: int

Snapshots it holds now.

class MapSummary

A map as the server identifies it.

sha256: str

The SHA-256 of the map file, in hex; the key TICK knows the map by.

map_uid: str

The map’s UID, as the game names it.

checkpoint_count: int

Checkpoints a race on it passes, the finish included, over every lap.

lap_count: int

Laps a race on it drives; 1 for a point-to-point map.

vehicle: VehicleType

The car the map starts in.

class Endpoint

Where a session’s gym socket listens.

class HostStatus

TICK’s state, as Client.status returns it.

cores: int

Processor cores the host runs gyms on.

sessions: int

Sessions open now.

gyms_open: int

Gyms open now, over every session.

gyms_available: int

Gyms that can still be opened.

endpoint: Endpoint

Where the gym socket listens.

resources: GameResourcePaths | None

The game folders in use, or None until TICK has reported them.

class GameResourcePaths

The game folders the host loads maps and cars from, as paths on the host.

game_data: Path

The game’s GameData folder.

user_data: Path

The user’s Trackmania documents folder.

packs: Path

The game’s Packs folder.