Skip to content

OxfordAPI

OxfordAPI

OxfordAPI(server_key=None, *, app_key=None, timeout=10, rate_limit='auto', max_retries=3, base_url=BASE_URL, session=None, global_key=None, server_id=None)

Bases: SyncSignatures, BaseClient

Client for the Oxford Response private server API (https://docs.oxfd.re).

For asyncio code (discord.py and the like) use :class:~oxrpy.AsyncOxfordAPI, which has the same methods.

Parameters:

Name Type Description Default
server_key Optional[str]

Your server's API key (Server Management > External > API Key).

None
app_key Optional[str]

Optional app key (oxa_…) from Oxford Roleplay, for apps used by many servers. Sent as Authorization: Bearer <app_key> alongside the server key.

None
timeout float

Seconds to wait for a response. Commands wait up to 8 seconds server side, so command requests always get at least 15.

10
rate_limit Union[str, float, None]

"auto" (default) paces requests to stay inside the API's published limits; "none"/None turns client-side pacing off; a number is the minimum seconds between requests of each kind.

'auto'
max_retries int

How many times to retry after a 429 (waiting Retry-After) or a network error / 500 on a read.

3
base_url str

Override the API base URL (for testing).

BASE_URL
session Optional[Session]

Use your own requests.Session.

None
global_key Optional[str]

Removed in 2.0; passing it warns and treats it as app_key.

None
server_id Optional[str]

No longer used; passing it warns.

None

alert

alert(message, style='normal', *, check=True)

An alert to everyone, style "normal", "yellow" or "red".

ambulance_callout

ambulance_callout(player=None, *, check=True)

A patient callout for that paramedic, or the first one free (RoleplayKit).

announce

announce(message, *, check=True)

An announcement to everyone.

assign_incident

assign_incident(incident_id, player, *, check=True)

Send a unit to an incident.

ban

ban(user, reason=None, duration=None, *, check=True)

Ban someone, in the server or not. duration is "30m", "12h", "7d", "1d12h", a timedelta or seconds; leave it out for a permanent ban. Reasons can be up to 200 characters.

clear_catalogue_cache

clear_catalogue_cache()

Forget the stored Catalogue, so the next get_catalogue asks the API.

clear_placeables

clear_placeables(player='all', *, check=True)

Pick up one person's cones, signs and other placed items, or everyone's.

close_incident

close_incident(incident_id, *, check=True)

Close an incident.

countdown

countdown(seconds, *, check=True)

Show everyone a countdown. 0 stops it.

create_incident

create_incident(team, priority, x, z, text, *, check=True)

Open a control-room incident at x, z (studs) for an emergency team, priority 1-3. The new incident's ID is in the result's Message.

despawn_vehicle

despawn_vehicle(player, *, check=True)

Put someone's vehicle away (the despawn command).

execute_command

execute_command(command)

Old name for :meth:run_command.

follow

follow(*logs, sections=(), limit=None, cursor=None, save_to=None)

A :class:~oxrpy.LogFollower that yields only new log entries. See its docs.

save_to (a file path, or an object with load/save) remembers the position across restarts. See :mod:oxrpy.state.

get_atms

get_atms()

ATMs: availability, alarm, who robbed them (None while offline).

get_audit

get_audit(*, before=None, category=None, user=None, limit=None)

One page of the full audit log: { Entries, Next, Total }. Slower than the rest.

get_bans

get_bans(*, limit=None, offset=None)

One page of bans: { Total, Offset, List: [...] }. See iter_bans.

get_catalogue

get_catalogue(*, max_age=3600, refresh=False)

Game data that only changes with an update: map, places, weapons, vehicles, offences, teams and ranks.

It's big and rarely changes, so the client keeps a copy for max_age seconds (an hour by default) and returns that instead of asking again. Pass refresh=True to fetch a fresh copy, or max_age=0 to never use the stored one.

get_command

get_command(command_id)

One command's result, for a command that was still Pending.

Keeps the API's old shape: lower-case Status (succeeded, failed, pending, no_result). Results are kept for 7 days.

get_command_results

get_command_results(*, since=None, limit=None)

Commands sent through the API and how they went. Last 200 kept.

get_commandlogs

get_commandlogs(*, since=None, limit=None)

The newest audit log entries. Last 100 kept.

get_events

get_events(*, since=None, limit=None)

About 100 kinds of game event, newest first. Last 1,000 kept.

get_groups

get_groups()

The server's groups and their members ([] without AdvancedServer).

get_incidents

get_incidents()

The control room: open incidents, units, operators, timeline.

get_joinlogs

get_joinlogs(*, since=None, limit=None)

Joins and leaves, newest first. Last 500 kept.

get_killlogs

get_killlogs(*, since=None, limit=None)

Kills (downs), newest first. Last 500 kept.

get_modcalls

get_modcalls(*, since=None, limit=None)

Help requests, responders and resolutions, newest first. Last 300 kept.

get_players

get_players()

Everyone in the server (None while offline).

get_queue

get_queue()

Who's waiting to join, front first (None while offline).

get_radiocalls

get_radiocalls(*, since=None, limit=None)

Radio calls, newest first. Last 500 kept.

get_robberies

get_robberies()

Robbery sites: state, stage, alarm, robbers (None while offline).

get_server

get_server()

The always-returned fields: Online, LastHeartbeat, NextHeartbeat, Cursor and Server (name, players, join code, packages…).

get_server_data

get_server_data(*sections, since=None, limit=None, offset=None, audit_before=None, audit_category=None, audit_user=None, if_none_match=None)

Everything about the server in one request: GET /v1/server.

Name each section you want (case doesn't matter), e.g. api.get_server_data("Players", "Vehicles", "Events", since=cursor). The top-level fields (Online, LastHeartbeat, NextHeartbeat, Cursor, Server) always come back.

Parameters:

Name Type Description Default
since Optional[int]

A Cursor from an earlier response: logs and shots only return newer entries.

None
limit Optional[int]

Most entries per log/Shots (default 100, max 500), Bans (max 1000) or Audit (max 100).

None
offset Optional[int]

Bans to skip.

None
audit_before Optional[int]

Audit entries numbered below this (the last Audit.Next).

None
audit_category Union[str, Iterable[str], None]

One or more of :data:AUDIT_CATEGORIES.

None
audit_user Union[str, int, None]

Only audit entries by this username or user ID.

None
if_none_match Optional[str]

A previous response's etag. Returns None if nothing changed.

None

Returns:

Name Type Description
A Optional[ServerData]

class:ServerData (a dict), or None on 304 Not Modified.

get_settings

get_settings()

Every Server Management setting, keyed by name. Webhooks read "(set)".

get_shots

get_shots(*, since=None, limit=None)

Every shot in the last 10 minutes, newest first.

get_staff

get_staff()

{ OwnerId, Staff: [...], Ranks: [...] }.

get_status

get_status()

The API's own health (GET /status): status, uptime and response times. Needs no key; don't ask more than every 30 seconds.

get_teams

get_teams()

Players, limits and access per team.

get_tracks

get_tracks()

Per-second position samples since the last report (None while offline).

get_vehicles

get_vehicles()

Every vehicle out, with emergency lights, siren, occupants… (None while offline).

get_world

get_world()

Weather, temperature, clock, locks, speed limit, sticky message, countdown.

give

give(players, tool, *, check=True)

Give a RoleplayKit tool: megaphone, firestarter, lectern, flag or staffcuffs.

group_add

group_add(user, group, *, check=True)

Add someone to one of your groups (AdvancedServer).

group_remove

group_remove(user, group, *, check=True)

Take someone out of one of your groups (AdvancedServer).

is_online

is_online()

Whether the server is running right now.

iter_bans

iter_bans(page_size=1000)

Yield every ban, fetching pages as needed.

jail

jail(player, seconds=None, *, check=True)

Jail someone as an arrest would, for 10 to 3,600 seconds (or the usual sentence).

kick

kick(player, reason=None, *, check=True)

Move someone out of your server, showing the reason. Staff can't be kicked.

list_callouts

list_callouts(*, check=True)

The callouts you can start, with their keys, in the result's Message.

lock_time

lock_time(locked=True, *, check=True)

Stop the clock (or start it again with locked=False).

lock_weather

lock_weather(locked=True, *, check=True)

Stop the weather changing by itself (or let it again with locked=False).

new_join_code

new_join_code(*, check=True)

Replace the join code with a new random one. The new code is in Message.

on

on(*keys)

Register a handler for :meth:run_forever.

Keys can be an entry Type ("Kill", "Join", "ModCall", "SpeedCamera", any event type), a log name ("KillLogs", "Events": every entry in it), "poll" (called with the whole response after every request) or "error" (called with the exception when a request fails and will be retried).

Use it as a decorator, @api.on("Kill"), or directly, api.on("Kill", handler).

plan_group_sync

plan_group_sync(group, members, *, remove_others=True)

The group add/group remove commands needed to make group contain exactly members (user IDs). Reads the groups; sends nothing.

plan_staff_sync

plan_staff_sync(desired, *, remove_others=False)

The rank/unrank commands needed to make the staff match desired (user ID -> rank name or Id, or None to remove). Reads the staff list; sends nothing. See :func:oxrpy.sync.plan_staff_changes.

pm

pm(players, message, *, check=True)

Send a private message, shown with your server's name and logo.

queue_front

queue_front(user, *, check=True)

Move someone to the front of the join queue.

queue_remove

queue_remove(user, *, check=True)

Take someone out of the join queue.

radio

radio(team, message, *, check=True)

A radio message from Control to an emergency team.

rank

rank(user, rank, *, check=True)

Put someone on the staff with a rank (its name or Id, e.g. "Admin"), or change it.

refuel

refuel(player, *, check=True)

Fill someone's tank or battery.

release

release(player, *, check=True)

Release someone from jail.

remove_message

remove_message(*, check=True)

Remove the pinned message.

remove_vehicle

remove_vehicle(plate_or_player, *, check=True)

Remove a vehicle by registration ("RJ75 FLK") or by its owner.

repair

repair(player, *, check=True)

Fully repair someone's vehicle, tyres included.

resolve_modcall

resolve_modcall(case_id, *, check=True)

Mark a mod call (help request) as handled. The CaseId is in ModCalls.

respawn

respawn(players, *, check=True)

Respawn them (the load command).

revive

revive(players, *, check=True)

Get anyone downed back up.

run_command

run_command(command, *, check=False)

Run one command (as you'd type it in game; the leading : is optional).

Waits up to 8 seconds for the result: { CommandId, Status, Code, Message }. Status is Succeeded, Failed or Pending. A Failed command is still a normal return unless check=True, which raises :class:CommandFailedError.

Raises:

Type Description
ServerOfflineError

The server is offline (nothing was run).

RateLimitError

Still rate limited after max_retries.

run_commands

run_commands(commands, *, check=False)

Run up to 10 commands in order, in one request. Returns one result per command.

run_forever

run_forever(*, sections=(), limit=None, cursor=None, skip_existing=True, save_to=None)

Poll the server and call the handlers registered with :meth:on, until :meth:stop.

Entries from every log are passed to handlers oldest first. A handler that raises is logged and skipped, and request errors are retried (see :class:LogFollower), so one bad moment doesn't stop your bot. A wrong key still raises.

Parameters:

Name Type Description Default
sections Sequence[str]

Other sections to fetch every time (e.g. ["Players"]), for poll handlers.

()
limit Optional[int]

Most entries per log per request.

None
cursor Optional[int]

Resume from a saved cursor (then nothing is skipped).

None
skip_existing bool

Don't replay the entries that were already in the logs when you started. Default True. Ignored when resuming from save_to.

True
save_to Any

A file path ("cursor.json"), or an object with load()/save(state), to remember the position. After a restart, the bot carries on exactly where it left off, including anything that happened while it was down (up to what the logs keep). See :mod:oxrpy.state.

None

run_many

run_many(commands, *, check=False)

Run any number of commands, in order, as fast as the game allows.

Sends them in batches of up to 10 and waits when needed to stay under the game's 15 commands every 10 seconds. Returns one result per command, in the same order. With check=True it stops at the first failed command and raises :class:CommandFailedError.

set_invincible

set_invincible(players, invincible=True, *, check=True)

Make them unable to be hurt by weapons (or able to again), until they leave.

set_message

set_message(message, *, check=True)

Pin a message on everyone's screen until it's removed.

set_setting

set_setting(name, value, *, check=True)

Change a Server Management setting. value is sent as JSON, so pass Python values: api.set_setting("TeamLimits", {"Police": 8}). Lists and objects replace the whole value.

set_team

set_team(player, team, *, check=True)

Put someone on a team, ignoring team limits and locks.

set_time

set_time(hour, *, check=True)

Set the clock to an hour from 0 to 24 (13.5 is 13:30).

set_weather

set_weather(weather, *, check=True)

Clear, Rain, Snow or Thunderstorm.

shutdown

shutdown(*, check=True)

Shut the server down, sending everyone to a public server.

spawn_vehicle

spawn_vehicle(player, custom_vehicle_id, *, check=True)

Spawn one of your FleetKit custom vehicles in front of them.

speed_limit

speed_limit(mph, *, check=True)

Limit every vehicle to 5-200 MPH (RoleplayKit). None or 0 lifts it.

start_callout

start_callout(team, key, *, check=True)

Start a Fire or Highways callout by its key (RoleplayKit; list_callouts shows keys).

stop

stop()

Make :meth:run_forever return after the current poll (safe from any thread).

stop_fires

stop_fires(*, check=True)

Put out every fire and end every fire callout (RoleplayKit).

sync_group

sync_group(group, members, *, remove_others=True)

Make group (name or Id) contain exactly members (user IDs), sending only the changes. Returns (command, result) pairs. remove_others=False only adds.

sync_staff

sync_staff(desired, *, remove_others=False)

Make the staff match desired (user ID -> rank, or None to remove), sending only the changes. Returns (command, result) pairs; an empty list means nothing needed changing. Use :meth:plan_staff_sync to see the commands without running them.

remove_others=True also unranks staff not in desired (never the owner).

team_announce

team_announce(team, message, *, check=True)

An announcement to one team.

teleport

teleport(players, to_player, *, check=True)

Teleport them next to another player (the tp command).

teleport_to_vehicle

teleport_to_vehicle(players, owner, *, check=True)

Teleport them next to another player's vehicle (the tocar command).

unban

unban(user, *, check=True)

Lift someone's ban.

unrank

unrank(user, *, check=True)

Take someone off the staff, whatever their rank.

wait_for_command

wait_for_command(command_id, *, timeout=130, interval=2)

Poll :meth:get_command until it's no longer pending (gives up after timeout).

wanted

wanted(players, level, *, check=True)

Set a wanted level from 0 to 3. players can be a name, all, team:Civilian…