Skip to main content

A small async api wrapper for the bungie api

Project description

aiobungie

An asynchronous statically typed API wrapper for the Bungie API written in Python.

Installing

IT IS recommended to use the latest pre-release from master since 0.2.4 is missing features from 0.2.5.

PyPI stable release. Not Recommended Currently.

$ pip install aiobungie

From master Recommended Currently.

$ pip install git+https://github.com/nxtlo/aiobungie

Quick Example

See Examples for more.

import aiobungie
from aiobungie import crate

# crates in aiobungie are implementations
# of Bungie's objects to provide
# more functionality.

client = aiobungie.Client('YOUR_API_KEY')

async def main() -> None:

    # fetch a clan
    clan: crate.Clan = await client.fetch_clan("Nuanceㅤ")
    print(clan.name, clan.id, clan.owner.name, clan.owner.id, ...)

    # fetch a member from the clan.
    member: crate.ClanMember = await clan.fetch_member("Fate怒")
    print(member.name, member.id, member.type, ...)

    # fetch the clan members and return only steam players
    members = await clan.fetch_members(aiobungie.MembershipType.STEAM)
    for member in members:
        if member.name == "Fate怒" or member.id == 4611686018484639825:
            print("Found Fate.")
        else:
            print(member.name, member.id, member.type)

    # fetch profiles.
    profile: crate.Profile = await client.fetch_profile(member.id, member.type)
    print(profile.name, profile.id, profile.type, ...)

    # You can fetch a character in two ways.
    # Whether from the player's profile or
    # using `fetch_character()` method.

    # The profile way.
    warlock: crate.Character = await profile.fetch_warlock()
    print(warlock.light, warlock.id, warlock.gender, warlock.race, ...)

    # the fetch_character() way using the profile attrs.
    character: crate.Character = await client.fetch_character(profile.id, profile.type, profile.warlock_id)
    print(character.light, character.id, character.gender, character.race, ...)

# You can either run it via the client or just `asyncio.run(main())`
client.run(main())

REST-Only client

For low-level and only to interact with the API directly without any high-level concepts, you can use the RESTClient.

Simple Example

import aiobungie
import asyncio

async def main(bearer: str) -> None:
    # Max retries is the maximum retries to backoff when you hit 5xx error codes.
    # It defaults to 4 retries.
    async with aiobungie.RESTClient("TOKEN", max_retries=5) as rest:
        fetch_player = await rest.fetch_player('Fate怒#4275')
        print(*fetch_player) # A JSON array of dict object
        for player in fetch_player: # Iterate through the array.
            print(player['membershipId'], player['iconPath']) # The player id and icon path.
            for k, v in player.items():
                print(k, v)

            # You can also send your own requests.
            await rest.static_request("POST", "Need/OAuth2", headers={"Auth": f"Bearer {bearer}"})
            # Defined methods.
            await rest.send_friend_request(bearer, member_id=1234)

asyncio.run(main("1234"))

Requirements

  • Python >=3.8 ,<=3.12
  • aiohttp
  • attrs.

Optional Requirements for speedups.

  • aiodns
  • cchardet
  • uvloop

Contributing

See the manual

Getting Help

  • Discord: Fate 怒#0008 | 350750086357057537
  • Docs: Here.

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

aiobungie-0.2.5b10.tar.gz (56.3 kB view hashes)

Uploaded Source

Built Distribution

aiobungie-0.2.5b10-py3-none-any.whl (83.9 kB view hashes)

Uploaded Python 3

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