A library for splitting and assembling Keycloak realm configurations.
Project description
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
./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 Keycloakexports- 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.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pykeycloak_realm-0.1.1.tar.gz.
File metadata
- Download URL: pykeycloak_realm-0.1.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3437433900031e8d7ec04e91a9ad4fe898e4c349d3ced902cbad90ac9a9873e3
|
|
| MD5 |
820affa877122061c4b9b32448785cc2
|
|
| BLAKE2b-256 |
c779fa9739d7bab624a5fc90f92bb295049ea7ed800828f0b434a298b52a5719
|
Provenance
The following attestation bundles were made for pykeycloak_realm-0.1.1.tar.gz:
Publisher:
workflow.yml on jaddek/pykeycloak-realm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pykeycloak_realm-0.1.1.tar.gz -
Subject digest:
3437433900031e8d7ec04e91a9ad4fe898e4c349d3ced902cbad90ac9a9873e3 - Sigstore transparency entry: 1540114353
- Sigstore integration time:
-
Permalink:
jaddek/pykeycloak-realm@b009a6c45ec3f15ea5ce56b8900eed8e1c67ec56 -
Branch / Tag:
refs/heads/dev - Owner: https://github.com/jaddek
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@b009a6c45ec3f15ea5ce56b8900eed8e1c67ec56 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pykeycloak_realm-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pykeycloak_realm-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5104a39a788cebaf399f45e2de2c58f7148cbbb3c05a2fc0d02a86e34edc997b
|
|
| MD5 |
c59713a7722da7fb0780b44b4096dd5e
|
|
| BLAKE2b-256 |
3464c1e7da92226233969798d9237c409ce30df4d24d521377d532bb75590091
|
Provenance
The following attestation bundles were made for pykeycloak_realm-0.1.1-py3-none-any.whl:
Publisher:
workflow.yml on jaddek/pykeycloak-realm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pykeycloak_realm-0.1.1-py3-none-any.whl -
Subject digest:
5104a39a788cebaf399f45e2de2c58f7148cbbb3c05a2fc0d02a86e34edc997b - Sigstore transparency entry: 1540114465
- Sigstore integration time:
-
Permalink:
jaddek/pykeycloak-realm@b009a6c45ec3f15ea5ce56b8900eed8e1c67ec56 -
Branch / Tag:
refs/heads/dev - Owner: https://github.com/jaddek
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@b009a6c45ec3f15ea5ce56b8900eed8e1c67ec56 -
Trigger Event:
push
-
Statement type: