Python client
A small client for Python 3.9+ with no dependencies. It handles pagination, search, retries that honour Retry-After, and structured errors.
gzw-data on PyPI ↗, latest release 0.2.0. Tested on Python 3.9, 3.11 and 3.13.
Datasets are resolved from the live API. New datasets work immediately with client.list("name"), with nothing to update in the package.
Install and make a request#
pip install gzw-datafrom gzw_data import GzwDataClient
client = GzwDataClient()
weapon = client.get("weapons", "ak-12")
print(weapon["name"], weapon["caliber"])
page = client.list("weapons", per_page=5)
print(page["total"], [w["name"] for w in page["data"]])Every method returns plain dictionaries and lists, exactly as the API sends them.
Datasets and records#
datasets() maps every dataset name to its record count. get() returns one record, or None when the ID does not exist. iterate() walks every page for you.
names = client.datasets() # {'ammo': 79, 'weapons': 44, ...}
print(len(names), "datasets")
record = client.get("weapons", "does-not-exist") # None
for ammo in client.iterate("ammo"): # every record, page by page
print(ammo["name"])list() returns one page with the full envelope: data, page, perPage, total and totalPages.
Search and filters#
Search inside one dataset with search=, or across all datasets with search(). Extra keyword arguments become query filters.
# Inside one dataset
for gun in client.iterate("weapons", search="AK"):
print(gun["name"])
# Across every dataset: {dataset name: [records]}
results = client.search("AK-12")
print(list(results))
# Filter by any string field
keycards = client.list("keys", type="Keycard", per_page=25)Errors and retries#
Failures raise GzwApiError with status, a stable code, the request url and, for rate limits, retry_after in seconds. Rate-limit (429) and server (5xx) responses are retried with backoff, and a Retry-After header is honoured up to max_retry_wait. Client errors such as 404 or 400 are not retried.
from gzw_data import GzwApiError, GzwDataClient
client = GzwDataClient()
try:
client.list("not_a_dataset")
except GzwApiError as error:
print(error.status, error.code) # 404 ENDPOINT_NOT_FOUNDConfiguration#
All options are keyword arguments of GzwDataClient.
client = GzwDataClient(
base_url="https://gzw-data.dev/api/v1", # default
timeout=10.0, # seconds per request
retries=2, # extra attempts after the first
max_retry_wait=65.0, # longest Retry-After to wait for
user_agent="my-bot/1.0",
)For tests, pass opener= with a function that behaves like urllib.request.urlopen. The client's own test suite does this.
Rate limit#
- The API allows about 100 requests per minute per IP address, on a best-effort basis.
iterate()reads 100 records per request. Walking all datasets takes roughly one request per dataset, so cache results in a long-running bot instead of scanning on every command.- The client waits and retries when the limit is hit, which can make a large scan pause for up to a minute.
Client behaviour goes to the Python client repository. Missing or wrong game data goes to the feedback page.
