Reading data¶
Reading data¶
get_server_data() lets you ask for any mix of sections in a single request. Section names
aren't case-sensitive. You'll always get Online, LastHeartbeat, NextHeartbeat, Cursor
and Server back too.
| Kind | Sections |
|---|---|
| Live | Players, Tracks, Vehicles, World, Teams, Queue, Robberies, Atms, Incidents, Fires, Medical, Trees, TrafficLights, Doors, Radio, Jobs, Bounties, Economy, Trailers, Placeables, PlaceablesSummary |
| Server | Staff, Groups, Bans, Settings, Catalogue |
| Logs | KillLogs, ModCalls, RadioCalls, JoinLogs, Events, CommandLogs, CommandResults, Shots, Audit |
data = api.get_server_data(
"Events", "KillLogs", "Shots",
since=cursor, # only entries newer than the Cursor from a previous response
limit=200, # max entries per log (up to 500)
)
bans = api.get_bans(limit=100, offset=0) # one page: {"Total", "Offset", "List"}
for ban in api.iter_bans(): # or every ban, page by page
...
audit = api.get_audit(category=["Moderation", "Staff"], user="amy_hx", limit=50)
older = api.get_audit(before=audit["Next"])
# Only download the data again if something's changed
data = api.get_server_data("Players")
again = api.get_server_data("Players", if_none_match=data.etag) # None if nothing changed
There's also a helper for each section: get_server, is_online, get_players,
get_tracks, get_vehicles, get_world, get_teams, get_queue, get_robberies,
get_atms, get_incidents, get_staff, get_groups, get_bans, iter_bans,
get_settings, get_catalogue, get_killlogs, get_modcalls, get_radiocalls,
get_joinlogs, get_events, get_commandlogs, get_command_results, get_shots and
get_audit.
Each helper makes its own request, and you only get one of these a second with a server key.
If you need a few sections at once, ask for them all in one get_server_data() call.
get_catalogue() is the exception. The Catalogue is big and only changes when the game
updates, so oxrpy keeps a copy for an hour and hands that back instead of asking again. Pass
refresh=True to get a fresh one.
Autocomplete¶
Your editor knows the shape of everything the API sends back, so it suggests field names as you type and flags typos before you run anything:
for player in api.get_players() or []:
player["Usernmae"] # your editor flags this: did you mean "Username"?
This works in VS Code, PyCharm and anything else that understands Python type hints, with both
the normal and async clients. The data is still plain dicts, so nothing changes when your code
runs. If you want to use the types in your own code, they're in oxrpy.types: