Metadata-Version: 2.4
Name: pygsi-cs2
Version: 0.1.1
Summary: A Python library to interface with CS2's Game State Integration
Keywords: counter-strike,cs2,gsi,game-state-integration
Author: Parkkeo1
License-Expression: MIT
License-File: LICENSE
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Games/Entertainment
Classifier: Topic :: Software Development :: Libraries
Requires-Dist: fastapi>=0.100.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: uvicorn>=0.20.0
Requires-Python: >=3.11
Project-URL: Homepage, https://github.com/parkkeo1/pygsi-cs2
Project-URL: Documentation, https://parkkeo1.github.io/pygsi-cs2/
Project-URL: Repository, https://github.com/parkkeo1/pygsi-cs2
Project-URL: Issues, https://github.com/parkkeo1/pygsi-cs2/issues
Project-URL: Changelog, https://github.com/parkkeo1/pygsi-cs2/blob/main/CHANGELOG.md
Description-Content-Type: text/markdown

# pygsi

[![PyPI](https://img.shields.io/pypi/v/pygsi-cs2.svg)](https://pypi.org/project/pygsi-cs2/)
[![CI](https://github.com/parkkeo1/pygsi-cs2/actions/workflows/ci.yml/badge.svg)](https://github.com/parkkeo1/pygsi-cs2/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/pypi/l/pygsi-cs2.svg)](https://github.com/parkkeo1/pygsi-cs2/blob/main/LICENSE)

A Python library to interface with CS2's [Game State Integration](https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Game_State_Integration) (GSI).

pygsi runs the server that CS2 sends its game state to while you play. It parses each payload into typed Pydantic models, keeps the latest state for each player it tracks, and calls your async handlers when something happens, like a round starting, the bomb being planted, or a kill. It's built for players in a match, one or several at once, not for spectators or observers.

## Getting Started

pygsi needs Python 3.11 or newer. It's called `pygsi-cs2` on PyPI, and you import it as `pygsi`:

```sh
pip install pygsi-cs2
```

CS2 also needs a config file that tells it where to send updates. [Installation and CS2 Setup][setup] has the file and where to put it. Then a script like this prints a line for every kill:

```python
from pygsi import GSIServer, PlayerMatchStats

gsi = GSIServer(player_ids="76561198000000000")  # your SteamID64


@gsi.on_local_player_kill
async def kill(
    player_id: str, old: PlayerMatchStats | None, new: PlayerMatchStats
) -> None:
    print(f"Kill! That's {new.kills} this match")


gsi.run()
```

The [Quick Start][quick-start] walks through a longer version, and [`example/`](example/) has a script that logs every event.

## Documentation

The [book] covers the events, the game state, tracking several players, and every type. To build it locally, install [mdBook] and run `mdbook serve docs --open`.

## Development

You'll need [uv]. CI runs these checks:

```sh
uv sync --group dev --group test
uv run ruff format --check src tests example
uv run ruff check src tests example
uv run mypy src
uv run pytest tests
```

The tests replay real CS2 payloads from a practice match, stored in `tests/fixtures.json`, so they don't need the game.

## License

[MIT](https://github.com/parkkeo1/pygsi-cs2/blob/main/LICENSE)

[book]: https://parkkeo1.github.io/pygsi-cs2/
[setup]: https://parkkeo1.github.io/pygsi-cs2/installation.html
[quick-start]: https://parkkeo1.github.io/pygsi-cs2/quick-start.html
[mdBook]: https://rust-lang.github.io/mdBook/
[uv]: https://docs.astral.sh/uv/
