Ory Hydra Python Client SDK
raw JSON → 25.4.0 verified Mon Apr 27 auth: no python
Python client for the Ory Hydra API, providing programmatic access to OAuth 2.0 and OpenID Connect functionality. Auto-generated from the official OpenAPI spec. Version 25.4.0 released 2025-04-27. Active development but versioning is tied to Hydra itself, not SDK maturity.
pip install ory-hydra-client Common errors
error ImportError: cannot import name 'OryHydraApiClient' from 'ory_hydra_client' ↓
cause Ory SDK is auto-generated: the main client class is named differently (e.g., `HydraAdminApi` or `ApiClient`). Package structure varies by version.
fix
Use
from ory_hydra_client.api_client import ApiClient or check actual class names via help(ory_hydra_client). error AttributeError: module 'ory_hydra_client' has no attribute 'Configuration' ↓
cause Configuration class is in its own submodule, not directly in the package root.
fix
from ory_hydra_client.configuration import Configuration error TypeError: list() got an unexpected keyword argument 'page_size' ↓
cause Method `list_o_auth2_clients()` does not accept `page_size`; pagination parameters differ between versions.
fix
Check method signature:
list_o_auth2_clients(limit=100, offset=0). Warnings
breaking Version 25.4.0 matches Hydra release version, not SDK stability. Breaking changes may occur between minor versions (e.g., 25.3.x -> 25.4.0). Pin exact version in production. ↓
fix pip freeze | grep ory-hydra-client && add `ory-hydra-client==25.4.0` to requirements.txt
gotcha Auto-generated SDK; method names are verbatim from OpenAPI spec (e.g., `list_o_auth2_clients` with underscores). Always check generated docs for exact method signatures. ↓
fix Use IDE autocomplete or browse https://github.com/ory/sdk/tree/master/clients/hydra/python
deprecated OAuth2 token introspection/revocation endpoints are deprecated in Hydra 2.x+ in favor of Ory OAuth2 Access Control (Ory Oathkeeper or Ory Keto). Future SDK versions may remove these methods. ↓
fix Migrate to Ory Oathkeeper for token validation; see https://www.ory.sh/docs/hydra/deprecation
gotcha Environment variable `HYDRA_ADMIN_URL` must NOT include a trailing slash. The SDK appends paths directly. ↓
fix Set HYDRA_ADMIN_URL=http://localhost:4445 (no slash at end)
Imports
- OryHydraApiClient wrong
import hydracorrectfrom ory_hydra_client import OryHydraApiClient - Configuration wrong
from hydra_client import Configurationcorrectfrom ory_hydra_client.configuration import Configuration
Quickstart
from ory_hydra_client import OryHydraApiClient
from ory_hydra_client.configuration import Configuration
config = Configuration(host=os.environ.get('HYDRA_ADMIN_URL', 'http://localhost:4445'))
config.api_key['bearer'] = os.environ.get('HYDRA_API_KEY', '')
api_client = OryHydraApiClient(configuration=config)
api_instance = api_client.admin_api
# Example: list OAuth2 clients
try:
clients = api_instance.list_o_auth2_clients()
print(clients)
except Exception as e:
print(f"Error: {e}")