python-keycloak
python-keycloak is a Python package providing access to the Keycloak API.
What it is and what it does
python-keycloak is a Python client library for Keycloak, an open-source identity and access management platform. It exposes two main interfaces: KeycloakOpenID for OpenID Connect authentication workflows (token acquisition, user info retrieval, logout) and KeycloakAdmin for server-side administrative tasks (user creation, role management). The library wraps HTTP calls to Keycloak's REST API using requests and httpx, with support for both synchronous and asynchronous operations.
The package is designed for applications that need to integrate Keycloak for authentication or for administrators who want to automate user and realm management. It requires a Keycloak server to be running and supports the five most recent major versions, allowing teams to upgrade gradually. Dependencies include httpx, requests, requests-toolbelt for HTTP operations, jwcrypto for token handling, deprecation for API lifecycle management, and aiofiles for async file operations.
Use it for:
- Integrate Keycloak OpenID Connect authentication into a Python web application for user login and token management.
- Automate user provisioning and role assignment in Keycloak from a Python backend service.
- Build a Python CLI tool to manage Keycloak realms, clients, and users without manual admin console access.
- Implement token refresh and logout flows in a Python API gateway or middleware.
- Exchange tokens between different Keycloak clients for service-to-service authentication.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides Python bindings to the Keycloak API, supporting both OpenID Connect authentication flows and administrative operations on Keycloak servers.
Yes. The package is actively maintained, has low install friction, carries a permissive MIT license, and is widely used (top 5000 on PyPI). It directly solves Keycloak integration for Python applications. The 'Alpha' classifier is a minor concern given active development and no known vulnerabilities, but verify production readiness for your use case before committing to a critical auth path.
Install
python-keycloak on PyPI
pip
pip install python-keycloakuv
uv add python-keycloakpoetry
poetry add python-keycloakInstalling python-keycloak
Before you install
Low friction install with six runtime dependencies. Actively maintained with a recent release; supports current Python versions (3.10–3.14) and tracks the latest five major Keycloak versions.
License in practice
MIT license permits commercial and private use with minimal restrictions; suitable for most projects.
Quickstart
pip install python-keycloak
from keycloak import KeycloakOpenID
keycloak_openid = KeycloakOpenID(
server_url="http://localhost:8080/auth/",
client_id="example_client",
realm_name="example_realm",
client_secret_key="secret"
)
token = keycloak_openid.token("user", "password")
Requires a running Keycloak server instance; supports Keycloak versions 22.X through 26.X.
Verify before relying
- Whether async support via aiofiles is fully integrated or only partially available.
- Current stability beyond 'Alpha' classification—whether the library is production-ready despite active maintenance.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — aiofiles, deprecation, httpx, jwcrypto, requests, requests-toolbelt |
| Maintenance | actively maintained — 180 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 7,856,130/month — #1,687 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: python_keycloak-7.1.1-py3-none-any.whl
Keywords: keycloak, openid, oidc
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
fastapi-keycloak-middlewareFastAPI middleware that integrates Keycloak for…
unclear · top 15,000 on PyPI
pyopImplements an OpenID Connect Provider (OP)…
permissive · top 15,000 on PyPI
apache-airflow-providers-keycloakIntegrates Keycloak identity and access…
permissive · top 15,000 on PyPI
django-oidc-providerProvides OpenID Connect and OAuth 2.0 server…
permissive · top 15,000 on PyPI
pulumi-keycloakA Pulumi resource provider that lets you define…
permissive · top 15,000 on PyPI
flask-oidcAdds OpenID Connect authentication support to…
permissive · top 5,000 on PyPI
oidc-provider-mockA mock OpenID Connect provider server that runs…
permissive · top 15,000 on PyPI
oauth2-clientHandles OAuth2 authentication flows…
unclear · top 15,000 on PyPI
AuthlibAuthlib provides a complete implementation of…
permissive · top 1,000 on PyPI
mozilla-django-oidcIntegrates Django applications with OpenID…
copyleft · top 5,000 on PyPI