Metadata-Version: 2.4
Name: keykosh-sdk
Version: 1.0.0
Summary: 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-URL: Homepage, https://keykosh.com
Project-URL: Documentation, https://github.com/k2platform/k2-sdk-python/blob/main/USER_MANUAL.md
Project-URL: Repository, https://github.com/k2platform/k2-sdk-python
Project-URL: Changelog, https://github.com/k2platform/k2-sdk-python/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/k2platform/k2-sdk-python/issues
Author: KeyKosh
License: MIT License
        
        Copyright (c) 2026 KeyKosh
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: config,configuration,feature-flags,k2,keykosh,secrets,self-hosted
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: cryptography>=41.0
Provides-Extra: aws
Requires-Dist: boto3>=1.28; extra == 'aws'
Provides-Extra: dev
Requires-Dist: build>=1.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: twine>=5.0; extra == 'dev'
Description-Content-Type: text/markdown

# 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

```bash
pip install keykosh-sdk
```

## Quick start

```python
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}/current` and
  `/properties/{key}`, authenticated with `Authorization: Bearer <token>` (and `X-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 SDK `K2C1` cache.

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

```bash
python tests/test_smoke.py   # offline-cache crypto + config parsing, no network needed
```
