Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-3181] Asyncio Support #312

Merged
merged 15 commits into from
May 4, 2022
Merged

[SDK-3181] Asyncio Support #312

merged 15 commits into from
May 4, 2022

Conversation

adamjmcgrath
Copy link
Contributor

@adamjmcgrath adamjmcgrath commented Apr 4, 2022

For Python >=v3.6 with aiohttp installed, new asynchronous methods will be available using the _async suffix, eg

import asyncio
from auth0.v3 import asyncify
from auth0.v3.management import Auth0, Users, Connections
from auth0.v3.authentication import Users

domain = 'myaccount.auth0.com'
mgmt_api_token = 'MGMT_API_TOKEN'

auth0 = Auth0(domain, mgmt_api_token)

async def main():
  # u = auth0.users.all() <= sync
  u = await auth0.users.all_async() # <= async

 # To share a session amongst multiple calls to the same service
 async with auth0.users as users:
    data = await users.get_async(id)
    users.update_async(id, data)

  # Use asyncify directly on services and share session
  Users = asyncify(Users)
  Connections = asyncify(Connections)
  session = aiohttp.ClientSession()
  users = Users(domain, mgmt_api_token)
  connections = Connections(domain, mgmt_api_token)
  users.set_session(session)
  connections.set_session(session) 
  u = await auth0.users.all_async()
  c = await auth0.connections.all_async()
  session.close()

  # Use auth api
  U = asyncify(Users)
  u = U(domain=domain)
  await u.userinfo_async(access_token)

asyncio.run(main())

fixes #304

TODO:

  • auth client
  • share session across services (users, clients, etc)

@adamjmcgrath adamjmcgrath added the review:medium Medium review label Apr 4, 2022
auth0/v3/utils.py Outdated Show resolved Hide resolved
@adamjmcgrath adamjmcgrath marked this pull request as ready for review May 3, 2022 17:26
@adamjmcgrath adamjmcgrath requested a review from a team as a code owner May 3, 2022 17:26
@adamjmcgrath adamjmcgrath merged commit f39dff0 into master May 4, 2022
@adamjmcgrath adamjmcgrath deleted the asyncio branch May 4, 2022 16:50
@adamjmcgrath adamjmcgrath changed the title [SDK-3181] Asyncio Support (WIP) [SDK-3181] Asyncio Support May 4, 2022
@adamjmcgrath adamjmcgrath mentioned this pull request May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review:medium Medium review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AsyncIO support
2 participants