Async API wrapper for hakush.in written in Python.
Project description
hakushin-py
An async API wrapper for Hakushin written in Python. Hakushin is a website that display Genshin Impact and Honkai: Star Rail game data, including the beta ones.
Note: I am not the developer of Hakushin.
Quick Links
Developing something for Hoyoverse games? Here's a collection of Python async API wrappers for Hoyoverse games made by me:
- enka.py is an Enka Network API wrapper for fetching in-game showcase.
- yatta.py is a Project Yatta API wrapper for fetching Honkai Star Rail game data.
- ambr.py is a Project Ambr API wrapper for fetching Genshin Impact game data.
- hakushin.py is a Hakushin API wrapper for fetching Genshin Impact and Honkai Star Rail beta game data.
Features
- Fully typed.
- Provides direct icon URLs.
- Fully asynchronous by using
aiosqlite
,aiohttp
, andasyncio
. - Supports persistent caching using SQLite.
- Supports Pydantic V2.
- Supports both Genshin Impact and Honkai: Star Rail.
- 100% test coverage.
[!IMPORTANT]
This wrapper is mainly focused on fetching beta game data, this mean that it does not cover all the endpoints of the Hakushin API and models do not cover all the fields from the API's response.
Installing
# poetry
poetry add git+https://github.com/seriaati/hakushin-py
# pip
pip install git+https://github.com/seriaati/hakushin-py
Quick Example
import hakushin
import asyncio
async def main() -> None:
async with hakushin.HakushinAPI() as client:
await client.fetch_character(10000095, hakushin.Game.GI)
await client.fetch_character(1309, hakushin.Game.HSR)
asyncio.run(main())
Usage
Starting and closing the client properly
To use the client properly, you can either:
Manually call start()
and close()
import hakushin
import asyncio
async def main() -> None:
api = hakushin.HakushinAPI()
await api.start()
await api.fetch_new(hakushin.Game.GI)
await api.close()
asyncio.run(main())
Or use the async with
syntax:
import hakushin
import asyncio
async def main() -> None:
async with hakushin.HakushinAPI() as api:
await api.fetch_new(hakushin.Game.GI)
asyncio.run(main())
[!IMPORTANT]
You need to callstart()
or the api client will not function properly; theclose()
method closes the request session and database properly.
Finding models' attributes
If you're using an IDE like VSCode or Pycharm, then you can see all the attributes and methods the model has in the autocomplete.
[!TIP] If you're using VSCode,
alt
+left click
on the attribute, then the IDE will bring you to the source code of this wrapper for you to see all the fields defined, most classes and methods have docstrings for you to reference to.
Catching exceptions
If data is not found (API returns 404), then hakushin.errors.NotFoundError
will be raised.
Questions, issues, contributions
For questions, you can contact me on Discord or open an issue.
To report issues with this wrapper, open an issue.
To contribute, fork this repo and submit a pull request.
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
File details
Details for the file hakushin_py-0.1.0.tar.gz
.
File metadata
- Download URL: hakushin_py-0.1.0.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.11 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 400ab9a434b3de5886285750f8e5eb0a7833f9c9d82434da99e4bbb511727be6 |
|
MD5 | af07e1ad058019d614bc3c10a98d09f7 |
|
BLAKE2b-256 | 9d8f5b8960be9d091c536e8115ec643222f4c4615ff1209215bd64b8d510ea7d |
File details
Details for the file hakushin_py-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: hakushin_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.11 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b37f77f78841b51d033e46f0664759be63219c1b39fc20da01cc537e3811324 |
|
MD5 | d839b7a0ebd996d4e762c3c1d48c0435 |
|
BLAKE2b-256 | 5d95683fcf26152ab8c39419ec02ae1ca21091d7fafd95b20af0adddeae9525c |