Skip to content

Usage Tips

seria edited this page May 15, 2024 · 2 revisions

Starting and Closing the Client Properly

Remember to call start and close or use the async with syntax!

import ambr

async with ambr.AmbrAPI() as api:
    ...

# Or
api = ambr.AmbrAPI()
await api.start()
...
await api.close()

Finding Model's Attributes

If you're using an IDE like pycharm or VSCode, you can alt + left click on a variable and it will lead you the source code of the wrapper, from there you can see the model's docstring.

class ArtifactSet(BaseModel):
    """
    Represents an artifact set.

    Attributes
    ----------
    id: :class:`int`
        The artifact set's ID.
    name: :class:`str`
        The artifact set's name.
    rarity_list: List[:class:`int`]
        Obtainable rarities of the artifact set.
    affix_list: List[:class:`str`]
        The artifact set's set effect list.
    icon: :class:`str`
        The artifact set's icon.
    route: :class:`str`
        The artifact set's route.
    sort_order: :class:`int`
        The artifact set's sort order.
    """

Catching exceptions

All exception classes can be found in ambr/exceptions.py, Catch them with try-except.

import ambr

async with ambr.AmbrAPI() as api:
    try:
        await api.fetch_character(0)
    except ambr.exceptions.DataNotFoundError:
        print("Character does not exist.")
Clone this wiki locally