Skip to content

Game

game

Game

Game(client: _HTTPClientT_co)

Bases: AsyncBaseExtension[Game]

Extension for game related endpoints.

Source code in pokelance/ext/_base.py
def __init__(self, client: _HTTPClientT_co) -> None:
    self._client = client
    self._cache_manager = client.cache_manager
    self._cache_group = getattr(self._cache_manager, self.__class__.__name__.lower())

get_generation

get_generation(name: str | int) -> Generation | None

Gets a generation from the cache.

Parameters:

Name Type Description Default
name str | int

The name or id.

required

Returns:

Type Description
Generation | None

The cached model or None.

Examples:

generation = client.game.get_generation("generation-i")
if generation:
    print(generation)
Source code in pokelance/ext/_async/game.py
def get_generation(self, name: str | int) -> models.Generation | None:
    """Gets a generation from the cache.

    Parameters
    ----------
    name : str | int
        The name or id.

    Returns
    -------
    models.Generation | None
        The cached model or None.

    Examples
    --------
    ```python
    generation = client.game.get_generation("generation-i")
    if generation:
        print(generation)
    ```"""
    route = Endpoint.get_generation(name)
    self._validate_resource(self._cache_group.generation, name, route)
    return self._cache_group.generation.get(route, None)

fetch_generation async

fetch_generation(name: str | int) -> Generation

Fetches a generation from the API.

Parameters:

Name Type Description Default
name str | int

The name or id.

required

Returns:

Type Description
Generation

The fetched model.

Examples:

generation = await client.game.fetch_generation("generation-i")
print(generation)
Source code in pokelance/ext/_async/game.py
async def fetch_generation(self, name: str | int) -> models.Generation:
    """Fetches a generation from the API.

    Parameters
    ----------
    name : str | int
        The name or id.

    Returns
    -------
    models.Generation
        The fetched model.

    Examples
    --------
    ```python
    generation = await client.game.fetch_generation("generation-i")
    print(generation)
    ```"""
    route = Endpoint.get_generation(name)
    self._validate_resource(self._cache_group.generation, name, route)
    data = await self._client.request(route)
    return self._cache_group.generation.setdefault(route, self._cache_group.generation.from_payload(data))

get_pokedex

get_pokedex(name: str | int) -> Pokedex | None

Gets a pokedex from the cache.

Parameters:

Name Type Description Default
name str | int

The name or id.

required

Returns:

Type Description
Pokedex | None

The cached model or None.

Examples:

pokedex = client.game.get_pokedex("national")
if pokedex:
    print(pokedex)
Source code in pokelance/ext/_async/game.py
def get_pokedex(self, name: str | int) -> models.Pokedex | None:
    """Gets a pokedex from the cache.

    Parameters
    ----------
    name : str | int
        The name or id.

    Returns
    -------
    models.Pokedex | None
        The cached model or None.

    Examples
    --------
    ```python
    pokedex = client.game.get_pokedex("national")
    if pokedex:
        print(pokedex)
    ```"""
    route = Endpoint.get_pokedex(name)
    self._validate_resource(self._cache_group.pokedex, name, route)
    return self._cache_group.pokedex.get(route, None)

fetch_pokedex async

fetch_pokedex(name: str | int) -> Pokedex

Fetches a pokedex from the API.

Parameters:

Name Type Description Default
name str | int

The name or id.

required

Returns:

Type Description
Pokedex

The fetched model.

Examples:

pokedex = await client.game.fetch_pokedex("national")
print(pokedex)
Source code in pokelance/ext/_async/game.py
async def fetch_pokedex(self, name: str | int) -> models.Pokedex:
    """Fetches a pokedex from the API.

    Parameters
    ----------
    name : str | int
        The name or id.

    Returns
    -------
    models.Pokedex
        The fetched model.

    Examples
    --------
    ```python
    pokedex = await client.game.fetch_pokedex("national")
    print(pokedex)
    ```"""
    route = Endpoint.get_pokedex(name)
    self._validate_resource(self._cache_group.pokedex, name, route)
    data = await self._client.request(route)
    return self._cache_group.pokedex.setdefault(route, self._cache_group.pokedex.from_payload(data))

get_version

get_version(name: str | int) -> Version | None

Gets a version from the cache.

Parameters:

Name Type Description Default
name str | int

The name or id.

required

Returns:

Type Description
Version | None

The cached model or None.

Examples:

version = client.game.get_version("red")
if version:
    print(version)
Source code in pokelance/ext/_async/game.py
def get_version(self, name: str | int) -> models.Version | None:
    """Gets a version from the cache.

    Parameters
    ----------
    name : str | int
        The name or id.

    Returns
    -------
    models.Version | None
        The cached model or None.

    Examples
    --------
    ```python
    version = client.game.get_version("red")
    if version:
        print(version)
    ```"""
    route = Endpoint.get_version(name)
    self._validate_resource(self._cache_group.version, name, route)
    return self._cache_group.version.get(route, None)

fetch_version async

fetch_version(name: str | int) -> Version

Fetches a version from the API.

Parameters:

Name Type Description Default
name str | int

The name or id.

required

Returns:

Type Description
Version

The fetched model.

Examples:

version = await client.game.fetch_version("red")
print(version)
Source code in pokelance/ext/_async/game.py
async def fetch_version(self, name: str | int) -> models.Version:
    """Fetches a version from the API.

    Parameters
    ----------
    name : str | int
        The name or id.

    Returns
    -------
    models.Version
        The fetched model.

    Examples
    --------
    ```python
    version = await client.game.fetch_version("red")
    print(version)
    ```"""
    route = Endpoint.get_version(name)
    self._validate_resource(self._cache_group.version, name, route)
    data = await self._client.request(route)
    return self._cache_group.version.setdefault(route, self._cache_group.version.from_payload(data))

get_version_group

get_version_group(name: str | int) -> VersionGroup | None

Gets a version group from the cache.

Parameters:

Name Type Description Default
name str | int

The name or id.

required

Returns:

Type Description
VersionGroup | None

The cached model or None.

Examples:

group = client.game.get_version_group("red-blue")
if group:
    print(group)
Source code in pokelance/ext/_async/game.py
def get_version_group(self, name: str | int) -> models.VersionGroup | None:
    """Gets a version group from the cache.

    Parameters
    ----------
    name : str | int
        The name or id.

    Returns
    -------
    models.VersionGroup | None
        The cached model or None.

    Examples
    --------
    ```python
    group = client.game.get_version_group("red-blue")
    if group:
        print(group)
    ```"""
    route = Endpoint.get_version_group(name)
    self._validate_resource(self._cache_group.version_group, name, route)
    return self._cache_group.version_group.get(route, None)

fetch_version_group async

fetch_version_group(name: str | int) -> VersionGroup

Fetches a version group from the API.

Parameters:

Name Type Description Default
name str | int

The name or id.

required

Returns:

Type Description
VersionGroup

The fetched model.

Examples:

group = await client.game.fetch_version_group("red-blue")
print(group)
Source code in pokelance/ext/_async/game.py
async def fetch_version_group(self, name: str | int) -> models.VersionGroup:
    """Fetches a version group from the API.

    Parameters
    ----------
    name : str | int
        The name or id.

    Returns
    -------
    models.VersionGroup
        The fetched model.

    Examples
    --------
    ```python
    group = await client.game.fetch_version_group("red-blue")
    print(group)
    ```"""
    route = Endpoint.get_version_group(name)
    self._validate_resource(self._cache_group.version_group, name, route)
    data = await self._client.request(route)
    return self._cache_group.version_group.setdefault(route, self._cache_group.version_group.from_payload(data))

setup

setup(lance: PokeLanceAsyncClient) -> None

Sets up the game extension.

Source code in pokelance/ext/_async/game.py
def setup(lance: PokeLanceAsyncClient) -> None:
    """Sets up the game extension."""
    lance.add_extension("game", Game(lance.http))

Comments