Skip to content

Machine

machine

Machine

Machine(client: _HTTPClientT_co)

Bases: SyncBaseExtension[Machine]

Extension for machine 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_machine

get_machine(id: int) -> Machine | None

Gets a machine from the cache.

Parameters:

Name Type Description Default
id int

The resource id.

required

Returns:

Type Description
Machine | None

The cached model or None.

Examples:

machine = client.machine.get_machine(1)
if machine:
    print(machine)
Source code in pokelance/ext/sync/machine.py
def get_machine(self, id: int) -> models.Machine | None:
    """Gets a machine from the cache.

    Parameters
    ----------
    id : int
        The resource id.

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

    Examples
    --------
    ```python
    machine = client.machine.get_machine(1)
    if machine:
        print(machine)
    ```"""
    route = Endpoint.get_machine(id)
    self._validate_resource(self._cache_group.machine, id, route)
    return self._cache_group.machine.get(route, None)

fetch_machine

fetch_machine(id: int) -> Machine

Fetches a machine from the API.

Parameters:

Name Type Description Default
id int

The resource id.

required

Returns:

Type Description
Machine

The fetched model.

Examples:

machine = client.machine.fetch_machine(1)
print(machine)
Source code in pokelance/ext/sync/machine.py
def fetch_machine(self, id: int) -> models.Machine:
    """Fetches a machine from the API.

    Parameters
    ----------
    id : int
        The resource id.

    Returns
    -------
    models.Machine
        The fetched model.

    Examples
    --------
    ```python
    machine = client.machine.fetch_machine(1)
    print(machine)
    ```"""
    route = Endpoint.get_machine(id)
    self._validate_resource(self._cache_group.machine, id, route)
    data = self._client.request(route)
    return self._cache_group.machine.setdefault(route, self._cache_group.machine.from_payload(data))

setup

setup(lance: PokeLanceSyncClient) -> None

Sets up the machine extension.

Source code in pokelance/ext/sync/machine.py
def setup(lance: PokeLanceSyncClient) -> None:
    """Sets up the machine extension."""
    lance.add_extension("machine", Machine(lance.http))

Comments