Skip to content

Clients

AniList

AniList(api_url: str = 'https://graphql.anilist.co', retries: PositiveInt = 5, **kwargs: HTTPXClientKwargs)

AniList API client.

Parameters:

Name Type Description Default
api_url str

The URL of the AniList API. Default is https://graphql.anilist.co.

'https://graphql.anilist.co'
retries PositiveInt

Number of times to retry a failed request before raising an error. Default is 5. Set this to 1 to disable retrying.

5
kwargs HTTPXClientKwargs

Keyword arguments to pass to the underlying httpx.Client() used to make the POST request.

{}
Source code in src/pyanilist/_clients/_sync.py
def __init__(
    self, api_url: str = "https://graphql.anilist.co", retries: PositiveInt = 5, **kwargs: HTTPXClientKwargs
) -> None:
    """
    AniList API client.

    Parameters
    ----------
    api_url : str, optional
        The URL of the AniList API. Default is `https://graphql.anilist.co`.
    retries : PositiveInt, optional
        Number of times to retry a failed request before raising an error. Default is 5.
        Set this to 1 to disable retrying.
    kwargs : HTTPXClientKwargs, optional
        Keyword arguments to pass to the underlying [httpx.Client()](https://www.python-httpx.org/api/#client)
        used to make the POST request.
    """
    self.api_url = api_url
    self.retries = retries
    self.kwargs = kwargs

search

search(title: AniListTitle, season: MediaSeason | None = None, season_year: AniListYear | None = None, type: MediaType | None = None, format: MediaFormat | None = None, status: MediaStatus | None = None) -> Media

Search for media on AniList based on the provided parameters.

Parameters:

Name Type Description Default
title AniListTitle

The string used for searching on AniList.

required
season MediaSeason | None

The season the media was initially released in. Default is None.

None
season_year AniListYear | None

The season year the media was initially released in. Default is None.

None
type MediaType | None

The type of the media; anime or manga. Default is None.

None
format MediaFormat | None

The format the media was released in. Default is None.

None
status MediaStatus | None

The current releasing status of the media. Default is None.

None

Raises:

Type Description
ValidationError

Invalid input

HTTPStatusError

AniList returned a non 2xx response.

Returns:

Type Description
Media

A Media object representing the retrieved media information.

Source code in src/pyanilist/_clients/_sync.py
@validate_call
def search(
    self,
    title: AniListTitle,
    season: MediaSeason | None = None,
    season_year: AniListYear | None = None,
    type: MediaType | None = None,
    format: MediaFormat | None = None,
    status: MediaStatus | None = None,
) -> Media:
    """
    Search for media on AniList based on the provided parameters.

    Parameters
    ----------
    title : AniListTitle
        The string used for searching on AniList.
    season : MediaSeason | None, optional
        The season the media was initially released in. Default is None.
    season_year : AniListYear | None, optional
        The season year the media was initially released in. Default is None.
    type : MediaType | None, optional
        The type of the media; anime or manga. Default is None.
    format : MediaFormat | None, optional
        The format the media was released in. Default is None.
    status : MediaStatus | None, optional
        The current releasing status of the media. Default is None.

    Raises
    ------
    ValidationError
        Invalid input
    HTTPStatusError
        AniList returned a non 2xx response.

    Returns
    -------
    Media
        A Media object representing the retrieved media information.
    """

    return Media.model_validate(
        self._post_process_response(
            self._post_request(
                title=title,
                season=season,
                season_year=season_year,
                type=type,
                format=format,
                status=status,
            )
        )
    )

get

get(id: AniListID) -> Media

Retrieve media information from AniList based on it's ID.

Parameters:

Name Type Description Default
id int

AniList ID of the media as found in the URL: https://anilist.co/{type}/{id}.

required

Raises:

Type Description
ValidationError

Invalid input

HTTPStatusError

AniList returned a non 2xx response.

Returns:

Type Description
Media

A Media object representing the retrieved media information.

Source code in src/pyanilist/_clients/_sync.py
@validate_call
def get(self, id: AniListID) -> Media:
    """
    Retrieve media information from AniList based on it's ID.

    Parameters
    ----------
    id : int
        AniList ID of the media as found in the URL: `https://anilist.co/{type}/{id}`.

    Raises
    ------
    ValidationError
        Invalid input
    HTTPStatusError
        AniList returned a non 2xx response.

    Returns
    -------
    Media
        A Media object representing the retrieved media information.
    """

    return Media.model_validate(
        self._post_process_response(
            self._post_request(
                id=id,
            )
        )
    )

AsyncAniList

AsyncAniList(api_url: str = 'https://graphql.anilist.co', retries: PositiveInt = 5, **kwargs: HTTPXAsyncClientKwargs)

Async AniList API client.

Parameters:

Name Type Description Default
api_url str

The URL of the AniList API. Default is https://graphql.anilist.co.

'https://graphql.anilist.co'
retries PositiveInt

Number of times to retry a failed request before raising an error. Default is 5. Set this to 1 to disable retrying.

5
kwargs HTTPXAsyncClientKwargs

Keyword arguments to pass to the underlying httpx.AsyncClient() used to make the POST request.

{}
Source code in src/pyanilist/_clients/_async.py
def __init__(
    self, api_url: str = "https://graphql.anilist.co", retries: PositiveInt = 5, **kwargs: HTTPXAsyncClientKwargs
) -> None:
    """
    Async AniList API client.

    Parameters
    ----------
    api_url : str, optional
        The URL of the AniList API. Default is `https://graphql.anilist.co`.
    retries : PositiveInt, optional
        Number of times to retry a failed request before raising an error. Default is 5.
        Set this to 1 to disable retrying.
    kwargs : HTTPXAsyncClientKwargs, optional
        Keyword arguments to pass to the underlying [httpx.AsyncClient()](https://www.python-httpx.org/api/#asyncclient)
        used to make the POST request.
    """
    self.api_url = api_url
    self.retries = retries
    self.kwargs = kwargs

search async

search(title: AniListTitle, season: MediaSeason | None = None, season_year: AniListYear | None = None, type: MediaType | None = None, format: MediaFormat | None = None, status: MediaStatus | None = None) -> Media

Search for media on AniList based on the provided parameters.

Parameters:

Name Type Description Default
title AniListTitle

The string used for searching on AniList.

required
season MediaSeason | None

The season the media was initially released in. Default is None.

None
season_year AniListYear | None

The season year the media was initially released in. Default is None.

None
type MediaType | None

The type of the media; anime or manga. Default is None.

None
format MediaFormat | None

The format the media was released in. Default is None.

None
status MediaStatus | None

The current releasing status of the media. Default is None.

None

Raises:

Type Description
ValidationError

Invalid input

HTTPStatusError

AniList returned a non 2xx response.

Returns:

Type Description
Media

A Media object representing the retrieved media information.

Source code in src/pyanilist/_clients/_async.py
@validate_call
async def search(
    self,
    title: AniListTitle,
    season: MediaSeason | None = None,
    season_year: AniListYear | None = None,
    type: MediaType | None = None,
    format: MediaFormat | None = None,
    status: MediaStatus | None = None,
) -> Media:
    """
    Search for media on AniList based on the provided parameters.

    Parameters
    ----------
    title : AniListTitle
        The string used for searching on AniList.
    season : MediaSeason | None, optional
        The season the media was initially released in. Default is None.
    season_year : AniListYear | None, optional
        The season year the media was initially released in. Default is None.
    type : MediaType | None, optional
        The type of the media; anime or manga. Default is None.
    format : MediaFormat | None, optional
        The format the media was released in. Default is None.
    status : MediaStatus | None, optional
        The current releasing status of the media. Default is None.

    Raises
    ------
    ValidationError
        Invalid input
    HTTPStatusError
        AniList returned a non 2xx response.

    Returns
    -------
    Media
        A Media object representing the retrieved media information.
    """

    return Media.model_validate(
        await self._post_process_response(
            await self._post_request(
                title=title,
                season=season,
                season_year=season_year,
                type=type,
                format=format,
                status=status,
            )
        )
    )

get async

get(id: AniListID) -> Media

Retrieve media information from AniList based on it's ID.

Parameters:

Name Type Description Default
id int

AniList ID of the media as found in the URL: https://anilist.co/{type}/{id}.

required

Raises:

Type Description
ValidationError

Invalid input

HTTPStatusError

AniList returned a non 2xx response.

Returns:

Type Description
Media

A Media object representing the retrieved media information.

Source code in src/pyanilist/_clients/_async.py
@validate_call
async def get(self, id: AniListID) -> Media:
    """
    Retrieve media information from AniList based on it's ID.

    Parameters
    ----------
    id : int
        AniList ID of the media as found in the URL: `https://anilist.co/{type}/{id}`.

    Raises
    ------
    ValidationError
        Invalid input
    HTTPStatusError
        AniList returned a non 2xx response.

    Returns
    -------
    Media
        A Media object representing the retrieved media information.
    """

    return Media.model_validate(
        await self._post_process_response(
            await self._post_request(
                id=id,
            )
        )
    )