Utilities for the Anilist GraphQL API.
Project description
Nifty Anilist Tools
Overview
This is a simple utility library for interfacing with the Anilist GraphQL API. It provides things like authentication and schema validation for requests.
Setup
To use this library, you will need to have the variables shown in .env.example in environment variables or your local .env file.
Features
GraphQL Requests
The Anilist API is GraphQL-based and provides a public schema. This library uses gql to make GraphQL requests. You should use the anilist_request() function in request.py to make requests to Anilist.
Anilist Auth
Token Storage
This library will store Anilist auth token(s) locally in one of two ways (customizable with the TOKEN_SAVING_METHOD environment variable):
- Using your system's keyring (kept "permanently"):
KEYRING - In-memory (lost when you restart your program):
IN_MEMORY
Using Auth
In order to get an auth token for the first time, you can use the sign_in_if_no_global() function from auth.py. After the first time, these details will be stored locally and added to your Anilist requests automatically.
Note: The sign-in function currently opens an instance of Google Chrome to the Anilist login page, from which your auth code will be automatically extracted. There will be more ways to do sign-in later.
There are two ways that auth headers can be added to your requests:
- Using a global user ID stored in the
.envfile: The ID is stored asANILIST_CURRENT_USER. This is the user ID that will be used to retrieve the token from the storage method(s) above. When making requests withanilist_request(), you can ignore the optionaluser_idparameter to use this approach. Example:
async def do_something():
request = gql("some query")
anilist_request(request)
if __name__ == "__main__":
sign_in_if_no_global()
asyncio.run(do_something())
- Manually passing in a user ID to the
anilist_request()with theuser_idparameter will try to get that user's token from local storage and use it instead of the global one. Example:
async def do_something(user_id: str):
request = gql("some query")
anilist_request(request, user_id=user_id)
if __name__ == "__main__":
my_user_id = "12345"
asyncio.run(do_something(user_id=my_user_id))
You can also choose to not use auth on requests with the use_auth parameter (default is True):
async def do_something():
request = gql("some query")
anilist_request(request, use_auth=False)
Project details
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 nifty_anilist-0.1.1.tar.gz.
File metadata
- Download URL: nifty_anilist-0.1.1.tar.gz
- Upload date:
- Size: 32.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e4a56bb0961d928f408dc4c857f640fab31e608f08a19ab48b36aaeb33772b5
|
|
| MD5 |
8de03f744d9b022e57fcb7890da6d392
|
|
| BLAKE2b-256 |
e32493e350a2c1fa6c1f7b31f27ff88e566616b8ecbf47d57afe7612531865ba
|
File details
Details for the file nifty_anilist-0.1.1-py3-none-any.whl.
File metadata
- Download URL: nifty_anilist-0.1.1-py3-none-any.whl
- Upload date:
- Size: 32.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bec555159bc74578eb748b253863a0498ed9cc237a4881921c3b34c744e763a6
|
|
| MD5 |
f10b86ba9bdbf7fc1f3eddc18f69f1a9
|
|
| BLAKE2b-256 |
06f0facc526d2622d17875d8a15fefbfd938c59554b25d7756e497be40961d0f
|