Typing stubs for auth0-python
This is a type stub package for the `auth0-python` library, providing static type annotations that can be used by type checkers like MyPy or Pyright. It helps ensure type safety and improves IDE autocompletion for code interacting with the Auth0 Python SDK. This version of `types-auth0-python` aims to provide accurate annotations for `auth0-python==4.10.*`. It is part of the typeshed project, which releases frequently (often several times a month) to keep up with runtime library changes.
Common errors
-
ImportError: cannot import name 'Auth0' from 'auth0.management'
cause The `Auth0` class was removed/renamed in `auth0-python` v5.0.0.fixChange the import to `from auth0.management import ManagementClient` and update the client instantiation accordingly. -
AttributeError: 'dict' object has no attribute 'user_id' (or similar for Pydantic model methods)
cause In `auth0-python` v5.0.0, many API responses are now Pydantic models instead of plain dictionaries, particularly for Management API calls.fixAccess attributes directly (e.g., `user.user_id`) or convert the Pydantic model to a dictionary using `.model_dump()` (e.g., `user.model_dump().get('user_id')`) if dictionary-like access is desired. -
error: Library "auth0-python" has no attribute "management" (or similar type checker error)
cause Your type checker might be using an outdated stub version or `types-auth0-python` is not correctly installed/recognized for your `auth0-python` version.fixEnsure `types-auth0-python` is installed and its version is compatible with your `auth0-python` version. Run your type checker with verbose output to confirm which stubs are being used. You may need to update `auth0-python` or `types-auth0-python`.
Warnings
- breaking The `auth0-python` library underwent a major rewrite in v5.0.0, introducing significant breaking changes. This includes changes to import paths (e.g., `from auth0.management import Auth0` is now `from auth0.management import ManagementClient`), client initialization, and response types (now Pydantic models instead of generic dictionaries).
- gotcha Mismatching versions of `types-auth0-python` and `auth0-python` can lead to incorrect type checking or errors. The stub package aims to provide accurate annotations for specific `auth0-python` versions (e.g., `4.10.*`).
- breaking `auth0-python` has increased its minimum Python version requirement. For example, v5 requires Python >=3.9, and v5.2.0 dropped support for Python 3.8. Using older Python versions with newer `auth0-python` (and thus `types-auth0-python`) can cause runtime errors or `SyntaxError` with type hints.
Install
-
pip install types-auth0-python
Imports
- ManagementClient
from auth0.v3.management import Auth0
from auth0.management import ManagementClient
- GetToken
from auth0.authentication import GetToken
- TokenVerifier
from auth0.authentication.token_verifier import TokenVerifier
- ApiError
from auth0.exceptions import Auth0Error
from auth0.management.errors import ApiError
Quickstart
import os
from auth0.management import ManagementClient
from auth0.management.users import Users
from typing import Dict, Any
# Ensure environment variables are set for actual use
AUTH0_DOMAIN: str = os.environ.get('AUTH0_DOMAIN', 'your-tenant.auth0.com')
AUTH0_CLIENT_ID: str = os.environ.get('AUTH0_CLIENT_ID', 'YOUR_CLIENT_ID')
AUTH0_CLIENT_SECRET: str = os.environ.get('AUTH0_CLIENT_SECRET', 'YOUR_CLIENT_SECRET')
# Initialize the ManagementClient with client credentials for automatic token management
# This client is fully type-hinted by types-auth0-python
management_client: ManagementClient = ManagementClient(
domain=AUTH0_DOMAIN,
client_id=AUTH0_CLIENT_ID,
client_secret=AUTH0_CLIENT_SECRET
)
# Access a sub-client, e.g., for users management
users_client: Users = management_client.users
# Example: List users (response types are Pydantic models in v5, but can be dicts too)
try:
# Use .all() for pagination convenience or .get_all() if you need more control
all_users: list[Dict[str, Any]] = users_client.get_all()
print(f"Found {len(all_users)} users.")
if all_users:
print(f"First user ID: {all_users[0].get('user_id')}")
except Exception as e:
print(f"An error occurred: {e}")