Skip to main content

AnimeAPI Python Wrapper

animeapi-python is a Python wrapper for the AnimeAPI made by nattadasu.

The wrapper is released with type hints and async support in mind for ease of use and is compatible with Python 3.7 or higher.

Installation

pip install animeapi-py

Depending on your system, you may need to use pip3 instead of pip, or sudo pip instead of pip.

Requirements

Usage

import animeapi

with animeapi.AnimeAPI() as api:
    # Get anime relation data for the anime with ID 1 on MyAnimeList
    mal = api.get_anime_relations(1, animeapi.Platform.MYANIMELIST)
    print(mal)

    # Get list of anime available on AniList
    anilist = api.get_list_anime_relations(animeapi.Platform.ANILIST)
    print(anilist[:2])  # Print first two results

    # Get dictionary of anime available on Kitsu
    kitsu = api.get_dict_anime_relations(animeapi.Platform.KITSU)
    print(kitsu['1'])  # Print data for Cowboy Bebop

We recommend using the with statement to create an instance of AnimeAPI as we designed the wrapper to be easy to switch between sync and async, although you can also use AnimeAPI directly on sync methods only.

Custom Headers

You can pass custom headers to the API client, which is useful for APIs that require authorization (e.g., ids.moe):

import animeapi

# Using custom headers for ids.moe
headers = {"Authorization": "Bearer YOUR_TOKEN_HERE"}

with animeapi.AnimeAPI(base_url="https://ids.moe", headers=headers) as api:
    # Get anime relation data with custom headers
    mal = api.get_anime_relations(1, animeapi.Platform.MYANIMELIST)
    print(mal)

Asyncronous Usage

Similarly, for async, you just need to replace AnimeAPI with AsyncAnimeAPI and use await on the methods.

You must use the wrapper in with statement, or you will receive RuntimeError exception.

import asyncio
import animeapi

async def main():
    async with animeapi.AsyncAnimeAPI() as api:
        # Get anime relation data for the anime with ID 1 on MyAnimeList
        mal = await api.get_anime_relations(1, animeapi.Platform.MYANIMELIST)
        print(mal)

        # Get list of anime available on AniList
        anilist = await api.get_list_anime_relations(animeapi.Platform.ANILIST)
        print(anilist[:2])  # Print first two results

        # Get dictionary of anime available on Kitsu
        kitsu = await api.get_dict_anime_relations(animeapi.Platform.KITSU)
        print(kitsu['1'])  # Print data for Cowboy Bebop

if __name__ == "__main__":
    asyncio.run(main())

Custom headers can also be used with async:

import asyncio
import animeapi

async def main():
    headers = {"Authorization": "Bearer YOUR_TOKEN_HERE"}

    async with animeapi.AsyncAnimeAPI(base_url="https://ids.moe", headers=headers) as api:
        mal = await api.get_anime_relations(1, animeapi.Platform.MYANIMELIST)
        print(mal)

if __name__ == "__main__":
    asyncio.run(main())

Documentation

You can find the documentation for the wrapper here

Available Methods

get_anime_relations(title_id: str | int, platform: str | Platform, media_type: str | TraktMediaType | TmdbMediaType | None = None, title_season: int | None) -> AnimeRelation

This method equals to the /:platform/:title_id endpoint on the API.

# Get anime relation data for the anime with ID 1 on MyAnimeList
mal = api.get_anime_relations(1, animeapi.Platform.MYANIMELIST)
print(mal)

# Get anime relation data for Trakt shows with season
trakt = api.get_anime_relations(152334, animeapi.Platform.TRAKT,
                                 media_type=animeapi.TraktMediaType.SHOWS,
                                 title_season=3)
print(trakt)

# Get anime relation data for TMDB TV shows
tmdb = api.get_anime_relations(12345, animeapi.Platform.THEMOVIEDB,
                                media_type=animeapi.TmdbMediaType.TV)
print(tmdb)

# Get anime relation data for The TVDB with season
tvdb = api.get_anime_relations(76885, animeapi.Platform.THETVDB,
                                title_season=1)
print(tvdb)

get_dict_anime_relations(platform: str | Platform) -> dict[str, AnimeRelation]

This method equals to the /:platform endpoint on the API. Use this method if you want to get complete data for all anime available on a platform and wanted to be able to access the data by the anime ID faster.

# Get dictionary of anime available on Kitsu
kitsu = api.get_dict_anime_relations(animeapi.Platform.KITSU)
print(kitsu['1'])  # Print data for Cowboy Bebop

get_list_anime_relations(platform: str | Platform) -> list[AnimeRelation]

This method equals to the /:platform() endpoint on the API.

# Get list of anime available on AniList
anilist = api.get_list_anime_relations(animeapi.Platform.ANILIST)
print(anilist[:2])  # Print first two results

get_list_index() -> list[AnimeRelation]

This method equals to the /animeapi endpoint on the API.

# Get list of anime available on AnimeAPI
animeapi_list = api.get_list_index()
print(animeapi_list[:2])  # Print first two results

get_status() -> ApiStatus

This method equals to the /status endpoint on the API.

# Get status of AnimeAPI
status = api.get_status()
print(status)

get_heartbeat() -> Heartbeat

This method equals to the /heartbeat endpoint on the API.

# Get heartbeat of AnimeAPI
heartbeat = api.get_heartbeat()
print(heartbeat)

get_updated_time() -> Updated

This method equals to the /updated endpoint on the API.

# Get last updated time of AnimeAPI
updated = api.get_updated_time()
print(updated)
print(updated.datetime())  # Convert to datetime class

License

animeapi-py is licensed under the GNU Affero General Public License v3.0.

Metadata

Release files for animeapi-py 3.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for animeapi-py 3.8.1
File Size Uploaded Provenance Actions
animeapi_py-3.8.1.tar.gz 25.7 kB Without provenance Details for animeapi_py-3.8.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for animeapi-py 3.8.1
File Interpreter ABI Platform Actions
animeapi_py-3.8.1-py3-none-any.whl Python 3 none any Details for animeapi_py-3.8.1-py3-none-any.whl

Total release size: 52.6 kB

Release files / animeapi_py-3.8.1.tar.gz

Download URL animeapi_py-3.8.1.tar.gz
Size 25.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9ed10f8207f1ccd7949ee3728285f4aced9a5ec57f71d211594ca5dc356fdea5
BLAKE2b-256 checksum
How to use checksums
28a2f868bba3b6399e2c953f8796fa90c8de91f797ad0fe19c7e2c536cd0092f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / animeapi_py-3.8.1-py3-none-any.whl

Download URL animeapi_py-3.8.1-py3-none-any.whl
Size 27.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c29f6e633d17bb613f459aa6514c0baab7ae325881f8a109eb6e4b3be5c22827
BLAKE2b-256 checksum
How to use checksums
ba986775d71cf7d88d554e8394f5ce5cda90041c99fdf1b2b60af02001e8c790
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for animeapi-py 3.8.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page