python-keycloak 5.8.1


pip install python-keycloak

  Latest version

Released: Aug 19, 2025


Meta
Author: Marcos Pereira
Requires Python: >=3.9,<4.0

Classifiers

Development Status
  • 3 - Alpha

License
  • OSI Approved :: MIT License

Operating System
  • MacOS
  • Microsoft :: Windows
  • Unix

Programming Language
  • Python :: 3
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13

Topic
  • Utilities

CircleCI Documentation Status

Python Keycloak

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

Installation

Install via PyPI:

$ pip install python-keycloak

Bug reports

Please report bugs and feature requests at https://github.com/marcospereirampj/python-keycloak/issues

Documentation

The documentation for python-keycloak is available on readthedocs.

Keycloak version support

The library strives to always support Keycloak's latest version. Additionally to that, we also support 5 latest major versions of Keycloak, in order to give our user base more time for smoother upgrades.

Current list of supported Keycloak versions:

  • 26.X
  • 25.X
  • 24.X
  • 23.X
  • 22.X

Python version support

We only support Python versions that have active or security support by the Python Software Foundation. You can find the list of active Python versions here.

Example of Using Keycloak OpenID

from keycloak import KeycloakOpenID

# Configure client
keycloak_openid = KeycloakOpenID(server_url="http://localhost:8080/auth/",
                                 client_id="example_client",
                                 realm_name="example_realm",
                                 client_secret_key="secret")

# Get WellKnown
config_well_known = keycloak_openid.well_known()

# Get Code With Oauth Authorization Request
auth_url = keycloak_openid.auth_url(
    redirect_uri="your_call_back_url",
    scope="email",
    state="your_state_info")

# Get Access Token With Code
access_token = keycloak_openid.token(
    grant_type='authorization_code',
    code='the_code_you_get_from_auth_url_callback',
    redirect_uri="your_call_back_url")


# Get Token
token = keycloak_openid.token("user", "password")
token = keycloak_openid.token("user", "password", totp="012345")

# Get token using Token Exchange
token = keycloak_openid.exchange_token(token['access_token'], "my_client", "other_client", "some_user")

# Get Userinfo
userinfo = keycloak_openid.userinfo(token['access_token'])

# Refresh token
token = keycloak_openid.refresh_token(token['refresh_token'])

# Logout
keycloak_openid.logout(token['refresh_token'])

Example of Using Keycloak Admin API

from keycloak import KeycloakAdmin
from keycloak import KeycloakOpenIDConnection

keycloak_connection = KeycloakOpenIDConnection(
                        server_url="http://localhost:8080/",
                        username='example-admin',
                        password='secret',
                        realm_name="master",
                        user_realm_name="only_if_other_realm_than_master",
                        client_id="my_client",
                        client_secret_key="client-secret",
                        verify=True)

keycloak_admin = KeycloakAdmin(connection=keycloak_connection)

# Add user
new_user = keycloak_admin.create_user({"email": "example@example.com",
                                       "username": "example@example.com",
                                       "enabled": True,
                                       "firstName": "Example",
                                       "lastName": "Example"})

# Add user and raise exception if username already exists
# exist_ok currently defaults to True for backwards compatibility reasons
new_user = keycloak_admin.create_user({"email": "example@example.com",
                                       "username": "example@example.com",
                                       "enabled": True,
                                       "firstName": "Example",
                                       "lastName": "Example"},
                                      exist_ok=False)

# Add user and set password
new_user = keycloak_admin.create_user({"email": "example@example.com",
                                       "username": "example@example.com",
                                       "enabled": True,
                                       "firstName": "Example",
                                       "lastName": "Example",
                    "credentials": [{"value": "secret","type": "password",}]})

For more details, see the documentation available on readthedocs.

5.8.1 Aug 19, 2025
5.8.0 Aug 19, 2025
5.7.0 Jul 17, 2025
5.6.1 Jul 17, 2025
5.6.0 Jun 22, 2025
5.5.1 May 25, 2025
5.5.0 Apr 09, 2025
5.4.0 Apr 08, 2025
5.3.1 Feb 03, 2025
5.3.0 Feb 02, 2025
5.2.0 Jan 30, 2025
5.1.2 Jan 26, 2025
5.1.1 Dec 15, 2024
5.1.0 Dec 14, 2024
5.0.0 Dec 10, 2024
4.7.3 Nov 29, 2024
4.7.2 Nov 17, 2024
4.7.1 Nov 13, 2024
4.7.0 Nov 03, 2024
4.6.3 Oct 26, 2024
4.6.2 Oct 05, 2024
4.6.1 Oct 05, 2024
4.6.0 Oct 04, 2024
4.5.1 Oct 02, 2024
4.5.0 Sep 28, 2024
4.4.0 Sep 14, 2024
4.3.0 Aug 01, 2024
4.2.3 Jul 24, 2024
4.2.2 Jul 16, 2024
4.2.1 Jul 11, 2024
4.2.0 Jun 22, 2024
4.1.0 Jun 06, 2024
4.0.1 Jun 04, 2024
4.0.0 Apr 27, 2024
3.12.0 Apr 10, 2024
3.11.1 Apr 08, 2024
3.11.0 Apr 08, 2024
3.10.2 Apr 08, 2024
3.10.1 Apr 08, 2024
3.10.0 Apr 08, 2024
3.9.3 Apr 08, 2024
3.9.2 Apr 08, 2024
3.9.1 Feb 26, 2024
3.9.0 Feb 16, 2024
3.8.4 Feb 15, 2024
3.8.3 Feb 14, 2024
3.8.2 Feb 14, 2024
3.8.1 Feb 13, 2024
3.8.0 Feb 13, 2024
3.7.1 Feb 13, 2024
3.7.0 Nov 13, 2023
3.6.1 Nov 13, 2023
3.6.0 Nov 13, 2023
3.5.0 Nov 13, 2023
3.4.0 Nov 13, 2023
3.3.0 Jun 27, 2023
3.2.0 Jun 23, 2023
3.1.1 Jun 23, 2023
3.1.0 Jun 23, 2023
3.0.0 May 28, 2023
2.16.6 May 28, 2023
2.16.5 May 28, 2023
2.16.4 May 28, 2023
2.16.3 May 15, 2023
2.16.2 May 09, 2023
2.16.1 May 01, 2023
2.16.0 Apr 28, 2023
2.15.4 Apr 28, 2023
2.15.3 Apr 06, 2023
2.15.2 Apr 05, 2023
2.15.1 Apr 05, 2023
2.15.0 Apr 05, 2023
2.14.0 Mar 17, 2023
2.13.2 Mar 06, 2023
2.13.1 Mar 05, 2023
2.13.0 Mar 05, 2023
2.12.2 Mar 05, 2023
2.12.1 Mar 05, 2023
2.12.0 Feb 10, 2023
2.11.1 Feb 08, 2023
2.11.0 Feb 08, 2023
2.10.0 Feb 08, 2023
2.9.0 Jan 11, 2023
2.8.0 Dec 29, 2022
2.7.0 Dec 24, 2022
2.6.1 Dec 13, 2022
2.6.0 Oct 03, 2022
2.5.0 Aug 19, 2022
2.4.0 Aug 19, 2022
2.3.0 Aug 13, 2022
2.2.0 Aug 12, 2022
2.1.1 Jul 19, 2022
2.1.0 Jul 18, 2022
2.0.0 Jul 17, 2022
1.9.1 Jul 13, 2022
1.9.0 Jul 13, 2022
1.8.1 Jul 13, 2022
1.8.0 Jun 22, 2022
1.7.0 Jun 16, 2022
1.6.0 Jun 13, 2022
1.5.0 Jun 03, 2022
1.4.0 Jun 02, 2022
1.3.0 May 31, 2022
1.2.0 May 31, 2022
1.1.1 May 27, 2022
1.1.0 May 26, 2022
1.0.1 May 25, 2022
1.0.0 May 25, 2022
0.29.1 May 24, 2022
0.29.0 May 23, 2022
0.28.3 May 23, 2022
0.28.2 May 19, 2022
0.28.1 May 19, 2022
0.28.0 May 19, 2022
0.27.1 May 18, 2022
0.27.0 Feb 16, 2022
0.26.1 Aug 30, 2021
0.25.0 Jun 01, 2021
0.24.0 Dec 18, 2020
0.23.0 Nov 19, 2020
0.22.0 Aug 16, 2020
0.21.0 Jun 30, 2020
0.20.0 Apr 11, 2020
0.19.0 Feb 19, 2020
0.18.0 Dec 11, 2019
0.17.6 Oct 11, 2019
0.17.5 Aug 30, 2019
0.17.4 Jun 25, 2019
0.17.3 Jun 25, 2019
0.17.2 Jun 04, 2019
0.17.1 May 27, 2019
0.17.0 May 27, 2019
0.16.0 Mar 21, 2019
0.15.0 Mar 09, 2019
0.14.4 Dec 16, 2018
0.14.3 Dec 15, 2018
0.14.2 Dec 15, 2018
0.14.1 Dec 15, 2018
0.13.3 Oct 25, 2018
0.13.2 Aug 30, 2018
0.13.1 Aug 05, 2018
0.12.0 Jan 25, 2018
0.11.1 Dec 14, 2017
0.11.0 Dec 12, 2017
0.10.2 Oct 23, 2017
0.9.0 Sep 05, 2017
0.8.4 Aug 24, 2017
0.8.2 Aug 24, 2017
0.8.0 Aug 24, 2017
0.7.0 Aug 23, 2017
0.6.5 Aug 23, 2017
0.6.4 Aug 23, 2017
0.6.2 Aug 23, 2017
0.6.0 Aug 23, 2017
0.5.1 Aug 22, 2017
0.5.0 Aug 21, 2017
0.4.1 Aug 15, 2017
0.4.0 Aug 15, 2017
0.3.1 Aug 15, 2017
0.2.0 Aug 15, 2017
0.0.0 May 19, 2022

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras: None
Dependencies:
aiofiles (>=24.1.0)
async-property (>=0.2.2)
deprecation (>=2.1.0)
httpx (>=0.23.2)
jwcrypto (>=1.5.4)
requests (>=2.20.0)
requests-toolbelt (>=0.6.0)