Skip to main content
  1. Realm Builder pykeycloak
  2. Methodology for Defining Realm Configurations

Pykeycloak Realm Builder

This library allows you to split the configuration and assemble a Keycloak realm configuration.

It is especially useful for local development, when you need a full Keycloak instance running on your local machine for testing, and later upload it to your local Keycloak instance, a containerized Keycloak, or your own Keycloak instance running on a server.

Special Note

Keycloak validation is weird. When you upload a realm configuration file, you never get a detailed error explaining what’s wrong. It just reports vague issues like duplicated resources or invalid JSON, even when the JSON file itself is valid.

otago.realm.yml is provided as an example for future realms and should not be used in production.

How it works

  1. ./data/realms/templates/otago.realm.yml - keycloak template

Data directory

The default structure consists of two main directories for different purposes:

  • templates - contains all realm configuration templates that need to be uploaded to Keycloak
  • exports - contains all finalized realm JSON configurations
data/
└── realms/
    ├── templates/
    │   └── otago.realm.yml # config as an example
    ├── export/
        └── otago.realm.json # real Keycloak config transformed from templates

Install

make install

Dependencies

  • no specific dependencies

Commands

There are multiple options how to run the tool:

For shell environment

PYTHONPATH=src bin/realm_builder --from-realm otago --to-realm otago

For UV

uv run python src/pykeycloak_realm/realm.py --from-realm=otago --to-realm=otago - will generate a new config

Shortcuts using MAKE

#build and upload realm (alias for make docker-kc-export-realm-otago)
make otago
# generate new config
make docker-kc-build-realm-%
# generate and export config to Keycloak
make docker-kc-export-realm-%

Configs

All configs here

./src/pykeycloak_realm/config.py

You can manage them using system environment variables or .env files.

.env files are supported only via Makefiles (no dotenv dependencies are used); in other cases, they are intended as helper files for environment setup.

.env        # All variables available for configuring
.env.kc     # Docker Keycloak
.env.local  # optional (for local usage)

Docker

make help
make dup # up docker container with keycloak
make dd  # down docker container
...

Tests

make tests - run tests


Methodology for Defining Realm Configurations

Sections: envs, vars, realms

To make the entire configuration manageable, it is important to separate the configuration into its components.

envs

The envs section is defined at the global scope of the realm and contains clients along with their environment variables (IDs, secrets, etc.).

vars

The vars section contains all configuration variables and presets based on them, which are duplicated or may be duplicated across the configuration.

realms

The main configuration containing all parameters.

Metadata

Release files for pykeycloak-realm 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pykeycloak-realm 0.1.2
File Size Uploaded Provenance Actions
pykeycloak_realm-0.1.2.tar.gz 5.6 kB With provenance Details for pykeycloak_realm-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pykeycloak-realm 0.1.2
File Interpreter ABI Platform Actions
pykeycloak_realm-0.1.2-py3-none-any.whl Python 3 none any Details for pykeycloak_realm-0.1.2-py3-none-any.whl

Total release size: 11.8 kB

Release files / pykeycloak_realm-0.1.2.tar.gz

Download URL pykeycloak_realm-0.1.2.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
082370f3062b49a51aaed145bc93d3ce49d9c6f5bfe94925d6c59cdf07b9a181
BLAKE2b-256 checksum
How to use checksums
2a57ed570736e927356f9bc8286c81ec2fa6ed0e127833c32dc78b2eac644569
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

Release files / pykeycloak_realm-0.1.2-py3-none-any.whl

Download URL pykeycloak_realm-0.1.2-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d8e858deaef39172fb4d80dff4bc9344e38a69dbf868572b314d347023cb40f
BLAKE2b-256 checksum
How to use checksums
e936b4cf75aebb6612535bcd7d19b387b3783955b1297c05da456144bf937e35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

Security for pykeycloak-realm 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pykeycloak_realm-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files Full provenance

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