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#

async truckersmp.base.TruckersMP.get_player(self, player_id: int) Optional[Union[Player, bool]]#

Get a specific TruckersMP player from the API using their player id

Parameters

player_id (int) – TruckersMP Player ID

Returns

Player

Return type

Union[Player, bool, None]

Get Bans#

async truckersmp.base.TruckersMP.get_bans(self, player_id: int) Optional[Union[List[Ban], bool]]#

Get a list of a TruckersMP player’s bans.

Parameters

player_id (int) – TruckersMP Player ID

Returns

List of Ban

Return type

Union[Ban], bool, None]

Get Servers#

async truckersmp.base.TruckersMP.get_servers(self) Optional[Union[List[Server], bool]]#

Get a list of TruckersMP servers

Returns

list of Server

Return type

Union[List[Server], bool, None]

Get In-game Time#

async truckersmp.base.TruckersMP.get_ingame_time(self) Optional[Union[int, bool]]#

Get the ingame-time as an integer.

Returns

Ingame-time

Return type

Union[int, bool, None]

Get Events#

async truckersmp.base.TruckersMP.get_events(self) Optional[Union[Events, bool]]#

Get featured, todays and upcoming events.

Note

An event’s confirmed_users and unsure_users will be None when making this call. Get a specific event via it’s ID to get all confirmed and unsure users.

Returns

Events

Return type

Union[Events, bool, None]

Get Event#

async truckersmp.base.TruckersMP.get_event(self, event_id: int) Optional[Union[Event, bool]]#

Get a specific event

Parameters

event_id (int) – An event ID

Returns

Event

Return type

Union[Event, bool, None]

Get VTCs#

async truckersmp.base.TruckersMP.get_vtcs(self) Optional[Union[VTCs, bool]]#

Get recent, featured and featured cover VTCs.

Returns

VTCs

Return type

Union[VTCs, bool, None]

Get VTC#

async truckersmp.base.TruckersMP.get_vtc(self, vtc_id: int) Optional[Union[VTC, bool]]#

Get a specific VTC.

Parameters

vtc_id (int) – A VTC’s ID

Returns

VTC

Return type

Union[VTC, bool, None]

Get VTC News#

async truckersmp.base.TruckersMP.get_vtc_news(self, vtc_id: int) Optional[Union[List[NewsPost], bool]]#

Get all news posts from a specific VTC.

Note

An news post’s content (not content_summary) will be None when making this API call. Get a specific post via it’s ID to get the full content.

Parameters

vtc_id (int) – A VTC’s ID

Returns

List of NewsPost

Return type

Union[List[NewsPost], bool, None]

Get a VTC News Post#

async truckersmp.base.TruckersMP.get_vtc_news_post(self, vtc_id: int, news_post_id: int) Optional[Union[NewsPost, bool]]#

Get a specific news post from a specific VTC.

Parameters
  • vtc_id (int) – A VTC’s ID

  • news_post_id (int) – A news post’s ID

Returns

NewsPost

Return type

Union[NewsPost, bool, None]

Get VTC Roles#

async truckersmp.base.TruckersMP.get_vtc_roles(self, vtc_id: int) Optional[Union[List[Role], bool]]#

Get all of a VTC’s roles.

Parameters

vtc_id (int) – A VTC’s ID

Returns

List of Role

Return type

Union[List[Role], bool, None]

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.

Parameters
  • vtc_id (int) – A VTC’s ID

  • role_id (int) – A VTC news post’s ID

Returns

Role

Return type

Union[Role, bool, None]

Get VTC Members#

async truckersmp.base.TruckersMP.get_vtc_members(self, vtc_id: int) Optional[Union[List[Member], bool]]#

Get all of a VTC’s members.

Parameters

vtc_id (int) – A VTC’s ID

Returns

List of Member

Return type

Union[List[Member], bool, None]

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.

Parameters
  • vtc_id (int) – A VTC’s ID

  • member_id (int) – A VTC’s member ID

Returns

Member

Return type

Union[Member, bool, None]

Get VTC Events#

async truckersmp.base.TruckersMP.get_vtc_events(self, vtc_id: int) Optional[Union[List[Event], bool]]#

Get all of a VTC’s events.

Parameters

vtc_id (int) – A VTC’s ID

Returns

List of Event

Return type

Union[List[Event], bool, None]

Get Version#

async truckersmp.base.TruckersMP.get_version(self) Optional[Union[Version, bool]]#

Get version information.

Returns

Version

Return type

Union[Version, bool, None]

Get Rules#

async truckersmp.base.TruckersMP.get_rules(self) Optional[Union[Rules, bool]]#

Get the latest TruckersMP rules.

Returns

Rules

Return type

Union[Rules, bool, None]

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.

Variables
  • featured (Optional[List[Event]]) – Events featured by TruckersMP

  • today (Optional[List[Event]]) – Events that are starting today

  • upcoming (Optional[List[Event]]) – Events that are starting soonest, but not today

  • now (Optional[List[Event]]) – Events that are happening right now

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#

class models.event.Event.EventType#

A class object representing a type of event

Variables
  • key (Optional[str]) –

  • name (Optional[str]) – The name of the event type

Server#

class models.event.Event.Server#

A class object representing an event’s server

Variables
  • id (Optional[int]) – The ID of the event’s server

  • name (Optional[str]) – The name of the event’s server

Departure#

class models.event.Event.Departure#

A class object representing an event’s depature location

Variables
  • location (Optional[str]) – The location in the departure city (eg. garage)

  • city (Optional[str]) – The depature city name

Arrive#

class models.event.Event.Arrive#

A class object representing an event’s destination

Variables
  • location (Optional[str]) – The location in the arrival city (eg. garage)

  • city (Optional[str]) – The arrival city name

VTC#

class models.event.Event.VTC#

A class object representing an event’s VTC

Variables
  • id (Optional[int]) – The ID of the host VTC

  • name (Optional[str]) – The name of the host VTC

User#

class models.event.Event.User#

A class object representing the user (owner) of an event

Variables
  • id (Optional[int]) – The ID of the host user

  • name (Optional[str]) – The name of the host user

Attendances#

class models.event.Event.Attendances#

A class object representing attendance information of an event

Variables
  • confirmed (Optional[int]) – The number of users that have confirmed their attendance

  • unsure (Optional[int]) – The number of users that are unsure if they can make it

  • confirmed_users (Optional[List[Attendee]]) – List of confirmed users

  • unsure__users (Optional[List[Attendee]]) – List of unsure users

Attendee#
class models.event.Event.Attendances.Attendee#

A class object representing an attendee (user) of an event

Variables
  • id (Optional[int]) – The ID of the user

  • username (Optional[str]) – The name of the user

  • following (Optional[bool]) –

  • created_at (Optional[str]) – When the user confirmed their attendance

  • updated_at (Optional[str]) – When the user updated their attendance

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

Variables
  • is_patron (Optional[bool]) –

  • active (Optional[bool]) –

  • color (Optional[str]) –

  • tier_id (Optional[int]) –

  • current_pledge (Optional[int]) –

  • lifetime_pledge (Optional[int]) –

  • next_pledge (Optional[int]) –

  • hidden (Optional[bool]) –

Permissions#

class models.player.Player.Permissions#

A class object representing the permissions of a player

Variables
  • is_staff (Optional[bool]) – Whether the user is a staff member

  • is_upper_staff (Optional[bool]) – Whether the user is an upper staff member

  • is_game_admin (Optional[bool]) – Whether the user is an in-game admin

  • show_detailed_on_maps (Optional[bool]) –

VTC#

class models.player.Player.VTC#

A class object representing the VTC of a player

Variables
  • id (Optional[int]) – The player’s VTC ID

  • name (Optional[str]) – The player’s VTC name

  • tag (Optional[str]) – The player’s VTC tag

  • in_vtc (Optional[bool]) – Whether the player is in a VTC

  • member_id (Optional[int]) –

Rules#

class models.rules.Rules#

A class object representing TruckersMP rules.

Variables
  • rules (optional[str]) –

  • revision (optional[int]) –

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#

class models.version.Version.ETS2MPChecksum#

A class object to represent the ETS2MP Checksum in a version

Variables
  • dll (Optional[str]) –

  • adb (Optional[str]) –

ATSMPChecksum#

class models.version.Version.ATSMPChecksum#

A class object to represent the ATSMP Checksum in a version

Variables
  • dll (Optional[str]) –

  • adb (Optional[str]) –

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) –

Socials#

class models.vtc.VTC.Socials#

A class object respresenting a VTC’s socials.

Variables
  • twitter (Optional[str]) –

  • facebook (Optional[str]) –

  • twitch (Optional[str]) –

  • discord (Optional[str]) –

  • youtube (Optional[str]) –

Games#

class models.vtc.VTC.Games#

A class object representing a VTC’s games.

Variables
  • ats (Optional[bool]) –

  • ets (Optional[bool]) –

VTCs#

class models.vtc.VTCs#

A class object representing recent, featured and featured cover VTCs.

Variables
  • recent (Optional[List[VTC]]) –

  • featured (Optional[List[VTC]]) –

  • featured_cover (Optional[List[VTC]]) –

VTC News Post#

class models.vtc.NewsPost#

A class representing a VTC news post.

Variables
  • id (Optional[int]) –

  • title (Optional[str]) –

  • content_summary (Optional[str]) –

  • content (Optional[str]) –

  • author_id (Optional[int]) –

  • author (Optional[str]) –

  • pinned (Optional[bool]) –

  • updated_at (Optional[str]) –

  • published_at (Optional[str]) –

VTC Role#

class models.vtc.Role#

A class object representing a VTC role.

Variables
  • id (Optional[int]) –

  • name (Optional[str]) –

  • order (Optional[int]) –

  • owner (Optional[bool]) – Whether the role is the owner role (highest rank)

  • created_at (Optional[str]) –

  • updated_at (Optional[str]) –

VTC Member#

class models.vtc.Member#

A class object representing a VTC Member.

Variables
  • id (Optional[int]) –

  • user_id (Optional[int]) –

  • username (Optional[str]) –

  • steam_id (Optional[int]) –

  • role_id (Optional[int]) –

  • role (Optional[str]) –

  • join_date (Optional[str]) –

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

execute()#