nxtlo / aiobungie

Python and asyncio Bungie API wrapper.
https://nxtlo.github.io/aiobungie/
MIT License
52 stars 10 forks source link
aiobungie bungie-api bungie-destiny-api destiny2 hacktoberfest python3

aiobungie

A statically typed, asynchronous API wrapper that supports Bungie's REST API for Python 3.

Installing

Currently Python 3.10, 3.11, 3.12 and 3.13 are supported.

Latest Release using pip.

pip install aiobungie

Development via github master.

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

Quick Example

See Examples for advance usage

import aiobungie
import asyncio

client = aiobungie.Client('YOUR_API_KEY')

async def main() -> None:
    # Search for Destiny 2 players.
    async with client.rest:
        users = await client.search_users("Fate")
        for user in users:
            # Print all Destiny 2 memberships for this user.
            print(user.memberships)

asyncio.run(main())

RESTful clients

aiobungie also provides a stand-alone RESTClient / RESTPool which's what Client built on top of, These clients just provide a lower-level abstraction.

A key note is that any Client based user can access the RESTClient instance bound to it with .rest property.

Key features

Example

import aiobungie
import asyncio

# Single REST client connection.
client = aiobungie.RESTClient("YOUR_API_KEY")

async def main() -> None:
    async with client:
        # Download and open the JSON manifest.
        manifest = await client.download_json_manifest(name="latest_manifest")
        with manifest.open("r") as file:
            data = file.read()

        # OAuth2 API. 2 simple methods for fetching and refreshing tokens.
        tokens = await client.fetch_oauth2_tokens('code')
        refreshed_tokens = await client.refresh_access_token(tokens.refresh_token)

        # Testing your own requests.
        response = await client.static_request(
            "GET", # Method.
            "Destiny2/path/to/route", # Route.
            auth="optional_access_token", # If the method requires OAuth2.
            json={"some_key": "some_value"} # If you need to pass JSON data.
        )

asyncio.run(main())

Dependencies

Features

aiobungie features are extra dependencies that replaces the standard library with either faster/neater pkgs.

For installing the specified feature, type pip install aiobungie[feature-name]

Contributing

Please read this manual

Related Projects

If you have used aiobungie and want to show your work, Feel free to Open a PR including it.

Useful Resources

FaQ