Library for storing and retrieving state of Kelvin applications.
Project description
kelvin-app-storage
Redis-backed storage client for Kelvin applications. Keys are automatically prefixed with the application name and version derived from app.yaml.
Installation
pip install kelvin-app-storage
Prerequisites
A running Redis instance is required. For local development:
docker run -d --name redis -p 6379:6379 redis
Quick Start
from kelvin_app_storage import StorageClient
client = StorageClient()
# Store and retrieve values
client.set("sensor_id", "abc-123")
client.get("sensor_id") # "abc-123"
# List all stored keys
client.list_keys() # ["myapp_1.0_sensor_id"]
# Print a formatted table of all stored key-value pairs
print(client)
Disable Key Prefixing
By default, keys are prefixed with <app_name>_<app_version>_ derived from app.yaml. To store keys without a prefix:
client = StorageClient(no_prefix=True)
Supported Value Types
The client automatically serializes and deserializes the following types:
| Type | Storage Format |
|---|---|
str |
Stored as-is |
int |
String representation |
float |
String representation |
bool |
"true" / "false" |
list |
JSON string |
dict |
JSON string |
client.set("count", 42)
client.get("count") # 42
client.set("config", {"threshold": 0.8, "enabled": True})
client.get("config") # {"threshold": 0.8, "enabled": True}
client.set("tags", ["pressure", "temperature"])
client.get("tags") # ["pressure", "temperature"]
Configuration
The client is configured via environment variables:
| Environment Variable | Default | Description |
|---|---|---|
KELVIN_APP_STORAGE_HOST |
kelvin-app-storage.app |
Redis host |
KELVIN_APP_STORAGE_PORT |
6379 |
Redis port |
KELVIN_APP_STORAGE_PREFIX |
Derived from app.yaml |
Custom key prefix (overrides app.yaml) |
KELVIN_APP_STORAGE_LOG_LEVEL |
INFO |
Log level (DEBUG or INFO) |
Key Prefix via app.yaml
When no custom prefix is set, the key prefix is derived from app.yaml in the current working directory:
info:
name: myapp
version: "1.0"
This produces the prefix myapp_1.0, so a key sensor_id becomes myapp_1.0_sensor_id in Redis.
If app.yaml is missing or unreadable, a random UUID is used as the fallback prefix.
API Reference
StorageClient(no_prefix: bool = False)
Creates a new storage client and connects to Redis.
no_prefix-- IfTrue, keys are stored without any prefix.- Raises
ValueErrorifKELVIN_APP_STORAGE_PORTis not a valid integer. - Raises
redis.ConnectionErrorif Redis is unreachable.
client.get(key: str) -> Any
Retrieves and deserializes the value for the given key. Returns None if the key does not exist.
client.set(key: str, value: Any) -> bool
Serializes and stores a value. Returns True on success. Raises TypeError for unsupported value types.
client.list_keys() -> list
Returns all keys currently stored in Redis.
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 Distributions
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 kelvin_app_storage-1.0.0-py3-none-any.whl.
File metadata
- Download URL: kelvin_app_storage-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c1429432f4d1b51bf4b72737ad079b7e6156bbcedd3ec3420431ee816be2e82
|
|
| MD5 |
8baca586bc41e226de9928393e576f8e
|
|
| BLAKE2b-256 |
3c2fff5f68b5854a59a243c3f55e68d2f60a6614cdb4fb8a7a1688e23994f0d8
|