Changelog¶
2.3.0¶
Nothing in this release should break existing code.
New¶
- Carry on after a restart.
run_forever(save_to="cursor.json")andfollow(..., save_to=...)remember where they got to. After a restart, your bot picks up exactly there, including anything that happened while it was down, as long as the logs still hold it. The position is saved after your handlers run, so a crash never loses entries. To keep it in your own database, pass any object withload()andsave(state). - Many servers in one app.
AsyncServerPoolruns one set of handlers across lots of servers. Handlers get the server's name first. - With an app key, every server's requests are paced together within your app's limits.
- A server whose key stops working is dropped and reported, and the rest carry on.
- You can add and remove servers while it runs.
each()andrun_command_on_all()do something on every server at once.- Docs site. Full guides and a reference for every method, built with MkDocs
(
pip install "oxrpy[docs]", thenmkdocs serve).
Fixed¶
- Hovering over a method in your editor shows its description again, as well as its types. Since 2.2.0, some editors showed only the types.
OxfordAPI(...)andAsyncOxfordAPI(...)list their arguments properly, so editors autocomplete them.
2.2.0¶
Nothing in this release should break code written for 2.0 or 2.1.
New¶
- Autocomplete. Editors now know the shape of everything the API returns, so they suggest
field names (
Username,SpeedMph,Wanted…) and flag typos before you run your code. The types are inoxrpy.typesif you want them in your own code. At runtime it's all still plain dicts. - Server online, offline and restart events. Handlers can listen for
"ServerOnline","ServerOffline"and"ServerRestart". - Staff and group sync.
sync_staff({user_id: rank})andsync_group(name, user_ids)send only the changes needed.plan_staff_syncandplan_group_syncshow those changes without sending anything. run_many()sends any number of commands, batching them and waiting when needed to stay under the game's 15 commands every 10 seconds.- Map helpers.
oxrpy.mapconverts positions to pixels on Oxford's map image and back, and works out distances and the nearest place. - Catalogue caching.
get_catalogue()keeps a copy for an hour. Passrefresh=Trueto fetch a new one. - Command line.
oxrpy status,oxrpy serverandoxrpy players. - Examples. Ready-to-run scripts in examples/, including Discord bots for a kill feed and server status.
Fixed¶
- Return types are back in your editor. In 2.1.0, every method showed up as returning
Any. - The changelog and license links on the PyPI page work now. They used to point at files PyPI doesn't have.
- The source download on PyPI no longer includes the tests.
2.1.0¶
Nothing in this release should break code written for 2.0.
New¶
- Async client.
AsyncOxfordAPIhas every methodOxfordAPIhas, but youawaitthem, so discord.py bots and other async code don't freeze while waiting for the API. Install it withpip install "oxrpy[async]", which addshttpx. - Event handlers. Register functions with
@api.on("Kill"),@api.on("Join", "Leave"),@api.on("SpeedCamera")and so on, then callapi.run_forever(). oxrpy works out which logs to ask for. Entries arrive oldest first, and old entries are skipped on startup. If a handler raises, the error is logged and the bot keeps going. There are also"poll"and"error"handlers, andapi.stop(). - Command helpers. There's a method for every command, such as
api.kick(...),api.ban(user, reason, "7d"),api.set_team(...),api.create_incident(...)andapi.set_setting(...). They check arguments before sending, so typos fail straight away, and they raiseCommandFailedErrorif the command didn't work (passcheck=Falseto turn that off).format_duration()turns atimedeltaor seconds into a ban duration.
Changed¶
follow()no longer stops when a request fails. It waits and tries again, waiting longer after each failure in a row (up to a minute), and only stops for errors that waiting won't fix, like a wrong key. Usefollower.iter(retry=False)for the old behaviour.
2.0.1¶
- Rewrote the README to be easier to read. No code changes.
2.0.0¶
This version is a full rewrite for Oxford's new API (https://docs.oxfd.re). The endpoints 1.x used are being switched off on 1 January 2027, so you'll need to upgrade before then.
What might break your code¶
- All the data now comes from the new API, so it's in the new format. Field names are
PascalCase, and anything missing is
Noneinstead of a placeholder like"None"or0. For example: - Players have
PositionandLocation { Road, Area, Grid, Address }, where they used to haveCoordinates. WantedLevelis nowWanted { Level, ... }.- Vehicles use
Plate,OwnerIdandElsin place ofRegistration,OwnerUserIdandELS. get_server()now returnsOnline,LastHeartbeat,NextHeartbeat,CursorandServer. The server's details are under["Server"].get_queue()returns a list like[{ UserId, JoinedAt, Priority }]instead of{ total, users }.get_bans()returns one page at a time as{ Total, Offset, List }, and each ban hasExpiresAtinstead ofExpiry. Useiter_bans()if you want all of them.- Every log entry now has
Seq,Id,TypeandAt. - Commands return
{ CommandId, Status, Code, Message }. A command can fail without raising an error, so checkStatus. - You always need a
server_keynow.global_keyhas gone. If you've got an app key, pass it asapp_key=along with the server key. If you still passglobal_key, you'll get a warning and it'll be used as the app key. server_idisn't needed any more. If you pass it, you'll get a warning and it's ignored.- You need Python 3.10 or newer.
What's new¶
get_server_data()gets any mix of the API's 35 sections in one request. You can also pass an ETag so it only downloads the data again when something's changed.- New helpers for the new sections:
get_tracks,get_world,get_teams,get_atms,get_incidents,get_staff,get_groups,get_settings,get_catalogue,get_events,get_shots,get_command_results,get_audit,is_onlineanditer_bans. follow()watches the logs for you and only gives you entries you haven't seen yet.run_commands()sends up to 10 commands at once.run_command(..., check=True)raises an error if the command didn't work.get_command()andwait_for_command()let you check on slow commands.get_status()tells you whether the API itself is up.- Rate limiting now matches Oxford's published limits for server keys and app keys. When you get rate limited, it waits as long as the API asks before trying again.
- Each kind of error has its own exception:
AuthenticationError,BadRequestError,NotFoundError,EndpointRemovedErrorandCommandFailedError. They all have.status,.codeand.body. - Requests reuse one connection, you can use the client in a
withblock, and the package includes type hints.
Still works from 1.x¶
execute_command()(it's calledrun_command()now),api.servers,api.logs,api.commands, andfrom oxrpy.oxrpy import OxfordAPI.
1.3.4¶
The last 1.x release, which used the old endpoints.