Skip to main content

Keycloak IAM Admin Pydantic Models

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keycloak_admin_client-26.0.7.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keycloak_admin_client-26.0.7-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file keycloak_admin_client-26.0.7.tar.gz.

File metadata

  • Download URL: keycloak_admin_client-26.0.7.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/24.2.0

File hashes

Hashes for keycloak_admin_client-26.0.7.tar.gz
Algorithm Hash digest
SHA256 42c2d52db7a11711c421eaebe5da40b2e06194e4989a3054af682537699c8e46
MD5 2c97df8dc7ac49744b38d4247ac29d28
BLAKE2b-256 6e80d7d095c9251cfa0def569e3ae63e0121eb70e7abe554e572b349c49fe10c

See more details on using hashes here.

File details

Details for the file keycloak_admin_client-26.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for keycloak_admin_client-26.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 9184b2fe6a276614cfd751bf15ac117a9fa3644805b869be16032824f30b454b
MD5 257f97a355fb461c2e19a910a0dd2926
BLAKE2b-256 a369095b62a1d2d81fd52a13cdb1e93628f630bc9243f52df237f87adeb7c7f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page