Registry / auth-security / h2o-authn

h2o-authn

JSON →
library3.1.0pypypi✓ verified 82d ago

h2o-authn provides authentication helpers for H2O.ai Python clients, simplifying secure interactions with H2O AI Cloud and other services. It primarily focuses on managing and refreshing access tokens using various authentication flows, such as Client Credentials. The current version is 3.1.0, and the library maintains an active development pace with several releases per year.

pip install h2o-authn
INSTALL
IMPORT
SIG · H2O-AUTHN
H
h2o-authn
auth-securitypythonv3.1.0
Install
2.2s avg
Import
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 22.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.2s · import 0.000s · 23MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TokenProvider
from h2o_authn import TokenProvider
from h2o_authn import ClientCredentialsTokenProvider
AsyncTokenProvider
from h2o_authn import AsyncTokenProvider
error
from h2o_authn import error

This quickstart demonstrates how to use `h2o-authn` to obtain an access token using the Client Credentials flow. It fetches authentication details from environment variables (H2O_AUTHN_URI, H2O_AUTHN_CLIENT_ID, H2O_AUTHN_CLIENT_SECRET), initializes a `ClientCredentialsTokenProvider` with an `httpx.AsyncClient`, and then retrieves a token. It also shows wrapping the provider with `AuthCache` for automatic token caching and refreshing.

import os import httpx import asyncio from h2o_authn import ClientCredentialsTokenProvider, AuthCache async def authenticate_and_get_token(): auth_url = os.environ.get("H2O_AUTHN_URI", "") client_id = os.environ.get("H2O_AUTHN_CLIENT_ID", "") client_secret = os.environ.get("H2O_AUTHN_CLIENT_SECRET", "") if not all([auth_url, client_id, client_secret]): print("Please set H2O_AUTHN_URI, H2O_AUTHN_CLIENT_ID, and H2O_AUTHN_CLIENT_SECRET environment variables.") return async with httpx.AsyncClient() as client: token_provider = ClientCredentialsTokenProvider( auth_url=auth_url, client_id=client_id, client_secret=client_secret, client=client, ) # Optional: Wrap with AuthCache for token caching and refresh cached_token_provider = AuthCache(token_provider) try: token = await cached_token_provider.get_token() print(f"Successfully obtained token. Access Token (first 10 chars): {token.access_token[:10]}...") print(f"Token expires in: {token.expires_in} seconds") except Exception as e: print(f"Authentication failed: {e}") if __name__ == "__main__": asyncio.run(authenticate_and_get_token())
Debug
Known issues
breakingPython 3.8 is no longer officially supported as of version 3.0.0. Projects using `h2o-authn` 3.x or later must run on Python 3.9 or newer.
fix
Upgrade your Python environment to 3.9 or newer, or pin `h2o-authn<3.0.0` if you must remain on Python 3.8.
affects: >=3.0.0
breakingThe minimum required version of the `httpx` library was updated to `0.23.0` in `h2o-authn` v3.0.0. Older versions of `httpx` may cause dependency conflicts or runtime errors.
fix
Ensure `httpx>=0.23.0` is installed in your environment. If other dependencies require an older `httpx` version, you may face conflicts requiring careful dependency management or pinning `h2o-authn<3.0.0`.
affects: >=3.0.0
deprecatedPython 3.7 support was dropped in `h2o-authn` v2.0.0. Using this library with Python 3.7 is no longer supported and may lead to installation failures or unexpected behavior.
fix
Upgrade your Python environment to 3.8 or newer. For `h2o-authn>=3.0.0`, Python 3.9+ is required.
affects: >=2.0.0
gotchaThe library heavily relies on environment variables (`H2O_AUTHN_URI`, `H2O_AUTHN_CLIENT_ID`, `H2O_AUTHN_CLIENT_SECRET`) for configuration. Missing or incorrectly set variables will lead to `RuntimeError` or `TokenEndpointError` at runtime.
fix
Always ensure the necessary environment variables are set correctly before running applications that use `h2o-authn`. Use `os.environ.get('VAR', '')` for safer access in code.
affects: all
Upgrade
Version history
3.1.0latest on PyPI · released Apr 28, 2025
Audit
Dependencies
httpxrequiredRequired for HTTP requests to authentication endpoints.
typing_extensionsrequiredRequired for Python versions < 3.10 for backport of typing features.
h2o-cloud-discoveryoptionalOptional dependency for using token providers created from discovery objects.
Agent activity
25 hits · last 30 days
node
24
OpenAI (training)
1
Resources
h2o-authn — pip install h2o-authn · libregistry