Skip to content

Commit

Permalink
chore: misc changes (#9)
Browse files Browse the repository at this point in the history
* chore: misc changes

* docstring

* more
  • Loading branch information
Ravencentric authored Mar 23, 2024
1 parent 2279f23 commit 1e1fe47
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 73 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<img src="https://raw.githubusercontent.com/Ravencentric/pyanilist/main/docs/assets/logo.png" alt="Logo" width="400">
</a>
<p align="center">
Simple read-only Anilist API wrapper
Simple Anilist API wrapper to fetch data about it's media
<br/>
<br/>
</p>
Expand All @@ -17,7 +17,7 @@
[![PyPI - Version](https://img.shields.io/pypi/v/pyanilist?link=https%3A%2F%2Fpypi.org%2Fproject%2Fpyanilist%2F)](https://pypi.org/project/pyanilist/)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyanilist)
![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/Ravencentric/pyanilist/release.yml)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ravencentric/pyanilist/test.yml?label=tests&link=https%3A%2F%2Fgithub.com%2FRavencentric%2Fpyanilist%2Factions%2Fworkflows%2Ftest.yml)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ravencentric/pyanilist/test.yml?label=tests)
![License](https://img.shields.io/github/license/Ravencentric/pyanilist)
![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)
![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)
Expand All @@ -33,9 +33,9 @@

## About

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

## Installation

Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/exceptions.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
!!! note
This module simply re-exports exceptions from
PyAnilist simply re-exports exceptions from
[`httpx`](https://www.python-httpx.org/exceptions/) and
[`pydantic`](https://docs.pydantic.dev/latest/api/pydantic_core/#pydantic_core.ValidationError) for convenience.

Expand Down
6 changes: 4 additions & 2 deletions docs/api-reference/types.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
!!! note
Additionally, this module also offers the convenience of re-exporting some of the Pydantic types used within this library:
Additionally, PyAnilist also uses and exports the following [pydantic](https://docs.pydantic.dev/latest/) types for convenience:

- [HttpUrl](https://docs.pydantic.dev/latest/api/networks/#pydantic.networks.HttpUrl)

Expand All @@ -10,4 +10,6 @@
::: pyanilist._types.AnilistID
::: pyanilist._types.AnilistTitle
::: pyanilist._types.AnilistYear
::: pyanilist._types.YearsActive
::: pyanilist._types.YearsActive
::: pyanilist._types.HTTPXAsyncClientKwargs
::: pyanilist._types.HTTPXClientKwargs
12 changes: 6 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<img src="https://raw.githubusercontent.com/Ravencentric/pyanilist/main/docs/assets/logo.png" alt="Logo" width="400">
</a>
<p align="center">
Simple read-only Anilist API wrapper
Simple Anilist API wrapper to fetch data about it's media
<br/>
<br/>
</p>
Expand All @@ -13,8 +13,8 @@
<p align="center">
<a href="https://pypi.org/project/pyanilist/"><img src="https://img.shields.io/pypi/v/pyanilist" alt="PyPI - Version" ></a>
<img src="https://img.shields.io/pypi/pyversions/pyanilist" alt="PyPI - Python Version">
<img src="https://img.shields.io/github/actions/workflow/status/Ravencentric/pyanilist/release.yml" alt="GitHub Workflow Status">
<img src="https://img.shields.io/github/actions/workflow/status/Ravencentric/pyanilist/test.yml" alt="GitHub Workflow Status">
<img src="https://img.shields.io/github/actions/workflow/status/Ravencentric/pyanilist/release.yml?" alt="GitHub Workflow Status">
<img src="https://img.shields.io/github/actions/workflow/status/Ravencentric/pyanilist/test.yml?label=tests" alt="GitHub Workflow Status">
<img src="https://img.shields.io/github/license/Ravencentric/pyanilist" alt="License">
<img src="https://www.mypy-lang.org/static/mypy_badge.svg" alt="Checked with mypy">
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff">
Expand All @@ -23,9 +23,9 @@

## About

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

## Installation

Expand Down
58 changes: 29 additions & 29 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "pyanilist"
version = "0.3.0"
description = "Simple read-only Anilist API wrapper"
description = "Simple Anilist API wrapper to fetch data about it's media"
authors = ["Raventric <[email protected]>"]
license = "Unlicense"
readme = "README.md"
Expand Down Expand Up @@ -30,7 +30,7 @@ httpx = ">=0.27.0"
boltons = ">=23.1.1"
tenacity = ">=8.2.3"
strenum = { version = ">=0.4.15", python = "<3.11" }
importlib-metadata = { version = ">=7.0.2", python = "<3.10" }
importlib-metadata = { version = ">=7.1.0", python = "<3.10" }
eval-type-backport = { version = ">=0.1.3", python = "<3.10" }

[tool.ruff]
Expand Down
22 changes: 10 additions & 12 deletions src/pyanilist/_clients/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from .._enums import MediaFormat, MediaSeason, MediaStatus, MediaType
from .._models import Media
from .._query import query_string
from .._types import AnilistID, AnilistTitle, AnilistYear
from .._types import AnilistID, AnilistTitle, AnilistYear, HTTPXAsyncClientKwargs
from .._utils import flatten, remove_null_fields


class AsyncAnilist:
def __init__(
self, api_url: str = "https://graphql.anilist.co", retries: int = 5, **httpx_async_client_kwargs: Any
self, api_url: str = "https://graphql.anilist.co", retries: int = 5, **kwargs: HTTPXAsyncClientKwargs
) -> None:
"""
Async Anilist API client.
Expand All @@ -26,13 +26,13 @@ def __init__(
The URL of the Anilist API. Default is "https://graphql.anilist.co".
retries : int, optional
Number of times to retry a failed request before raising an error. Default is 5.
httpx_async_client_kwargs : Any, optional
Keyword arguments to pass to the internal [httpx.AsyncClient()](https://www.python-httpx.org/api/#asyncclient)
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.httpx_async_client_kwargs = httpx_async_client_kwargs
self.kwargs = kwargs

async def _post_request(
self,
Expand Down Expand Up @@ -98,7 +98,7 @@ async def _post_request(
reraise=True,
):
with attempt:
async with httpx.AsyncClient(**self.httpx_async_client_kwargs) as client:
async with httpx.AsyncClient(**self.kwargs) as client:
response = await client.post(self.api_url, json=payload)
response.raise_for_status()

Expand Down Expand Up @@ -194,9 +194,8 @@ async def search(
------
ValidationError
Invalid input
pyanilist._exceptions.*
Any exception from the pyanilist._exceptions module may be raised
in case of errors encountered during the POST request.
HTTPStatusError
Anilist returned a non 2xx response.
Returns
-------
Expand Down Expand Up @@ -231,9 +230,8 @@ async def get(self, id: AnilistID) -> Media:
------
ValidationError
Invalid input
pyanilist._exceptions.*
Any exception from the pyanilist._exceptions module may be raised
in case of errors encountered during the POST request.
HTTPStatusError
Anilist returned a non 2xx response.
Returns
-------
Expand Down
22 changes: 10 additions & 12 deletions src/pyanilist/_clients/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from .._enums import MediaFormat, MediaSeason, MediaStatus, MediaType
from .._models import Media
from .._query import query_string
from .._types import AnilistID, AnilistTitle, AnilistYear
from .._types import AnilistID, AnilistTitle, AnilistYear, HTTPXClientKwargs
from .._utils import flatten, remove_null_fields


class Anilist:
def __init__(
self, api_url: str = "https://graphql.anilist.co", retries: int = 5, **httpx_client_kwargs: Any
self, api_url: str = "https://graphql.anilist.co", retries: int = 5, **kwargs: HTTPXClientKwargs
) -> None:
"""
Anilist API client.
Expand All @@ -26,13 +26,13 @@ def __init__(
The URL of the Anilist API. Default is "https://graphql.anilist.co".
retries : int, optional
Number of times to retry a failed request before raising an error. Default is 5.
httpx_client_kwargs : Any, optional
Keyword arguments to pass to the internal [httpx.Client()](https://www.python-httpx.org/api/#client)
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.httpx_client_kwargs = httpx_client_kwargs
self.kwargs = kwargs

def _post_request(
self,
Expand Down Expand Up @@ -98,7 +98,7 @@ def _post_request(
reraise=True,
):
with attempt:
with httpx.Client(**self.httpx_client_kwargs) as client:
with httpx.Client(**self.kwargs) as client:
response = client.post(self.api_url, json=payload).raise_for_status()

return response
Expand Down Expand Up @@ -193,9 +193,8 @@ def search(
------
ValidationError
Invalid input
pyanilist._exceptions.*
Any exception from the pyanilist._exceptions module may be raised
in case of errors encountered during the POST request.
HTTPStatusError
Anilist returned a non 2xx response.
Returns
-------
Expand Down Expand Up @@ -230,9 +229,8 @@ def get(self, id: AnilistID) -> Media:
------
ValidationError
Invalid input
pyanilist._exceptions.*
Any exception from the pyanilist._exceptions module may be raised
in case of errors encountered during the POST request.
HTTPStatusError
Anilist returned a non 2xx response.
Returns
-------
Expand Down
4 changes: 2 additions & 2 deletions src/pyanilist/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ class Relation(ParentModel):
trailer: MediaTrailer = MediaTrailer()
"""Media trailer or advertisement"""

updated_at: datetime
updated_at: datetime = datetime.min
"""When the media's data was last updated"""

cover_image: MediaCoverImage = MediaCoverImage()
Expand Down Expand Up @@ -608,7 +608,7 @@ class Media(ParentModel):
trailer: MediaTrailer = MediaTrailer()
"""Media trailer or advertisement"""

updated_at: datetime
updated_at: datetime = datetime.min
"""When the media's data was last updated"""

cover_image: MediaCoverImage = MediaCoverImage()
Expand Down
Loading

0 comments on commit 1e1fe47

Please sign in to comment.