Typed client library for the authentication routes exposed by py-oidc-auth.
py-oidc-auth-client is the counterpart of the server-side library py-oidc-auth.
While py-oidc-auth helps you add OpenID Connect login, token, and device endpoints to web frameworks, py-oidc-auth-client consumes those routes and gives you ready-to-use bearer tokens for calling protected APIs.
Features
- One high level helper:
authenticate() TokenStoreas a first-class, host-aware token persistence layer- Device flow for headless sessions
- Authorization code flow for interactive logins
- Token caching and refresh token support
- Fully typed public API
Install
python -m pip install py-oidc-auth-client
Import name is py_oidc_auth_client:
from py_oidc_auth_client import authenticate
Relationship to py-oidc-auth
A typical py-oidc-auth server exposes endpoints similar to:
GET /auth/v2/loginGET /auth/v2/callbackPOST /auth/v2/tokenPOST /auth/v2/deviceGET /auth/v2/logoutGET /auth/v2/userinfo
This client calls the relevant routes (token and device, and possibly login/callback) and returns a Token
object that contains a ready-made Authorization header.
Quick start
from py_oidc_auth_client import authenticate
token = authenticate(host="https://auth.example.org")
# Use with any HTTP client
headers = token["headers"]
print(headers["Authorization"])
Use with httpx
import httpx
from py_oidc_auth_client import authenticate
token = authenticate(host="https://auth.example.org")
with httpx.Client() as client:
r = client.get("https://service.example.org/protected", headers=token["headers"])
r.raise_for_status()
print(r.json())
TokenStore
TokenStore is the storage layer that keeps authentication state available between runs.
It is one of the main building blocks of the library, alongside authenticate(),
CodeFlow, and DeviceFlow.
TokenStore separates tokens by host internally. That means a single token database file
is usually enough for one application, even if it talks to multiple auth servers.
Use separate store files when you want isolation between applications or environments,
not simply because the host changes.
Use it when you want to:
- choose a predictable token location
- separate tokens per application or environment
- support refresh-token based reuse in batch, remote, or repeated runs
- reuse one host-aware token store across multiple auth servers
from py_oidc_auth_client import TokenStore, authenticate
store = TokenStore(path="~/.cache/py-oidc-auth-client/my-app.json")
token = authenticate(
host="https://auth.example.org",
store=store,
)
Choosing the right entry point
Use these building blocks as a rule of thumb:
- start with
authenticate() - add an explicit
TokenStorewhen token persistence matters; one store usually covers multiple hosts - use
CodeFlowdirectly for browser-based interactive login control - use
DeviceFlowdirectly for headless or remote sessions
For many applications, the best default is authenticate() together with an explicit
TokenStore, typically one store per application or environment.
Interactive and non-interactive environments
The client tries to select a suitable strategy:
- Use a valid cached access token.
- Refresh using the refresh token.
- If interactive authentication is possible, fall back to an interactive login.
- If running in a non-interactive session without a usable token, raise an error telling you how to provide a token file.
For headless sessions, the device flow is the recommended approach. In those environments,
TokenStore is especially important because it lets later runs reuse persisted auth state.
Advanced usage
If you need more control than authenticate(), use the flow helpers from py_oidc_auth_client.auth.
Device flow
import asyncio
from py_oidc_auth_client import Config, DeviceFlow
async def main() -> None:
cfg = Config(host="https://auth.example.org")
flow = DeviceFlow(config=cfg, token=None, timeout=600)
device = await flow.get_device_code()
print("Open:", device.uri)
print("Code:", device.user_code)
token = await flow.poll(device["device_code"], int(device["interval"]))
print(token["headers"])
asyncio.run(main())
Authorization code flow
import asyncio
from py_oidc_auth_client import Config, CodeFlow
async def main() -> None:
cfg = Config(host="https://auth.example.org")
flow = CodeFlow(config=cfg, token=None, timeout=120)
token = await flow.authenticate()
print(token["headers"])
asyncio.run(main())
Stable public API
The main public building blocks are:
authenticateauthenticate_asyncTokenStoreCodeFlowDeviceFlowConfigTokenAuthError
Docs hub
The documentation is organised around a few task-oriented entry points:
- Overview
- Quickstart
- TokenStore
- Choosing an authentication strategy
- Non-interactive environments
- Configuration
- Recipes
- Stable public API
Contributing
Contributions are welcome. Please open an issue to discuss larger changes before submitting a pull request.
Metadata
Release files for py-oidc-auth-client 2603.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| py_oidc_auth_client-2603.0.1.tar.gz | 114.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py_oidc_auth_client-2603.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 140.1 kB
Release files / py_oidc_auth_client-2603.0.1.tar.gz
| Download URL | py_oidc_auth_client-2603.0.1.tar.gz |
|---|---|
| Size | 114.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85971187e8ca268e402a27d27d6c02f44f74a8765e68c54b6dafa3dbca7ea97a
|
|
BLAKE2b-256 checksum How to use checksums |
ddfbaca58df456a4eae0f97235b7666d79c3d341fe2793253320e3782f7ff306
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / py_oidc_auth_client-2603.0.1-py3-none-any.whl
| Download URL | py_oidc_auth_client-2603.0.1-py3-none-any.whl |
|---|---|
| Size | 26.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f67f91ac31d50540968469f1fb6a997e0eb46cd806dca5a1f54cf027b4b91d63
|
|
BLAKE2b-256 checksum How to use checksums |
a0a12299093f91e458750009d8bfd731376367a5d9e6ebe5672a3d6ecfc1e30f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for py-oidc-auth-client 2603.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.