API Reference#
Base#
When using Async-TruckersMP, the base class is at the core of all operations.
Import Asyncio and the class.
Initalise the class and assign it to a variable (to utilise Cache, rate limiting etc; see examples)
Use a method the class provides (The class will return a model in normal circumstances)
Using the model, get the information that is needed.
It can be imported and used like so:
import asyncio
from truckersmp import TruckersMP
truckersmp = TruckersMP()
- class truckersmp.base.TruckersMP(loop: ~asyncio.events.AbstractEventLoop = <_UnixSelectorEventLoop running=False closed=False debug=False>, limiter: ~aiolimiter.leakybucket.AsyncLimiter = <aiolimiter.leakybucket.AsyncLimiter object>, logger: ~logging.Logger = <RootLogger root (WARNING)>, log_freq: ~typing.Union[int, ~datetime.timedelta] = 60, min_queue_for_log: int = 10, request_timeout: int = 10, cache_time_to_live: ~typing.Optional[int] = 60, cache_max_size: ~typing.Optional[int] = 65536)#
The main/base class to import when using the API wrapper. Configurable on initialisation by parameter passing. All endpoints return a value (mostly a class or list of classes) if the request is successful, None if something was not found and False if the request failed.
- Parameters
loop (
asyncio.AbstractEventLoop, optional) – The asyncio loop to use. Tries to get if none provided.limiter (
aiolimiter.AsyncLimiter, optional) – Override the default limiter, defaults to 5 API requests/5 sec (60req/m).logger (
logging.Logger, optional) – A custom logger to use, defaults to result of logging.getLogger().log_freq (Union[int (as seconds), timedelta], optional) – How frequently to log rate limit warnings, defaults to 60.
min_queue_for_log (int, optional) – The minimum queue size required to start logging rate limits warnings. This will prevent warning logs for a small burst of requests, defaults to 10.
request_timeout (int, optional) – The number of seconds to wait for the API’s response, defaults to 10.
cache_time_to_live (int, optional) – The number of seconds to cache a for response before considering it expired, defaults to 60.
cache_max_size (Optional[int], optional) – The maximum number of items in the cache. Provide None for infinite size, defaults to 65536.
Get Player#
Get Bans#
Get Servers#
Get In-game Time#
Get Events#
Get Event#
Get VTCs#
Get VTC#
Get VTC News#
Get a VTC News Post#
Get VTC Roles#
Get a VTC Role#
- async truckersmp.base.TruckersMP.get_vtc_role(self, vtc_id: int, role_id: int) Optional[Union[Role, bool]]#
Get a specific role of a specific VTC.
Note
The info given by the TruckersMP API for VTC roles is the same, regardless of endpoint. Therefore, to reduce the number of API requests, this will make 1 call for all of a VTC’s roles (or use cache) and search for the specified ID locally.
Get VTC Members#
Get a VTC Member#
- async truckersmp.base.TruckersMP.get_vtc_member(self, vtc_id: int, member_id: int) Optional[Union[Member, bool]]#
Get a specific member that’s within a specific VTC.
Note
The info given by the TruckersMP API for VTC members is the same, regardless of endpoint. Therefore, to reduce the number of API requests, this will make 1 call for all of a VTC’s members (or use cache) and search for the specified ID locally.
Get VTC Events#
Get Version#
Get Rules#
Models#
Below all the models can be found. These are classes that are often returned when using the base class.
Example use of a Model:
"""This will print the names of all the admins that have banned the user with id 924220"""
from truckersmp import TruckersMP
truckersmp = TruckersMP()
user_id = 924220
bans = truckersmp.get_bans(user_id) # Returns a list of Ban objects (model)
for ban in bans:
print(ban.admin_name)
Note
Model variable descriptions are yet to be written.
Ban#
- class models.ban.Ban#
A class object representing a ban on TruckersMP.
- Variables
expiration (Optional[str]) – The expiration datetime of the ban.
time_added (Optional[str]) – The datetime that the ban was added.
active (Optional[bool]) – Whether the ban is considered active.
reason (Optional[str]) – The reason for the ban.
admin_name (Optional[str]) – The name of the admin that created the ban.
admin_id (Optional[str]) – The TruckersMP ID of the admin that created the ban.
Events#
- class models.event.Events#
A class object representing featured, todays, upcoming and now events.
Event#
- class models.event.Event#
A class representing an event on TruckersMP
- Variables
id (Optional[int]) – The event ID
name (Optional[str]) – The name of the event
slug (Optional[str]) – The event slug (present in the URL)
game (Optional[str]) – The game which the event takes place on
language (Optional[str]) – The primary language for the event
start_at (Optional[str]) – The starting time of the event
banner (Optional[str]) – An image URL of the event banner
map (Optional[str]) – An image URL of the event map
description (Optional[str]) – The event description
rule (Optional[str]) – The event rules
voice_link (Optional[str]) – A link to the event’s communication platform (eg. Discord server)
external_link (Optional[str]) – A link to the event’s website (or listing)
featured (Optional[str]) – If featured, equals “Featured”
dlcs (Optional[list]) – List of DLCs required
url (Optional[list]) – Link to the event on TruckersMP (only path)
created_at (Optional[str]) – When the event was created
updated_at (Optional[str]) – When the event was last updated
event_type (EventType) – The type of event
server (Server) – The server the event will take place on
departure (Departure) – The departure location
arrive (Arrive) – The desination location
vtc (VTC) – The VTC the event is organised by
user (User) – The user the event is organised by
attendances (Attendances) – The users that plan to attend
EventType#
Server#
Departure#
Arrive#
VTC#
User#
Attendances#
- class models.event.Event.Attendances#
A class object representing attendance information of an event
- Variables
Attendee#
- class models.event.Event.Attendances.Attendee#
A class object representing an attendee (user) of an event
Player#
- class models.player.Player#
A class object representing a TruckersMP player (user)
- Variables
id (Optional[int]) – The ID of the player
name (Optional[str]) – The name of the player
avatar (Optional[str]) – An image URL of the player’s avatar
small_avatar (Optional[str]) – An image URL of a small version of the player’s avatar
join_date (Optional[str]) – When the player’s account was created
steam_id_64 (Optional[int]) – The user’s Steam account SteamID64
steam_id (Optional[str]) – The user’s Steam account ID
discord_id (Optional[str]) – The user’s Discord account ID
display_vtc_history (Optional[bool]) – Whether the user is displaying their VTC history
group_name (Optional[str]) – The user’s group name
group_color (Optional[str]) – The user’s group colour
group_colour (Optional[str]) – The user’s group colour (same as group_color)
group_id (Optional[int]) – The user’s group ID
banned (Optional[bool]) – Whether the user is banned
banned_until (Optional[str]) – When the user’s ban expires
ban_count (Optional[int]) – How many times the user has been banned
display_bans (Optional[bool]) – Whether the user chooses to show their bans
patreon (Patreon) – Information about the player’s Patreon contributions
permissions (Permissions) – Information about the player’s permissions
vtc (VTC) – Information about the player’s VTC
Patreon#
- class models.player.Player.Patreon#
A class object representing Patreon information about a player
Permissions#
- class models.player.Player.Permissions#
A class object representing the permissions of a player
VTC#
- class models.player.Player.VTC#
A class object representing the VTC of a player
Rules#
Server#
- class models.server.Server#
A class object representing a TruckersMP server
- Variables
id (Optional[int]) – The ID of the server
game (Optional[str]) – The game of the server
ip (Optional[str]) – The IP address of the server
port (Optional[int]) – The port of the server
name (Optional[str]) – The server name
short_name (Optional[strr]) – The server’s shortname
id_prefix (Optional[str]) – A string that is inserted in front of an in-game user’s ID.
online (Optional[bool]) – Whether the server is online
players (Optional[int]) – The number of players in the server
queue (Optional[int]) – The number of players in the server’s queue
max_players (Optional[int]) – The maximum number of players allowed in the server
map_id (Optional[int]) – The map ID of the server
display_order (Optional[int]) – Where the server is displayed in the list
speed_limiter (Optional[int]) – Whether the speed limiter is enabled
collisions (Optional[str]) – Whether collisions are enabled
cars_for_players (Optional[str]) – Whether players are allowed to drive cars
afk_enabled (Optional[str]) – Whether AFK kick is enabled
event (Optional[str]) – Whether this is an event server
special_event (Optional[str]) – Whether this is a special event server
promods (Optional[str]) – Whether Promods is enabled on this server
sync_delay (Optional[int]) –
Version#
- class models.version.Version#
A class object to represent a TruckersMP version.
- Variables
name (Optional[str]) –
numeric (Optional[str]) –
stage (Optional[str]) –
time (Optional[str]) –
supported_game_version (Optional[str]) –
supported_ats_version (Optional[str]) –
ets2mp_checksum (ETS2MPChecksum) –
atsmp_checksum (ATSMPChecksum) –
ETS2MPChecksum#
ATSMPChecksum#
VTC#
- class models.vtc.VTC#
A class object representing a VTC.
- Variables
id (Optional[int]) –
name (Optional[str]) –
owner_id (Optional[int]) –
owner_username (Optional[str]) –
slogan (Optional[str]) –
tag (Optional[str]) –
logo (Optional[str]) –
cover (Optional[str]) –
information (Optional[str]) –
rules (Optional[str]) –
requirements (Optional[str]) –
website (Optional[str]) –
members_count (Optional[int]) –
recruitment (Optional[str]) –
language (Optional[str]) –
verified (Optional[bool]) –
validated (Optional[bool]) –
created (Optional[str]) –
socials (Socials) –
games (Games) –
Games#
VTCs#
VTC News Post#
- class models.vtc.NewsPost#
A class representing a VTC news post.
VTC Role#
VTC Member#
Exceptions#
Below are all the exceptions that the library may raise.
ConnectError#
- exception truckersmp.exceptions.ConnectError#
Raised when an error occurs during an API request. It’s likely a temporary problem with your internet or the API.
NotFoundError#
- exception truckersmp.exceptions.NotFoundError#
Raised when a resource at an endpoint is not found such as providing a player ID that is not registered.
RateLimitError#
- exception truckersmp.exceptions.RateLimitError#
Raised when the API returns a 429 error. This should never happen in normal circumstances when using the default limiter.
FormatError#
- exception truckersmp.exceptions.FormatError#
Raised when the API returns JSON that isn’t in the format that’s expected (eg. missing a key)
ExecuteError#
- exception truckersmp.exceptions.ExecuteError#
Raised when the execute() function raises a different error. See execute function docs for more info.
Advanced#
Note
This part of documentation is incomplete
Socials#
A class object respresenting a VTC’s socials.
twitter (Optional[str]) –
facebook (Optional[str]) –
twitch (Optional[str]) –
discord (Optional[str]) –
youtube (Optional[str]) –