Skip to content

Commit 97952cb

Browse files
committed
add docs
1 parent ddede97 commit 97952cb

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

README.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,54 @@ When consuming methods from the API clients, the requests could fail for a numbe
316316
resets is exposed in the ``reset_at`` property. When the header is unset, this value will be ``-1``.
317317
- Network timeouts: Adjustable by passing a ``timeout`` argument to the client. See the `rate limit docs <https://auth0.com/docs/policies/rate-limits>`__ for details.
318318
319+
=========================
320+
Asynchronous Environments
321+
=========================
322+
323+
This SDK provides async methods built on top of `asyncio <https://docs.python.org/3/library/asyncio.html>`__. To make them available you must have Python >=3.6 and the `aiohttp <https://docs.aiohttp.org/en/stable/>`__ module installed.
324+
325+
Then additional methods with the ``_async`` suffix will be added to modules created by the ``management.Auth0`` class or to classes that are passed to the ``asyncify`` method. For example:
326+
327+
.. code-block:: python
328+
329+
import asyncio
330+
import aiohttp
331+
from auth0.v3 import asyncify
332+
from auth0.v3.management import Auth0, Users, Connections
333+
from auth0.v3.authentication import Users as AuthUsers
334+
335+
auth0 = Auth0('domain', 'mgmt_api_token')
336+
337+
async def main():
338+
# users = auth0.users.all() <= sync
339+
users = await auth0.users.all_async() # <= async
340+
341+
# To share a session amongst multiple calls to the same service
342+
async with auth0.users as users:
343+
data = await users.get_async(id)
344+
users.update_async(id, data)
345+
346+
# Use asyncify directly on services
347+
Users = asyncify(Users)
348+
Connections = asyncify(Connections)
349+
users = Users(domain, mgmt_api_token)
350+
connections = Connections(domain, mgmt_api_token)
351+
352+
# Create a session and share it among the services
353+
session = aiohttp.ClientSession()
354+
users.set_session(session)
355+
connections.set_session(session)
356+
u = await auth0.users.all_async()
357+
c = await auth0.connections.all_async()
358+
session.close()
359+
360+
# Use auth api
361+
U = asyncify(AuthUsers)
362+
u = U(domain=domain)
363+
await u.userinfo_async(access_token)
364+
365+
366+
asyncio.run(main())
319367
320368
==============
321369
Supported APIs

auth0/v3/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from .asyncify import asyncify
12
from .exceptions import Auth0Error, RateLimitError, TokenValidationError
23

3-
__all__ = ("Auth0Error", "RateLimitError", "TokenValidationError")
4+
__all__ = ("Auth0Error", "RateLimitError", "TokenValidationError", "asyncify")

auth0/v3/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ def is_async_available():
77
import asyncio
88

99
import aiohttp
10-
import async_timeout
1110

1211
return True
1312
except ImportError:

0 commit comments

Comments
 (0)