skillfed

python-keycloak

python-keycloak is a Python package providing access to the Keycloak API.

python-keycloak v7.1.1 7.9M downloads/30d#1,687 on PyPI881
Permissive license MIT Active released

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-keycloak

uv

uv add python-keycloak

poetry

poetry add python-keycloak

Installing 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

Development Status :: 3 - AlphaLicense :: OSI Approved :: MIT LicenseOperating System :: MacOSOperating System :: Microsoft :: WindowsOperating System :: UnixProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Utilities

Tags

keycloak python clientopenid connect authenticationkeycloak admin apioidc python libraryidentity provider integration
authenticationidentity-managementopenid-connect

More Utilities packages