Client API
Classes
- class chimera.client.Chimera(host, port='14200', notification_callback=None)
Bases:
ClientAPIThe main Chimera class. Use this class to connect to a Chimera server and access the games on that server.
Examples
>>> chimera = Chimera("chimera.example.org") >>> games = chimera.get_games() >>> connectm = games["connectm"] >>> match = connectm.create_match("Alex")
- Parameters:
host (str) –
port (str) –
notification_callback (Callable[[MatchNotification], None] | None) –
- __init__(host, port='14200', notification_callback=None)
Constructor
- Raises:
ChimeraConnectionRefusedException – if unable to connect to the server
- Parameters:
host (str) – Hostname of Chimera server
port (str) – Port to connect to (default: “14200”)
notification_callback (Callable[[MatchNotification], None] | None) – Optional callback function to call any time a match notification is received
- send_request(operation, params=None)
- set_notification_callback(notification_callback)
- class chimera.client.api.Game(api, game_id, description)
Bases:
objectClass representing a game on the Chimera server.
Should not be instantiated directly.
- Parameters:
api (ClientAPI) –
game_id (str) –
description (str) –
- create_match(player_name)
Creates a new match
- Parameters:
player_name (str) – Player name to use in the match
- Raises:
AlreadyInAMatch – If player is already in another match
- Return type:
Returns: Match object
- property description
Get game description
- property id: str
Get game identifier
- join_match(match_id, player_name)
Joins an existing match
- Parameters:
match_id (str) –
player_name (str) –
- Raises:
AlreadyInAMatch – If the player is already in a match
UnknownMatch – If there is no match for the provided match identifier
DuplicatePlayer – If there is already a player with the same name in the match
- Return type:
Returns: Match object
- class chimera.client.api.Match(api, game, match_id, player_name)
Bases:
objectClass representing a match in the server.
Should never be instantiated directly.
- Parameters:
api (ClientAPI) –
game (Game) –
match_id (str) –
player_name (str) –
- STATUS_AWAITING_PLAYERS = 'awaiting-players'
- STATUS_DONE = 'done'
- STATUS_IN_PROGRESS = 'in-progress'
- STATUS_READY = 'ready'
- STATUS_UNKNOWN = None
- game_action(action, data=None)
Requests a game action
- Parameters:
action (str) – Name of the action to be performed
data (dict | None) – Action-specific data
- Raises:
GameNoSuchAction – If there is no such action in this game
GameIncorrectActionData – If the provided data is incorrect
GameNotPlayerTurn – If the requested action cannot be performed until it is the player’s turn
- Return type:
None
Returns: None
- property game_state: dict | None
Get’s the gane’s state
- property id
Gets the match identifier
- next_notification()
If there are any unprocessed notifications, returns the next notification
- Returns: A MatchNotification object if there are any unprocessed
notifications. Otherwise, returns None.
- Return type:
MatchNotification | None
- property player_name: str
Gets the player’s name in the match
- property status: str | None
Gets the match status
- wait_for_update()
- property winner: str | None
Get’s the winner’s name (if any)
- class chimera.client.api.MatchNotification(match, event, data)
Bases:
objectClass for storing information about a match notification received by the server.
Should never be instantiated directly.
- Parameters:
match (Match) –
event (str) –
data (dict) –
- EVENT_END = 'end'
- EVENT_START = 'start'
- EVENT_UPDATE = 'update'
- property event: str
Gets the notification event
- property game_state: dict | None
Gets the game state included in the notification
- property match_status: str | None
Gets the match status included in the notification
- process()
Processes the notification, and updates tha state of the match with the information included in the notification.
Returns: None
- Return type:
None
- property winner: str | None
Gets the winner included in the notification
Exceptions
- exception chimera.exceptions.ChimeraClientException(message)
Base class for all client API exceptions
- exception chimera.exceptions.ChimeraConnectionRefusedException(cre)
Raised when the client API is unable to connect to the Chimera server
- exception chimera.exceptions.MalformedResponse(message, response)
Raised when the client API receives a malformed response from the Chimera server
- exception chimera.exceptions.ErrorResponse(code, message, data)
Base class for exceptions that stem from an error response from the server
- exception chimera.exceptions.AlreadyInAMatch(code, message, data)
Raised when a player tries to join a match, but they are already in a match.
- exception chimera.exceptions.UnknownMatch(code, message, data)
Raised when a player provides an incorrect match identifier
- exception chimera.exceptions.DuplicatePlayer(code, message, data)
Raised when a player tries to join a match, but there is already a player with the same name in that match.
- exception chimera.exceptions.GameNoSuchAction(code, message, data)
Raised when a game action is sent to a match, but the game does not support that action.
- exception chimera.exceptions.GameIncorrectActionData(code, message, data)
Raised when a game action is sent to a match, but the data included in the action is incorrect.
- exception chimera.exceptions.GameNotPlayerTurn(code, message, data)
Raised when a player performs an action that can only be performed when it is the player’s turn.