sourcewatch


Namesourcewatch JSON
Version 0.0.7 PyPI version JSON
download
home_pageNone
SummaryA library to query information of Goldsrc and Source servers.
upload_time2025-07-14 20:39:07
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseThe MIT License Copyright (c) 2012-2018 Alex Kuhrt <alex@qrt.de> Copyright (c) 2010 - 2012 Andreas Klauer <Andreas.Klauer@metamorpher.de> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords goldsrc mcp query server source steam valve
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SourceWatch

[![Python Version](https://img.shields.io/pypi/pyversions/sourcewatch)](https://pypi.org/project/sourcewatch/)
[![PyPI Version](https://img.shields.io/pypi/v/sourcewatch)](https://pypi.org/project/sourcewatch/)
[![License](https://img.shields.io/pypi/l/sourcewatch)](https://github.com/SourceWatch/SourceWatch/blob/master/LICENSE)

A Python 3 library for querying information from Valve's GoldSrc and Source game servers. This library provides a complete implementation of the [Server Queries protocol](http://developer.valvesoftware.com/wiki/Server_Queries) used by games like Counter-Strike, Half-Life, Team Fortress, and many others.

## Features

- Support for both GoldSrc and Source engine servers
- Query server information, player lists, and server rules
- Ping measurement functionality
- Multi-packet response handling
- Modern Python 3.8+ support with type hints (Pydantic)
- MCP ready

## Installation

Install SourceWatch using pip:

```bash
pip install sourcewatch
```

## Quick Start

```python
import SourceWatch

# Connect to a server
server = SourceWatch.Query('server.example.com', 27015)

# Get basic server information
info = server.info()
print(f"Server: {info['info']['server_name']}")
print(f"Map: {info['info']['game_map']}")
print(f"Players: {info['info']['players_current']}/{info['info']['players_max_slots']}")

# Get player list
players = server.players()
for player in players['players']:
    print(f"Player: {player['name']} (Score: {player['kills']})")

# Get server rules/settings
rules = server.rules()
for key, value in rules['rules'].items():
    print(f"{key}: {value}")

# Measure ping
ping = server.ping()
print(f"Ping: {ping}ms")
```

## API Reference

### SourceWatch.Query(host, port=27015, timeout=10)

Main class for querying game servers.

**Parameters:**
- `host` (str): Server hostname or IP address
- `port` (int, optional): Server port (default: 27015)
- `timeout` (int, optional): Connection timeout in seconds (default: 10)

**Methods:**

#### `info()`
Returns basic server information including name, map, player count, and game details.

**Returns:** Dictionary with server information

```python
{
    "info": {
        "server_name": "My Game Server",
        "game_map": "de_dust2",
        "game_title": "Counter-Strike: Source",
        "players_current": 12,
        "players_max_slots": 24,
        "players_bots": 2,
        "players_humans": 10,
        "server_type": "d",  # 'd' for dedicated, 'l' for listen
        "server_os": "l",    # 'l' for Linux, 'w' for Windows
        "server_password_protected": 0,
        "server_vac_secured": 1,
        # ... additional fields
    },
    "server": {
        "ip": "127.0.0.1",
        "port": 27015,
        "ping": 42.5
    }
}
```

#### `players()`
Returns list of players currently on the server.

**Returns:** Dictionary with player information

```python
{
    "players": [
        {
            "index": 0,
            "name": "PlayerName",
            "kills": 15,
            "play_time": 1234.5
        },
        # ... more players
    ],
    "server": {
        "ip": "127.0.0.1",
        "port": 27015,
        "ping": 45.2
    }
}
```

#### `rules()`
Returns server configuration and rules.

**Returns:** Dictionary with server rules

```python
{
    "rules": {
        "sv_gravity": "800",
        "mp_friendlyfire": "1",
        "mp_timelimit": "30",
        # ... more rules
    },
    "server": {
        "ip": "127.0.0.1",
        "port": 27015,
        "ping": 38.7
    }
}
```

#### `ping(num_requests=3)`
Measures server response time by sending multiple info requests.

**Parameters:**
- `num_requests` (int, optional): Number of ping requests to average (default: 3)

**Returns:** Average ping in milliseconds (float)

## Supported Games

This library works with servers running games that use Valve's server query protocol, including:

- **Source Engine Games:**
  - Counter-Strike: Source
  - Half-Life 2: Deathmatch
  - Team Fortress 2
  - Garry's Mod
  - Left 4 Dead series
  - Portal 2

- **GoldSrc Engine Games:**
  - Counter-Strike 1.6
  - Half-Life
  - Team Fortress Classic
  - Day of Defeat

## Error Handling

The library raises `SourceWatchError` for various error conditions:

```python
import SourceWatch

try:
    server = SourceWatch.Query('invalid-server.com')
    info = server.info()
except SourceWatch.SourceWatchError as e:
    print(f"Query failed: {e}")
except socket.timeout:
    print("Connection timed out")
except socket.gaierror:
    print("Could not resolve hostname")
```

## Advanced Usage

### Custom Timeout

```python
# Set a custom timeout for slow connections
server = SourceWatch.Query('server.example.com', timeout=30)
```

### Logging

Enable debug logging to see detailed protocol communication:

```python
import logging
logging.basicConfig(level=logging.DEBUG)

server = SourceWatch.Query('server.example.com')
```

## Development

### Running Tests

```bash
python -m pytest test/
```

### Requirements

- Python 3.8 or higher
- No external dependencies for core functionality

## Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Credits

- **Alex Kuhrt** - Current maintainer
- **Andreas Klauer** - Original SourceLib implementation

This project is a modernized fork of [SourceLib](https://github.com/frostschutz/SourceLib).

## Changelog

### Version 0.0.4
- Modernized packaging with pyproject.toml
- Fixed server query protocol implementation
- Added comprehensive test suite
- Improved error handling and logging

---

For more information, visit the [GitHub repository](https://github.com/SourceWatch/SourceWatch) or check out the [issues page](https://github.com/SourceWatch/SourceWatch/issues) for bug reports and feature requests.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sourcewatch",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "goldsrc, mcp, query, server, source, steam, valve",
    "author": null,
    "author_email": "Alex Kuhrt <alex@qrt.de>",
    "download_url": "https://files.pythonhosted.org/packages/06/87/f09fcd2dc5ddc2f208b72a57f3877bdac6fe588d9c112ab876dc36d1370e/sourcewatch-0.0.7.tar.gz",
    "platform": null,
    "description": "# SourceWatch\n\n[![Python Version](https://img.shields.io/pypi/pyversions/sourcewatch)](https://pypi.org/project/sourcewatch/)\n[![PyPI Version](https://img.shields.io/pypi/v/sourcewatch)](https://pypi.org/project/sourcewatch/)\n[![License](https://img.shields.io/pypi/l/sourcewatch)](https://github.com/SourceWatch/SourceWatch/blob/master/LICENSE)\n\nA Python 3 library for querying information from Valve's GoldSrc and Source game servers. This library provides a complete implementation of the [Server Queries protocol](http://developer.valvesoftware.com/wiki/Server_Queries) used by games like Counter-Strike, Half-Life, Team Fortress, and many others.\n\n## Features\n\n- Support for both GoldSrc and Source engine servers\n- Query server information, player lists, and server rules\n- Ping measurement functionality\n- Multi-packet response handling\n- Modern Python 3.8+ support with type hints (Pydantic)\n- MCP ready\n\n## Installation\n\nInstall SourceWatch using pip:\n\n```bash\npip install sourcewatch\n```\n\n## Quick Start\n\n```python\nimport SourceWatch\n\n# Connect to a server\nserver = SourceWatch.Query('server.example.com', 27015)\n\n# Get basic server information\ninfo = server.info()\nprint(f\"Server: {info['info']['server_name']}\")\nprint(f\"Map: {info['info']['game_map']}\")\nprint(f\"Players: {info['info']['players_current']}/{info['info']['players_max_slots']}\")\n\n# Get player list\nplayers = server.players()\nfor player in players['players']:\n    print(f\"Player: {player['name']} (Score: {player['kills']})\")\n\n# Get server rules/settings\nrules = server.rules()\nfor key, value in rules['rules'].items():\n    print(f\"{key}: {value}\")\n\n# Measure ping\nping = server.ping()\nprint(f\"Ping: {ping}ms\")\n```\n\n## API Reference\n\n### SourceWatch.Query(host, port=27015, timeout=10)\n\nMain class for querying game servers.\n\n**Parameters:**\n- `host` (str): Server hostname or IP address\n- `port` (int, optional): Server port (default: 27015)\n- `timeout` (int, optional): Connection timeout in seconds (default: 10)\n\n**Methods:**\n\n#### `info()`\nReturns basic server information including name, map, player count, and game details.\n\n**Returns:** Dictionary with server information\n\n```python\n{\n    \"info\": {\n        \"server_name\": \"My Game Server\",\n        \"game_map\": \"de_dust2\",\n        \"game_title\": \"Counter-Strike: Source\",\n        \"players_current\": 12,\n        \"players_max_slots\": 24,\n        \"players_bots\": 2,\n        \"players_humans\": 10,\n        \"server_type\": \"d\",  # 'd' for dedicated, 'l' for listen\n        \"server_os\": \"l\",    # 'l' for Linux, 'w' for Windows\n        \"server_password_protected\": 0,\n        \"server_vac_secured\": 1,\n        # ... additional fields\n    },\n    \"server\": {\n        \"ip\": \"127.0.0.1\",\n        \"port\": 27015,\n        \"ping\": 42.5\n    }\n}\n```\n\n#### `players()`\nReturns list of players currently on the server.\n\n**Returns:** Dictionary with player information\n\n```python\n{\n    \"players\": [\n        {\n            \"index\": 0,\n            \"name\": \"PlayerName\",\n            \"kills\": 15,\n            \"play_time\": 1234.5\n        },\n        # ... more players\n    ],\n    \"server\": {\n        \"ip\": \"127.0.0.1\",\n        \"port\": 27015,\n        \"ping\": 45.2\n    }\n}\n```\n\n#### `rules()`\nReturns server configuration and rules.\n\n**Returns:** Dictionary with server rules\n\n```python\n{\n    \"rules\": {\n        \"sv_gravity\": \"800\",\n        \"mp_friendlyfire\": \"1\",\n        \"mp_timelimit\": \"30\",\n        # ... more rules\n    },\n    \"server\": {\n        \"ip\": \"127.0.0.1\",\n        \"port\": 27015,\n        \"ping\": 38.7\n    }\n}\n```\n\n#### `ping(num_requests=3)`\nMeasures server response time by sending multiple info requests.\n\n**Parameters:**\n- `num_requests` (int, optional): Number of ping requests to average (default: 3)\n\n**Returns:** Average ping in milliseconds (float)\n\n## Supported Games\n\nThis library works with servers running games that use Valve's server query protocol, including:\n\n- **Source Engine Games:**\n  - Counter-Strike: Source\n  - Half-Life 2: Deathmatch\n  - Team Fortress 2\n  - Garry's Mod\n  - Left 4 Dead series\n  - Portal 2\n\n- **GoldSrc Engine Games:**\n  - Counter-Strike 1.6\n  - Half-Life\n  - Team Fortress Classic\n  - Day of Defeat\n\n## Error Handling\n\nThe library raises `SourceWatchError` for various error conditions:\n\n```python\nimport SourceWatch\n\ntry:\n    server = SourceWatch.Query('invalid-server.com')\n    info = server.info()\nexcept SourceWatch.SourceWatchError as e:\n    print(f\"Query failed: {e}\")\nexcept socket.timeout:\n    print(\"Connection timed out\")\nexcept socket.gaierror:\n    print(\"Could not resolve hostname\")\n```\n\n## Advanced Usage\n\n### Custom Timeout\n\n```python\n# Set a custom timeout for slow connections\nserver = SourceWatch.Query('server.example.com', timeout=30)\n```\n\n### Logging\n\nEnable debug logging to see detailed protocol communication:\n\n```python\nimport logging\nlogging.basicConfig(level=logging.DEBUG)\n\nserver = SourceWatch.Query('server.example.com')\n```\n\n## Development\n\n### Running Tests\n\n```bash\npython -m pytest test/\n```\n\n### Requirements\n\n- Python 3.8 or higher\n- No external dependencies for core functionality\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Credits\n\n- **Alex Kuhrt** - Current maintainer\n- **Andreas Klauer** - Original SourceLib implementation\n\nThis project is a modernized fork of [SourceLib](https://github.com/frostschutz/SourceLib).\n\n## Changelog\n\n### Version 0.0.4\n- Modernized packaging with pyproject.toml\n- Fixed server query protocol implementation\n- Added comprehensive test suite\n- Improved error handling and logging\n\n---\n\nFor more information, visit the [GitHub repository](https://github.com/SourceWatch/SourceWatch) or check out the [issues page](https://github.com/SourceWatch/SourceWatch/issues) for bug reports and feature requests.\n",
    "bugtrack_url": null,
    "license": "The MIT License\n        \n        Copyright (c) 2012-2018 Alex Kuhrt <alex@qrt.de>\n        Copyright (c) 2010 - 2012 Andreas Klauer <Andreas.Klauer@metamorpher.de>\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in\n        all copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n        THE SOFTWARE.",
    "summary": "A library to query information of Goldsrc and Source servers.",
    "version": "0.0.7",
    "project_urls": {
        "Homepage": "https://github.com/SourceWatch/SourceWatch",
        "Issues": "https://github.com/SourceWatch/SourceWatch/issues",
        "Repository": "https://github.com/SourceWatch/SourceWatch"
    },
    "split_keywords": [
        "goldsrc",
        " mcp",
        " query",
        " server",
        " source",
        " steam",
        " valve"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1b1842c4013070e2faad5dd4de0010e4fb7ddad25c7a8c6429329423a9eafc98",
                "md5": "fe5ed524989504bcafdcaf9807f95fcb",
                "sha256": "9035b65ddfb276fd05fe9c6dd44a6f7ebd31ceb3d1204b28d1b1201c7b620c0f"
            },
            "downloads": -1,
            "filename": "sourcewatch-0.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fe5ed524989504bcafdcaf9807f95fcb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 11508,
            "upload_time": "2025-07-14T20:39:05",
            "upload_time_iso_8601": "2025-07-14T20:39:05.816125Z",
            "url": "https://files.pythonhosted.org/packages/1b/18/42c4013070e2faad5dd4de0010e4fb7ddad25c7a8c6429329423a9eafc98/sourcewatch-0.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0687f09fcd2dc5ddc2f208b72a57f3877bdac6fe588d9c112ab876dc36d1370e",
                "md5": "501e679dbbb3236d02b7fe0d2ed4a42e",
                "sha256": "377db1cc60938bd67d58039d44db433ac5d80134a135309626edf553a1be2fdd"
            },
            "downloads": -1,
            "filename": "sourcewatch-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "501e679dbbb3236d02b7fe0d2ed4a42e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10885,
            "upload_time": "2025-07-14T20:39:07",
            "upload_time_iso_8601": "2025-07-14T20:39:07.528852Z",
            "url": "https://files.pythonhosted.org/packages/06/87/f09fcd2dc5ddc2f208b72a57f3877bdac6fe588d9c112ab876dc36d1370e/sourcewatch-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-14 20:39:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SourceWatch",
    "github_project": "SourceWatch",
    "github_not_found": true,
    "lcname": "sourcewatch"
}
        
Elapsed time: 1.03614s