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:
objectPokemon 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.
- property account_configuration: AccountConfiguration
The client’s account configuration.
- Returns:
The client’s account configuration.
- Return type:
- 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 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.
- property server_configuration: ServerConfiguration
The client’s server configuration.
- Returns:
The client’s server configuration.
- Return type:
- async stop_listening()
This module contains objects related to player configuration.
- class poke_env.ps_client.account_configuration.AccountConfiguration(username: str, password: str | None)
Bases:
NamedTuplePlayer 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.
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:
NamedTupleServer configuration object. Represented with a tuple with two entries: server url and authentication endpoint url.
- 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.