python-keycloak is a Python package providing access to the Keycloak API.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python_keycloak-4.6.1.tar.gz
.
File metadata
- Download URL: python_keycloak-4.6.1.tar.gz
- Upload date:
- Size: 62.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dcc5ecbc8c3e90d4fe0e31cd3247057716d4f3e0364d1499539c5afa90659e2 |
|
MD5 | 669a75d76d9a9b762309c428c80e4dda |
|
BLAKE2b-256 | 51c024842129a79e8ce61a5bd0f98343241af78e03c1172274271b0e5eeb2394 |
File details
Details for the file python_keycloak-4.6.1-py3-none-any.whl
.
File metadata
- Download URL: python_keycloak-4.6.1-py3-none-any.whl
- Upload date:
- Size: 76.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a72ea25a5516dec1f01337a092b09e240004fae90a9f854983a82b21a6e3f139 |
|
MD5 | 0fee6ebf7611f20e5b0e1bc1819887e1 |
|
BLAKE2b-256 | 2d31627cfa4c92a0ecbeb80f66ca2377c71f1ae4df91775505f75420ff523350 |