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: AccountConfiguration, *, avatar: str | None = None, log_level: int | None = None, server_configuration: ServerConfiguration, start_listening: bool = True, ping_interval: float | None = 20.0, ping_timeout: float | None = 20.0)

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.

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 = ('localhost:8000', 'https://play.pokemonshowdown.com/action.php?')

Server configuration with localhost and smogon’s authentication endpoint.

class poke_env.ps_client.server_configuration.ServerConfiguration(server_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

server_url: str

Alias for field number 0

poke_env.ps_client.server_configuration.ShowdownServerConfiguration = ('sim.smogon.com:8000', 'https://play.pokemonshowdown.com/action.php?')

Server configuration with smogon’s server and authentication endpoint.