Skip to main content

API wrapper for ambr.top written in Python

Project description

ambr

An async API wrapper for Project Amber written in Python. Project Ambr displays Genshin Impact game data on a beautiful website.

Note: I am not the developer of Project Amber.

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, and asyncio.
  • Supports persistent caching using SQLite.
  • Supports Pydantic V2.
  • Supports the majority of popular endpoints (create an issue if the one you need is missing).
  • 100% test coverage.

Installing

# poetry
poetry add git+https://github.com/seriaati/ambr

# pip
pip install git+https://github.com/seriaati/ambr

Quick Example

from ambr import AmbrAPI, Language

async with AmbrAPI(lang=Language.CHT) as api:
    characters = await api.fetch_characters()
    for character in characters:
        print(character.name)

    weapons = await api.fetch_weapons(use_cache=False)
    for weapon in weapons:
        print(weapon.id)

Usage

Starting and closing the client properly

To use the client properly, you can either:
Manually call start() and close()

import ambr
import asyncio

async def main() -> None:
    api = ambr.AmbrAPI()
    await api.start()
    response = await api.fetch_characters()
    await api.close()

asyncio.run(main())

Or use the async with syntax:

import ambr
import asyncio

async def main() -> None:
   async with ambr.AmbrAPI() as api:
     await api.fetch_characters()

asyncio.run(main())

[!IMPORTANT]
You need to call start() or the api client will not function properly; the close() method closes the request session and database properly.

Client parameters

Currently, the AmbrAPI class allows you to pass in 3 parameters:

Language

This will affect the languages of names of weapon, character, constellations, etc. You can find all the languages here.

Headers

Custom headers used when requesting the Amber API, it is recommended to set a user agent, the default is {"User-Agent": "ambr-py"}.

Cache TTL

Default is 3600 seconds (1 hour), the cache is evicted when this time expires. Note that setting a longer TTL might result in inconsistent data.

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 ambr.exceptions.DataNotFoundError 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ambr_py-1.7.3.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

ambr_py-1.7.3-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file ambr_py-1.7.3.tar.gz.

File metadata

  • Download URL: ambr_py-1.7.3.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.11 Windows/10

File hashes

Hashes for ambr_py-1.7.3.tar.gz
Algorithm Hash digest
SHA256 800015014e9927e90f06836e37b0ccb1ab25396a0ca756c4f979650dceb3986e
MD5 d7f7e691b8ecfe93081c3726015ad021
BLAKE2b-256 b1198980294a7b17852db72677ab014ed7cd1015b41c1ce2e17d4ab97407f754

See more details on using hashes here.

File details

Details for the file ambr_py-1.7.3-py3-none-any.whl.

File metadata

  • Download URL: ambr_py-1.7.3-py3-none-any.whl
  • Upload date:
  • Size: 36.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.11 Windows/10

File hashes

Hashes for ambr_py-1.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2b13bd364e9539c066b18d183cebf57ea2778ca445386fcf9a5457f15531d107
MD5 65c21ecb778ff12cc3a266182e9a7aca
BLAKE2b-256 954e31db8bc5057a6a6446882dc9bf3bcbcbcfc3872138b7b4fe68470ea37a97

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page