Giter Club home page Giter Club logo

bungio's Introduction

BungIO Logo

BungIO


BungIO is a modern and pythonic wrapper for Bungies Destiny 2 API.

  • Python 3.10+
  • Asynchronous
  • 100% typed and raw api coverage
  • Ratelimit compliant
  • Manifest support
  • OAuth2 support
  • Easily used in combination with other libraries like FastApi

Click here to get started or visit the guides or api reference.

Basic Example

import asyncio
import os

from bungio import Client
from bungio.models import BungieMembershipType, DestinyActivityModeType, DestinyUser


# create the client obj with our bungie authentication
client = Client(
    bungie_client_id=os.getenv("bungie_client_id"),
    bungie_client_secret=os.getenv("bungie_client_secret"),
    bungie_token=os.getenv("bungie_token"),
)

async def main():
    # create a user obj using a known bungie id
    user = DestinyUser(membership_id=4611686018467765462, membership_type=BungieMembershipType.TIGER_STEAM)

    # iterate thought the raids that user has played
    async for activity in user.yield_activity_history(mode=DestinyActivityModeType.RAID):

        # print the date of the activity
        print(activity.period)

# bungio is by nature asynchronous, it can only be run in an asynchronous context
asyncio.run(main())

bungio's People

Contributors

kigstn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bungio's Issues

FastAPI Swagger UI Authentication

Hello @Kigstn,
I am using FastAPI and attempting to take advantage of the Swagger Doc UI to authenticate with bungie while developing my app. I know this is out of scope, but when you used FastAPI as an example, I thought you might have solved my issue.

from fastapi.security import OAuth2AuthorizationCodeBearer

bungie_secrets = dotenv_values(".env.secret")

client = MyClient(
    bungie_client_id=bungie_secrets.get("client_id"),
    bungie_client_secret=bungie_secrets.get("client_secret"),
    bungie_token=bungie_secrets.get("token"),
)

authentication = OAuth2AuthorizationCodeBearer(
    authorizationUrl=client.get_auth_url(state=secrets.token_urlsafe(20)),
    tokenUrl="https://www.bungie.net/platform/app/oauth/token/",
)

app: FastAPI = FastAPI(
    swagger_ui_init_oauth={
        "clientId": bungie_secrets.get("client_id"),
        "clientSecret": bungie_secrets.get("client_secret"),
    },
)

# call this from your website
@app.get("/auth/")
async def authenticate(state: str, code: str, token: str = Security(authentication)):
    """Receive information from bungie authentication"""

    # generate an access token with the code
    # this will call `Client.on_token_update` we defined above
    auth = await client.generate_auth(code=code)

    return {"membership_id": auth.membership_id}

In the Swagger Docs, I was able to get the authenticate button to initiate the oauth flow with bungie. Unfortunately, when it gets redirected back to my page I am getting a 401 error with {"detail":"Not authenticated"}

image,

Bungie only likes https so ive been tunneling my app via ngrok http 8000, and put the redirect url to the auto generated ngrok endpoint.

Do you have any advice on what my problem is and how to take better advantage of FastAPI's Swagger docs? I think this would be a good additional documentation for the auth example.

Edit: Further details about using NGROK

Simple Test from Example Code

Based on the simple example code getting the following error:

clientUser.py", line 20, in test
async for activity in user.yield_activity_history(mode=DestinyActivityModeType.RAID):
File "C:\Program Files\Python311\Lib\site-packages\bungio\models\mixins\user.py", line 77, in yield_activity_history
data = await self.get_historical_stats_for_account(groups=[0], auth=auth)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\site-packages\bungio\models\mixins\user.py", line 504, in get_historical_stats_for_account
return await self._client.api.get_historical_stats_for_account(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\site-packages\bungio\api\bungie\destiny2.py", line 1015, in get_historical_stats_for_account
response = await self._client.http.get_historical_stats_for_account(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\site-packages\bungio\http\routes\destiny2.py", line 1404, in get_historical_stats_for_account
return await self.request(
^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\site-packages\bungio\http\client.py", line 108, in request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\site-packages\bungio\http\client.py", line 163, in _request
async with self.session.request(
File "C:\Program Files\Python311\Lib\site-packages\aiohttp\client.py", line 1141, in aenter
self._resp = await self._coro
^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\site-packages\aiohttp\client.py", line 558, in _request
resp = await req.send(conn)
^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\site-packages\aiohttp\client_reqrep.py", line 670, in send
await writer.write_headers(status_line, self.headers)
File "C:\Program Files\Python311\Lib\site-packages\aiohttp\http_writer.py", line 130, in write_headers
buf = _serialize_headers(status_line, headers)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "aiohttp_http_writer.pyx", line 132, in aiohttp._http_writer._serialize_headers
File "aiohttp_http_writer.pyx", line 109, in aiohttp._http_writer.to_str
TypeError: Cannot serialize non-str key None

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.