Client SDK for reading configuration from a self-hosted KeyKosh (K2) platform — token-scoped reads, TTL cache, and an encrypted offline last-known-good cache.
Project description
KeyKosh Python SDK (keykosh-sdk)
Read configuration from your self-hosted KeyKosh (K2) platform. One dependency
(cryptography); HTTP via the standard library. Python 3.9+.
The SDK talks to exactly one host — your own platform. There is no vendor default URL
and no callback home; base_url is required.
Install
pip install keykosh-sdk
Quick start
from keykosh import create_client
# Reads K2_BASE_URL / K2_TOKEN / K2_ENV from the environment; kwargs override.
k2 = create_client(
base_url="https://k2.acme.com",
env="prod",
cache_ttl_seconds=30, # optional in-memory TTL cache
offline_cache=True, # optional last-known-good fallback (~/.k2/cache)
)
cfg = k2.get_configuration() # full config for the default env
db_url = cfg.get_string("db.url", "postgresql://localhost/app")
debug = cfg.get_bool("feature.debug", False)
pool_size = k2.get_property("prod", "pool.size") # single property
What it does
- Token-scoped reads against
GET /api/config/token/{env}/currentand/properties/{key}, authenticated withAuthorization: Bearer <token>(andX-API-Token). - TTL cache (
cache_ttl_seconds) so repeated reads don't hit the network each call; serves the last value through a failed refresh. - Encrypted offline cache (
offline_cache=True, available on every tier) — on a successful fetch the resolved config is written to disk AES-256-GCM-encrypted, HMAC-sealed, and TTL-bounded, with keys derived from the SDK token (rotating the token invalidates the snapshot). If the platform is unreachable, the last-known-good snapshot is served instead of raising. Auth/not-found errors (401/403/404/421) always surface. The on-disk format is byte-compatible with the Java and Node SDKK2C1cache.
Errors
All failures raise K2Error with a status_code (HTTP status, or -1 for transport/config
errors). err.is_availability_error() is true for transport failures and 5xx.
Configuration via environment
| Var | Meaning |
|---|---|
K2_BASE_URL |
platform URL, e.g. https://k2.acme.com |
K2_TOKEN |
SDK token (the one secret — never commit it) |
K2_ENV |
default environment for the no-arg reads |
K2_CACHE_DIR |
offline cache directory (default ~/.k2/cache) |
Test
python tests/test_smoke.py # offline-cache crypto + config parsing, no network needed
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 keykosh_sdk-1.0.0.tar.gz.
File metadata
- Download URL: keykosh_sdk-1.0.0.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d743a9062968a454cf25fc32981a3515650dad12994107be1e463743ccb1fd8
|
|
| MD5 |
0b0703734a230b65b1df163403cdad32
|
|
| BLAKE2b-256 |
d6f3cc01a9fd452b928994c7f96a0cb169eb2d60666c7cecf5eb2441a11e4a9d
|
File details
Details for the file keykosh_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: keykosh_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a2dfb527b291cbe8ddf9ce9807a436b4c2f2965d3091077503d2eaa35c6c2e7
|
|
| MD5 |
119cb11da83d035d8a91d409688fcece
|
|
| BLAKE2b-256 |
007ac4ff504424201b6a64f52174fa709702dbe920ded3fc368647a4e3572de2
|