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: ...
| Parameter | Default | Meaning |
|---|---|---|
player_ids | The SteamID64 of each player to track, as one string or a sequence of strings. Payloads from other players are dropped. | |
port | 4213 | The 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, passhost="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.