Teambuilder: Parse, manage and generate showdown teams

Base Teambuilder

This module defines the Teambuilder abstract class, which represents objects yielding Pokemon Showdown teams in the context of communicating with Pokemon Showdown.

class poke_env.teambuilder.teambuilder.Teambuilder

Bases: ABC

Teambuilder objects allow the generation of teams by Player instances.

They must implement the yield_team method, which must return a valid packed-formatted showdown team every time it is called.

This format is a custom format decribed in Pokemon’s showdown protocol documentation: https://github.com/smogon/pokemon-showdown/blob/master/PROTOCOL.md#team-format

This class also implements a helper function to convert teams from the classical showdown team text format into the packed-format.

static join_team(team: List[TeambuilderPokemon]) str

Converts a list of TeambuilderPokemon objects into the corresponding packed showdown team format.

Parameters:

team (list of TeambuilderPokemon) – The list of TeambuilderPokemon objects that form the team.

Returns:

The formatted team string.

Return type:

str

static parse_packed_team(team: str) List[TeambuilderPokemon]

Converts a packed-format team string into a list of TeambuilderPokemon objects.

Parameters:

team (str) – The packed-format team to convert.

Returns:

The formatted team.

Return type:

list of TeambuilderPokemon

static parse_showdown_team(team: str) List[TeambuilderPokemon]

Converts a showdown-formatted team string into a list of TeambuilderPokemon objects.

This method can be used when using teams built in the showdown teambuilder.

Parameters:

team (str) – The showdown-format team to convert.

Returns:

The formatted team.

Return type:

list of TeambuilderPokemon

abstractmethod yield_team() str

Returns a packed-format team.

Constant teambuilder

This module defines the ConstantTeambuilder class, which is a subclass of ShowdownTeamBuilder that yields a constant team.

class poke_env.teambuilder.constant_teambuilder.ConstantTeambuilder(team: str)

Bases: Teambuilder

property team: List[TeambuilderPokemon]
yield_team() str

Returns a packed-format team.

Smogon stats teambuilder

Teambuilders backed by Smogon usage statistics.

class poke_env.teambuilder.smogon_stats_teambuilder.SmogonStatsTeambuilder(stats: SmogonStats, team: Sequence[TeambuilderPokemon] = (), *, team_strategy: Literal['greedy', 'sample'] = 'greedy', pokemon_strategy: Literal['greedy', 'sample'] = 'greedy', rng: Random | None = None)

Bases: Teambuilder

Complete teams using one explicit Smogon usage-statistics snapshot.

The snapshot supplies marginal set frequencies, so fields of a Pokemon’s set are selected independently. Species selection starts from overall usage, then pools the selected Pokemon’s conditional teammate distributions in log-odds space. Signals from positively correlated team members are downweighted so the same evidence is not counted repeatedly. The teammate data describes pairs, so completions do not reproduce the full distribution of teams exactly.

Parameters:
  • stats – Statistics snapshot used for every completion.

  • team – Partially specified Pokemon to retain and complete.

  • team_strategy"greedy" selects the most likely species at each step; "sample" draws species from the corresponding distributions.

  • pokemon_strategy"greedy" selects the most likely ability, item, spread, move, and Tera type; "sample" draws each value from its marginal distribution. If a snapshot reports fewer than four moves, all reported moves are used.

  • rng – Source of randomness for sampled choices. Supplying a seeded random.Random makes generated teams reproducible.

classmethod from_format(battle_format: str, team: Sequence[TeambuilderPokemon] = (), *, month: str = 'latest', cutoff: int = 0, timeout: float = 30, cache_dir: str | Path | None = '.poke_env_stats_cache', refresh: bool = False, team_strategy: Literal['greedy', 'sample'] = 'greedy', pokemon_strategy: Literal['greedy', 'sample'] = 'greedy', rng: Random | None = None) SmogonStatsTeambuilder

Create a teambuilder from a Smogon statistics format.

This is a convenience wrapper around SmogonStats.fetch(). Use the constructor directly when a parsed snapshot is already available.

Parameters:
  • battle_format – Format whose Smogon statistics should be used.

  • team – Partially specified Pokemon to retain and complete.

  • month – Statistics month, or "latest".

  • cutoff – Smogon rating cutoff for the statistics snapshot.

  • timeout – HTTP timeout used when fetching statistics.

  • cache_dir – Directory used for cached snapshots. Set to None to disable caching.

  • refresh – Whether to replace an existing cached snapshot.

  • team_strategy – Strategy used to select missing species.

  • pokemon_strategy – Strategy used to complete missing set values.

  • rng – Source of randomness for sampled choices.

yield_team() str

Return a packed completed team.

poke_env.teambuilder.smogon_stats_teambuilder.complete_team(partial_team: Sequence[TeambuilderPokemon], battle_format: str, *, month: str = 'latest', cutoff: int = 0, timeout: float = 30, cache_dir: str | Path | None = '.poke_env_stats_cache', refresh: bool = False, team_strategy: Literal['greedy', 'sample'] = 'greedy', pokemon_strategy: Literal['greedy', 'sample'] = 'greedy', rng: Random | None = None) list[TeambuilderPokemon]

Complete a partial team using a Smogon statistics format.

partial_team should contain TeambuilderPokemon objects, for example from Teambuilder.parse_showdown_team() or Teambuilder.parse_packed_team(). The returned list is independent of the input and can be packed with Teambuilder.join_team().

poke_env.teambuilder.smogon_stats_teambuilder.generate_team(battle_format: str, *, month: str = 'latest', cutoff: int = 0, timeout: float = 30, cache_dir: str | Path | None = '.poke_env_stats_cache', refresh: bool = False, team_strategy: Literal['greedy', 'sample'] = 'greedy', pokemon_strategy: Literal['greedy', 'sample'] = 'greedy', rng: Random | None = None) list[TeambuilderPokemon]

Generate a structured team from a Smogon statistics format.

The returned list can be inspected or modified before being converted to a packed team with Teambuilder.join_team(). Use SmogonStatsTeambuilder.from_format() when the builder itself should be reused or passed to a Player.

Teambuilder pokemon

This module defines the TeambuilderPokemon class, which is used as an intermediate format to specify pokemon builds in teambuilders custom classes.

class poke_env.teambuilder.teambuilder_pokemon.TeambuilderPokemon(nickname: str | None = None, species: str | None = None, item: str | None = None, ability: str | None = None, moves: List[str] | None = None, nature: str | None = None, evs: List[int] | None = None, gender: str | None = None, ivs: List[int] | None = None, shiny: bool | None = None, level: int | None = None, happiness: int | None = None, hiddenpowertype: str | None = None, gmax: bool | None = None, tera_type: str | None = None)

Bases: object

HP_TO_IVS = {'bug': [31, 31, 31, 30, 31, 30], 'dark': [31, 31, 31, 31, 31, 31], 'dragon': [30, 31, 31, 31, 31, 31], 'electric': [31, 31, 31, 31, 30, 31], 'fighting': [31, 31, 30, 30, 30, 30], 'fire': [31, 30, 31, 30, 31, 30], 'flying': [31, 31, 31, 30, 30, 30], 'ghost': [31, 30, 31, 31, 31, 30], 'grass': [30, 31, 31, 31, 30, 31], 'ground': [31, 31, 31, 31, 30, 30], 'ice': [31, 30, 30, 31, 31, 31], 'poison': [31, 31, 30, 31, 30, 30], 'psychic': [30, 31, 31, 30, 31, 31], 'rock': [31, 31, 30, 30, 31, 30], 'steel': [31, 31, 31, 31, 31, 30], 'water': [31, 31, 31, 30, 30, 31]}
evs: List[int] | None
static from_packed(packed_mon: str) TeambuilderPokemon

Converts a packed-format pokemon string into a TeambuilderPokemon object.

Parameters:

packed_mon (str) – The packed-format pokemon string to convert.

Returns:

The converted TeambuilderPokemon object.

Return type:

TeambuilderPokemon

static from_showdown(showdown_mon: str) TeambuilderPokemon

Converts a showdown-format pokemon string into a TeambuilderPokemon object.

Parameters:

showdown_mon (str) – The showdown-format pokemon string to convert.

Returns:

The converted TeambuilderPokemon object.

Return type:

TeambuilderPokemon

ivs: List[int] | None
moves: List[str]
property packed: str
property packed_endstring: str
property packed_evs: str
property packed_ivs: str
property packed_moves: str