Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

GSIServer

GSIServer receives payloads from CS2, keeps the state of each tracked player, and runs event handlers. It’s a small FastAPI app with one route, POST /, run by uvicorn.

class GSIServer:
    def __init__(
        self,
        player_ids: str | Sequence[str],
        port: int = 4213,
        host: str = "0.0.0.0",
    ) -> None: ...
ParameterDefaultMeaning
player_idsThe SteamID64 of each player to track, as one string or a sequence of strings. Payloads from other players are dropped.
port4213The port to listen on. It has to match the uri in the CS2 config file.
host"0.0.0.0"The address to listen on. The default listens on every network interface.

Warning

With the default host, other machines on your network can send the server payloads too. If CS2 and pygsi run on the same machine, pass host="127.0.0.1".

Properties

player_ids is the frozenset[str] of tracked SteamID64s.

states is a dict[str, GameState | None] from each tracked SteamID64 to that player’s latest state. A player’s value is None until their first stored payload.

state is the latest GameState | None of the only tracked player. It raises RuntimeError when more than one player is tracked.

Methods

run() starts the server with uvicorn.run and blocks until the process is interrupted. uvicorn creates and runs its own event loop, so run() can’t be called from code that’s already inside one.

Event Decorators

Each event has a decorator, such as on_round_start, which registers an async handler and returns it unchanged. A handler takes (player_id: str, old: T | None, new: T) and returns None, where T depends on the event. Events lists every event with its T.