A statically typed API wrapper for the Bungie's REST API written in Python3 and Asyncio.
PyPI stable release.
$ pip install aiobungie
Development
$ pip install git+https://github.com/nxtlo/aiobungie@master
See Examples for advance usage.
import aiobungie
client = aiobungie.Client('YOUR_API_KEY')
async def main() -> None:
# fetch a clan
clan = await client.fetch_clan("Nuanceㅤ")
# Fetch the clan members.
members = await clan.fetch_members()
# Filter the results to return only steam members from the clan.
for member in members.filter(lambda m: m.type is aiobungie.MembershipType.STEAM):
# Get the profile for this clan member.
profile = await member.fetch_self_profile(
components=[aiobungie.ComponentType.CHARACTERS]
)
print(profile.characters)
# You can either run it using the client or just `asyncio.run(main())`
client.run(main())
Alternatively, You can use RESTClient
which's designed to only make HTTP requests and return JSON objects.
import aiobungie
import asyncio
async def main(access_token: str) -> None:
# Single REST client.
async with aiobungie.RESTClient("TOKEN") as rest_client:
response = await rest_client.fetch_clan_members(4389205)
raw_members_payload = response['results']
for member in raw_members_payload:
print(member)
# Methods only exposed through the REST API.
await rest.refresh_access_token('a token')
asyncio.run(main("DB_ACCESS_TOKEN"))
A REST client pool allows you to acquire multiple RESTClient
instances that shares the same connection.
import aiobungie
import asyncio
pool = aiobungie.RESTPool("token")
async def func1() -> None:
async with pool.acquire() as instance:
tokens = await instance.fetch_oauth2_tokens('code')
pool.metadata['tokens'] = tokens
async def func2() -> None:
async with pool.acquire() as instance:
tokens = pool.metadata['tokens']
await instance.refresh_access_token(tokens.refresh_token)
async def main() -> None:
await asyncio.gather(func1(), func2())
asyncio.run(main())
- Python 3.9 or higher
- aiohttp
- attrs
Please read this manual
- Discord:
Fate 怒#0008
|350750086357057537
- Docs: Here.