Keycloak Admin Model Representation Pydantic v2 Bindings
This project contains ONLY the pydantic v2 bindings for Keycloak model representations for use in Python based projects utilizing Keycloak admin APIs.
For APIs, I recommend Mantelo. Since this library itself doesn't offer any model representation bindings, projects can use both these libraries together for a complete pydantic compliant experience.
Caveats
-
Transform model representations to python dictionaries using pydantic
model_dump(). Mantelo client expects python dictionaries for write operations. Keycloak API semantics expect that all unset attributes are excluded.class TenantAdapter: @classmethod def model_new(cls, schema: TenantReqSchema) -> OrganizationRepresentation: """Convert `TenantReqSchema` to `OrganizationRepresentation`.""" return OrganizationRepresentation( name=schema.name, alias=schema.name.replace(" ", "_"), domains=[OrganizationDomainRepresentation(name=f"{schema.name.replace(' ', '-').lower()}.org", verified=False)], enabled=schema.active, attributes={"tax_id": [schema.tax_id], "address": [schema.address]}, ).model_dump(exclude_unset=True)
-
Models use
snake-caseattribute names for applications; but for Keycloak APIs, users should aliases to ensure actual Keyclock API attribute names are used.class TenantAdapter: @classmethod def model_new(cls, schema: TenantReqSchema) -> Any: """Convert `TenantReqSchema` to `Serializable`.""" return OrganizationRepresentation( name=schema.name, alias=schema.name.replace(" ", "_"), domains=[OrganizationDomainRepresentation(name=f"{schema.name.replace(' ', '-').lower()}.org", verified=False)], enabled=schema.active, attributes={"tax_id": [schema.tax_id], "address": [schema.address]}, ).model_dump(exclude_unset=True, use_alias=True)
-
Transform python dictionaries to model representations using python dictionary unpacking operator
**. Mantelo client returns python dictionaries for read operations.class TenantAdapter: @classmethod def schema(cls, data: Any | None) -> TenantResSchema | None: """Convert `Dict` to `TenantResSchema`.""" if data is None: return None # Coerse data dict to `OrganizationRepresentation` # representation = OrganizationRepresentation(**data) return TenantResSchema( id=representation.id, name=representation.name, address=representation.attributes["address"][0], tax_id=representation.attributes["tax_id"][0], active=representation.enabled, )
Versioning
I intend to keep the library versioning synced with the latest stable Keycloak release.
Installing
pip install keycloak-admin-clientpoetry add keycloak-admin-client
Metadata
Release files for keycloak-admin-client 26.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| keycloak_admin_client-26.2.4.tar.gz | 11.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| keycloak_admin_client-26.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.5 kB
Release files / keycloak_admin_client-26.2.4.tar.gz
| Download URL | keycloak_admin_client-26.2.4.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
74b51cb28dcde2a3f490ab9b88102d7b3161b6bdf36e8a5c36fbc722ea246217
|
|
BLAKE2b-256 checksum How to use checksums |
58cabb08b2b5272d2f395eaa6b65943b1e5e21f1726b4653a84e9b1dbdad7615
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2
|
Release files / keycloak_admin_client-26.2.4-py3-none-any.whl
| Download URL | keycloak_admin_client-26.2.4-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
63ee76a2bb6f55450beaf2936ae5d06f633e3a0c29c64c5b116409ad1b8fbcb8
|
|
BLAKE2b-256 checksum How to use checksums |
da51d3ab203e70c08a6d17530cdcedecd1c4e7bc54f4eec97086d3ba221f67fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2
|