Pokémon Showdown client: Interact seamlessly with Pokémon Showdown servers

This module defines a base class for communicating with showdown servers.

class poke_env.ps_client.ps_client.PSClient(account_configuration: ~poke_env.ps_client.account_configuration.AccountConfiguration, *, avatar: str | None = None, log_level: int | None = None, on_battle_message: ~typing.Callable[[~typing.List[~typing.List[str]]], ~typing.Awaitable[None]] | None = None, on_update_challenges: ~typing.Callable[[~typing.List[str]], ~typing.Awaitable[None]] | None = None, on_challenge_request: ~typing.Callable[[~typing.List[str]], ~typing.Awaitable[None]] | None = None, server_configuration: ~poke_env.ps_client.server_configuration.ServerConfiguration, start_listening: bool = True, open_timeout: float | None = 10.0, ping_interval: float | None = 20.0, ping_timeout: float | None = 20.0, loop: ~asyncio.events.AbstractEventLoop = <_UnixSelectorEventLoop running=True closed=False debug=False>)

Bases: object

Pokemon Showdown client.

Responsible for communicating with showdown servers. Also implements some higher level methods for basic tasks, such as changing avatar and low-level message handling.

async accept_challenge(username: str, packed_team: str | None)
property account_configuration: AccountConfiguration

The client’s account configuration.

Returns:

The client’s account configuration.

Return type:

AccountConfiguration

async challenge(username: str, format_: str, packed_team: str | None)
async change_avatar(avatar_name: str | None)

Changes the account’s avatar.

Parameters:

avatar_name (int) – The new avatar name. If None, nothing happens.

async listen()

Listen to a showdown websocket and dispatch messages to be handled.

async log_in(split_message: List[str])

Log in with specified username and password.

Split message contains information sent by the server. This information is necessary to log in.

Parameters:

split_message (List[str]) – Message received from the server that triggers logging in.

property logged_in: Event

Event object associated with user login.

Returns:

The logged-in event

Return type:

Event

property logger: Logger

Logger associated with the client.

Returns:

The logger.

Return type:

Logger

async search_ladder_game(format_: str, packed_team: str | None)
async send_message(message: str, room: str = '', message_2: str | None = None)

Sends a message to the specified room.

message_2 can be used to send a sequence of length 2.

Parameters:
  • message (str) – The message to send.

  • room (str) – The room to which the message should be sent.

  • message_2 (str, optional) – Second element of the sequence to be sent. Optional.

property server_configuration: ServerConfiguration

The client’s server configuration.

Returns:

The client’s server configuration.

Return type:

ServerConfiguration

async set_team(packed_team: str | None)
async stop_listening()
property username: str

The account’s username.

Returns:

The account’s username.

Return type:

str

async wait_for_login(checking_interval: float = 0.001, wait_for: int = 5)
property websocket_url: str

The websocket url.

It is derived from the server url.

Returns:

The websocket url.

Return type:

str

This module contains objects related to player configuration.

class poke_env.ps_client.account_configuration.AccountConfiguration(username: str, password: str | None)

Bases: NamedTuple

Player configuration object. Represented with a tuple with two entries: username and password.

classmethod generate(key: str, rand: bool = False) AccountConfiguration

Generates an AccountConfiguration instance using a provided key. The same key can be used multiple times to create multiple usernames.

Parameters:
  • key – The base of the username. Will be truncated to be a maximum of 18 characters long.

  • rand – If true, the unique identifier appended to the end will be a randomized 5-length alphanumeric string instead of an increment for every identical key.

password: str | None

Alias for field number 1

username: str

Alias for field number 0

This module contains objects related to server configuration.

poke_env.ps_client.server_configuration.LocalhostServerConfiguration = ('ws://localhost:8000/showdown/websocket', 'https://play.pokemonshowdown.com/action.php?')

Server configuration with localhost and smogon’s authentication endpoint.

class poke_env.ps_client.server_configuration.ServerConfiguration(websocket_url: str, authentication_url: str)

Bases: NamedTuple

Server configuration object. Represented with a tuple with two entries: server url and authentication endpoint url.

authentication_url: str

Alias for field number 1

websocket_url: str

Alias for field number 0

poke_env.ps_client.server_configuration.ShowdownServerConfiguration = ('wss://sim3.psim.us/showdown/websocket', 'https://play.pokemonshowdown.com/action.php?')

Server configuration with smogon’s server and authentication endpoint.