A complete Python wrapper for AniList GraphQL API
Project description
AniList-API Python Wrapper
A powerful, modular Python client for the AniList GraphQL API that enables you to fetch anime, manga, user profiles, characters, and more with minimal setup.
Features
- Comprehensive search for Anime and Manga with detailed metadata
- Fetch AniList user profiles and statistics
- Retrieve character information including descriptions and images
- Minimal external dependencies (
requestsonly) - Graceful error handling and clear exceptions
- Modular design for easy integration and extension
Installation
Install the latest stable release from PyPI:
pip install anilist-api
Or install the latest development version directly from GitHub:
pip install git+https://github.com/anbuinfosec/anilist-api.git
Getting Started
Importing functions
Import only the features you need:
from anilist_api import search_anime, search_manga, get_user, search_character
Basic Usage Examples
Search Anime by Title
try:
anime_results = search_anime("Fullmetal Alchemist", per_page=3)
for anime in anime_results:
title = anime['title']['english'] or anime['title']['romaji']
print(f"{title} | Status: {anime['status']} | Score: {anime.get('averageScore', 'N/A')}")
except Exception as e:
print(f"Failed to fetch anime: {e}")
Search Manga by Title
try:
manga_results = search_manga("Death Note", per_page=3)
for manga in manga_results:
title = manga['title']['english'] or manga['title']['romaji']
print(f"{title} | Volumes: {manga.get('volumes', 'N/A')} | Status: {manga['status']}")
except Exception as e:
print(f"Failed to fetch manga: {e}")
Get User Profile and Stats
try:
user = get_user("example_username")
if user:
print(f"User: {user['name']}")
print(f"Anime watched: {user['statistics']['anime']['count']}")
print(f"Manga read: {user['statistics']['manga']['count']}")
else:
print("User not found.")
except Exception as e:
print(f"Failed to fetch user info: {e}")
Search Characters by Name
try:
characters = search_character("Mikasa Ackerman", per_page=2)
for character in characters:
print(f"{character['name']['full']} — {character['description'][:120]}...")
except Exception as e:
print(f"Failed to fetch characters: {e}")
Advanced Usage
Handling Pagination and Large Data Sets
The per_page argument controls the number of results per request (max 50). For larger data sets, you can modify queries to handle pages:
def fetch_all_anime(search_term):
page = 1
all_results = []
while True:
results = search_anime(search_term, per_page=50, page=page)
if not results:
break
all_results.extend(results)
page += 1
return all_results
Custom GraphQL Queries
If you want to extend functionality beyond the wrapper, you can directly use the internal graphql_request function:
from anilist_api.graphql import graphql_request
query = """
query ($id: Int) {
Media(id: $id) {
id
title {
romaji
english
}
description(asHtml: false)
}
}
"""
variables = {"id": 15125} # Example Media ID for "Naruto"
try:
data = graphql_request(query, variables)
media = data.get("Media", {})
print(media.get("title", {}).get("english"))
print(media.get("description"))
except Exception as e:
print(f"GraphQL request failed: {e}")
Error Handling
The library raises AniListAPIError (a subclass of Exception) for any API-related issues such as HTTP errors, malformed requests, or returned API errors.
Example:
from anilist_api.exceptions import AniListAPIError
try:
results = search_anime("NonExistentAnimeTitle")
except AniListAPIError as api_err:
print(f"AniList API error: {api_err}")
except Exception as e:
print(f"Unexpected error: {e}")
Development & Contribution
Feel free to contribute! Fork the repo and submit pull requests with improvements or fixes.
- Follow PEP8 style guidelines
- Write clear commit messages
- Add tests for new features
- Open issues for bugs or feature requests
License
This project is licensed under the MIT License — see the LICENSE file for details.
Useful Links
- AniList API Documentation: https://docs.anilist.co
- GitHub Repository: https://github.com/anbuinfosec/anilist-api
- Issue Tracker: https://github.com/anbuinfosec/anilist-api/issues
Made with ❤️ by Mohammad Alamin
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anilist-api-0.1.0.tar.gz.
File metadata
- Download URL: anilist-api-0.1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee342bf5d73c1b3635154e5d82b5f7b995a826e86413e6a387d17fdca1a03fcf
|
|
| MD5 |
6978aabc4a3fe0bf9915e57e8d462bbc
|
|
| BLAKE2b-256 |
8e3585ec8d787d53afb617298d8872158af36338289ba9ee28006e66a063f026
|
File details
Details for the file anilist_api-0.1.0-py3-none-any.whl.
File metadata
- Download URL: anilist_api-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba6724c39855a5b4151d4f8bd748e00865873f21a20d414c7c82e0dc6e860328
|
|
| MD5 |
13733b3e90a6da4287a822c863fb0db7
|
|
| BLAKE2b-256 |
db05bab00ec30d4c07c6e6aa03136ac5c980d6edd223427c2d237de8915affc2
|