Skip to content

Commit

Permalink
docs: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravencentric committed Jul 6, 2024
1 parent e8bf608 commit b257bb2
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 277 deletions.
100 changes: 13 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
## About

- Supports both sync and async.
- Provides easy access to almost every field present in AniList's `Media` type.
- Only supports querying the `Media` type
- Only supports querying the `Media` type.

## Installation

Expand All @@ -45,91 +44,18 @@ pip install pyanilist

## Usage

1. `AniList()` - Synchronous class
- `search()` - Search a media

```py
from pyanilist import AniList, MediaType

media = AniList().search("Attack on Titan", type=MediaType.ANIME)

print(media.title.romaji)
"""
Shingeki no Kyojin
"""
print(media.site_url)
"""
https://anilist.co/anime/16498
"""
print(media.episodes)
"""
25
"""
```
- `get()` - Get a media by it's AniList ID

```py
from pyanilist import AniList

media = AniList().get(21459)

print(media.title.english)
"""
My Hero Academia
"""
print(media.site_url)
"""
https://anilist.co/anime/21459
"""
print(media.episodes)
"""
13
"""
```

2. `AsyncAniList()` - Asynchronous class
- `search()` - Search a media

```py
import asyncio
from pyanilist import AsyncAniList, MediaType

media = asyncio.run(AsyncAniList().search("Attack on Titan", type=MediaType.ANIME))

print(media.title.romaji)
"""
Shingeki no Kyojin
"""
print(media.site_url)
"""
https://anilist.co/anime/16498
"""
print(media.episodes)
"""
25
"""
```
- `get()` - Get a media by it's AniList ID

```py
import asyncio
from pyanilist import AsyncAniList

media = asyncio.run(AsyncAniList().get(21459))

print(media.title.english)
"""
My Hero Academia
"""
print(media.site_url)
"""
https://anilist.co/anime/21459
"""
print(media.episodes)
"""
13
"""
```
```py
from pyanilist import AniList

media = AniList().get("My Hero Academia")

print(media.title.romaji)
#> Boku no Hero Academia
print(media.site_url)
#> https://anilist.co/anime/21459
print(media.episodes)
#> 13
```

## Docs

Expand Down
12 changes: 0 additions & 12 deletions docs/api-reference/clients.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
::: pyanilist.AniList
options:
members:
- __init__
- search
- get


::: pyanilist.AsyncAniList
options:
members:
- __init__
- search
- get
22 changes: 21 additions & 1 deletion docs/api-reference/enums.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
::: pyanilist._enums.BaseStrEnum
::: pyanilist._enums.CharacterRole
options:
members: true
::: pyanilist._enums.ExternalLinkType
options:
members: true
::: pyanilist._enums.MediaFormat
options:
members: true
::: pyanilist._enums.MediaRankType
options:
members: true
::: pyanilist._enums.MediaRelation
options:
members: true
::: pyanilist._enums.MediaSeason
options:
members: true
::: pyanilist._enums.MediaSort
options:
members: true
::: pyanilist._enums.MediaSource
options:
members: true
::: pyanilist._enums.MediaStatus
::: pyanilist._enums.MediaType
options:
members: true
::: pyanilist._enums.MediaType
options:
members: true
3 changes: 3 additions & 0 deletions docs/api-reference/types.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
::: pyanilist._types.YearsActive
options:
members: true
::: pyanilist._types.FuzzyDateInt
::: pyanilist._types.Iterable
78 changes: 26 additions & 52 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
# Examples

!!! note
These examples use `pyanilist.AniList` but you can do the same thing with `pyanilist.AsyncAniList` since they share the same methods
These examples use [`pyanilist.AniList`][pyanilist.AniList] but you can do the same thing with [`pyanilist.AsyncAniList`][pyanilist.AsyncAniList] since they share the same methods

## AniList ID

```py
from pyanilist import AniList

media = AniList().get(16498)
media = AniList().get(id=16498)

print(media.title.english)
"""
Attack on Titan
"""
#> Attack on Titan
```

## Search

```py
from pyanilist import AniList

media = AniList().search("Attack on titan")
media = AniList().get("Attack on titan")

print(media.format)
"""
TV
"""
#> TV
print(media.title.romaji)
"""
Shingeki no Kyojin
"""
#> Shingeki no Kyojin
print(media.episodes)
"""
25
"""
#> 25
```

## Search with constraints

```py
from pyanilist import AniList, MediaSeason, MediaType, MediaStatus, MediaFormat
media = AniList().search(
media = AniList().get(
"My Hero Academia",
season=MediaSeason.SPRING,
season_year=2016,
Expand All @@ -51,85 +43,69 @@ media = AniList().search(

)
print(media.title.romaji)
"""
Boku no Hero Academia
"""
#> Boku no Hero Academia
print(media.start_date.iso_format())
"""
2016-04-03
"""
#> 2016-04-03
print(media.site_url)
"""
https://anilist.co/anime/21459
"""
#> https://anilist.co/anime/21459
```

## Related media

```py
from pyanilist import AniList

media = AniList().search("violet evergarden")
media = AniList().get("violet evergarden")

print(media.format)
"""
TV
"""
#> TV

for relation in media.relations:
print(f"{relation.title.romaji} ({relation.format}) - {relation.site_url}")
"""
Violet Evergarden: Kitto "Ai" wo Shiru Hi ga Kuru no Darou (OVA) - https://anilist.co/anime/101432
Violet Evergarden (NOVEL) - https://anilist.co/manga/97298
Violet Evergarden Gaiden: Eien to Jidou Shuki Ningyou (MOVIE) - https://anilist.co/anime/109190
Violet Evergarden CM (ONA) - https://anilist.co/anime/154164
"""
#> Violet Evergarden: Kitto "Ai" wo Shiru Hi ga Kuru no Darou (OVA) - https://anilist.co/anime/101432
#> Violet Evergarden (NOVEL) - https://anilist.co/manga/97298
#> Violet Evergarden Gaiden: Eien to Jidou Shuki Ningyou (MOVIE) - https://anilist.co/anime/109190
#> Violet Evergarden CM (ONA) - https://anilist.co/anime/154164
```

## Characters

```py
from pyanilist import AniList, CharacterRole

media = AniList().get(20954)
media = AniList().get(id=20954)

all_characters = [character.name.full for character in media.characters]

# Filter main characters
main_characters = [character.name.full for character in media.characters if character.role is CharacterRole.MAIN]

print(all_characters)
"""
['Shouya Ishida', 'Shouko Nishimiya', 'Yuzuru Nishimiya', 'Naoka Ueno', 'Miyako Ishida', 'Maria Ishida', 'Miki Kawai', 'Satoshi Mashiba', 'Tomohiro Nagatsuka', 'Yaeko Nishimiya', 'Ito Nishimiya', 'Miyoko Sahara', 'Kazuki Shimada', 'Takeuchi', 'Pedro', 'Keisuke Hirose', 'Ishida no Ane', 'Kita']
"""
#> ['Shouya Ishida', 'Shouko Nishimiya', 'Yuzuru Nishimiya', 'Naoka Ueno', 'Miyako Ishida', 'Maria Ishida', 'Miki Kawai', 'Satoshi Mashiba', 'Tomohiro Nagatsuka', 'Yaeko Nishimiya', 'Ito Nishimiya', 'Miyoko Sahara', 'Kazuki Shimada', 'Takeuchi', 'Pedro', 'Keisuke Hirose', 'Ishida no Ane', 'Kita']

print(main_characters)
"""
['Shouya Ishida', 'Shouko Nishimiya']
"""
#> ['Shouya Ishida', 'Shouko Nishimiya']
```

## Retries

AniList API is flaky, sometimes it might return an error for a perfectly valid request. `pyanilist` handles this by simply retrying failed requests a specified number of times (default is 5) before raising an error. Every subsequent retry also adds an additional one-second delay between requests.
AniList API is flaky, sometimes it might return an error for a perfectly valid request. `pyanilist` handles this by simply retrying failed requests a specified number of times (default is 5) before raising an error. Every subsequent retry also adds an additional delay between requests.

```py
from pyanilist import AniList

# Configure the number of retries. Setting it to 1 disables retrying.
anilist = AniList(retries=1)

media = anilist.search("violet evergarden")
media = anilist.get("violet evergarden")

print(f"{media.title.english} - {media.site_url}")
"""
Violet Evergarden - https://anilist.co/anime/21827
"""
#> Violet Evergarden - https://anilist.co/anime/21827
```

## Client

`pyanilist` gives you direct access to the internal [`httpx.Client()`](https://www.python-httpx.org/api/#client) used to send the POST request.
`pyanilist` lets you pass keyword arguments to the internal [`httpx.Client`](https://www.python-httpx.org/api/#client) used to send the POST request.

```py
from pyanilist import AniList
Expand All @@ -139,10 +115,8 @@ headers = {'user-agent': 'my-app/0.0.1'}
# You can pass any httpx.Client() keyword argument to AniList()
anilist = AniList(headers=headers)

media = anilist.get(105333)
media = anilist.get(id=105333)

print(media.title.english)
"""
Dr. STONE
"""
#> Dr. STONE
```
Loading

0 comments on commit b257bb2

Please sign in to comment.