A full reference for this library is available here.
Authentication API
The Authentication API is used for authentication flows such as obtaining tokens via client credentials, authorization codes, or resource owner password grants:
from auth0.authentication import GetToken
token_client = GetToken(
domain="your-tenant.auth0.com",
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
)
# Get an access token using client credentials
token_response = token_client.client_credentials(
audience="https://your-tenant.auth0.com/api/v2/"
)
access_token = token_response["access_token"]
Management API
Recommended: Using ManagementClient
The ManagementClient is the recommended way to interact with the Auth0 Management API. It provides a simpler interface using just your Auth0 domain, and supports automatic token management with client credentials:
from auth0.management import ManagementClient
# With an existing token
client = ManagementClient(
domain="your-tenant.auth0.com",
token="YOUR_TOKEN",
)
# Or with client credentials (automatic token acquisition and refresh)
client = ManagementClient(
domain="your-tenant.auth0.com",
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
)
You can obtain a token using the Authentication API and use it with the Management API client:
from auth0.authentication import GetToken
from auth0.management import Auth0
domain = "your-tenant.auth0.com"# Get a token using the Authentication API
token_client = GetToken(
domain=domain,
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
)
token_response = token_client.client_credentials(
audience=f"https://{domain}/api/v2/"
)
access_token = token_response["access_token"]
# Use the token with the Management API client
client = Auth0(
base_url=f"https://{domain}/api/v2",
token=access_token,
)
Using the Base Client
Alternatively, you can use the Auth0 client directly with a full base URL:
The SDK also exports an async client so that you can make non-blocking calls to our API. Note that if you are constructing an Async httpx client class to pass into this client, use httpx.AsyncClient() instead of httpx.Client() (e.g. for the httpx_client parameter of this client).
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
will be thrown.
from auth0.management.core.api_error import ApiError
try:
client.actions.create(...)
except ApiError as e:
print(e.status_code)
print(e.body)
Pagination
Paginated requests will return a SyncPager or AsyncPager, which can be used as generators for the underlying object.
from auth0.management import Auth0
client = Auth0(
base_url="https://YOUR_TENANT.auth0.com/api/v2",
token="YOUR_TOKEN",
)
response = client.actions.list(
trigger_id="post-login",
action_name="actionName",
deployed=True,
page=1,
per_page=1,
installed=True,
)
for item in response:
print(item)
# alternatively, you can paginate page-by-pagefor page in response.iter_pages():
print(page)
# You can also iterate through pages and access the typed response per page
pager = client.actions.list(...)
for page in pager.iter_pages():
print(page.response) # access the typed response for each pagefor item in page:
print(item)
Advanced
Access Raw Response Data
The SDK provides access to raw response data, including headers, through the .with_raw_response property.
The .with_raw_response property returns a "raw" client that can be used to access the .headers and .data attributes.
from auth0.management import Auth0
client = Auth0(
base_url="https://YOUR_TENANT.auth0.com/api/v2",
token="YOUR_TOKEN",
)
response = client.actions.with_raw_response.create(...)
print(response.headers) # access the response headersprint(response.data) # access the underlying object
pager = client.actions.list(...)
print(pager.response) # access the typed response for the first pagefor item in pager:
print(item) # access the underlying object(s)for page in pager.iter_pages():
print(page.response) # access the typed response for each pagefor item in page:
print(item) # access the underlying object(s)
Retries
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
retry limit (default: 2).
A request is deemed retryable when any of the following HTTP status codes is returned:
Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0
This project is licensed under the MIT license. See the LICENSE file for more info
Auth0 Python SDK - Management and Authentication APIs
We found that auth0-python demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Socket uncovered four malicious NuGet packages targeting ASP.NET apps, using a typosquatted dropper and localhost proxy to steal Identity data and backdoor apps.
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.