Skip to main content

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

  1. 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)
    
  2. Models use snake-case attribute 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)
    
  3. 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-client
  • poetry 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)

Source distribution for keycloak-admin-client 26.2.4
File Size Uploaded
keycloak_admin_client-26.2.4.tar.gz 11.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for keycloak-admin-client 26.2.4
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

26.2.4 This release

2 release files

26.0.8

2 release files

26.0.7

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page