Python client library for Stash KV service
Project description
Stash Python Client
Python client library for Stash - a simple key-value configuration service.
Installation
pip install stash-client
Or with uv:
uv add stash-client
For local development:
cd lib/stash-python
uv sync --all-extras
Quick Start
from stash import Client
# basic usage
client = Client("http://localhost:8080")
client.set("app/config", '{"debug": true}', fmt="json")
value = client.get("app/config")
print(value) # {"debug": true}
# with authentication
client = Client("http://localhost:8080", token="your-api-token")
# with zero-knowledge encryption
client = Client(
"http://localhost:8080",
zk_key="your-secret-passphrase-min-16-chars"
)
# values are encrypted client-side before sending to server
client.set("secrets/api-key", "sk-secret-value")
# automatically decrypted on retrieval
value = client.get("secrets/api-key") # "sk-secret-value"
Context Manager
from stash import Client
with Client("http://localhost:8080", zk_key="passphrase-min-16") as client:
client.set("key", "value")
value = client.get("key")
# passphrase is cleared from memory on exit
Dict-like Access
client = Client("http://localhost:8080")
# set
client["app/config"] = "value"
# get
value = client["app/config"]
# delete
del client["app/config"]
# check existence
if "app/config" in client:
print("exists")
API Reference
Client
Client(
base_url: str,
token: str | None = None,
timeout: float = 30.0,
retries: int = 3,
zk_key: str | None = None
)
Parameters:
base_url: Stash server URLtoken: Bearer token for authenticationtimeout: Request timeout in secondsretries: Number of retry attempts for failed requestszk_key: Passphrase for zero-knowledge encryption (min 16 chars)
Methods
| Method | Description |
|---|---|
get(key: str) -> str |
Get value as string |
get_bytes(key: str) -> bytes |
Get value as bytes |
get_or_default(key: str, default: str) -> str |
Get value or return default |
set(key: str, value: str, fmt: str = "text") |
Set value with format |
delete(key: str) |
Delete key |
list(prefix: str = "") -> list[KeyInfo] |
List keys with optional prefix filter |
info(key: str) -> KeyInfo |
Get key metadata |
ping() -> None |
Check server connectivity |
close() -> None |
Clear ZK passphrase from memory |
KeyInfo
@dataclass
class KeyInfo:
key: str
size: int
format: str
secret: bool
zk_encrypted: bool
created_at: datetime
updated_at: datetime
Errors
from stash import (
StashError, # base exception
NotFoundError, # key not found (404)
UnauthorizedError, # unauthorized (401)
ForbiddenError, # forbidden (403)
DecryptionError, # ZK decryption failed
ConnectionError, # connection failed
)
Zero-Knowledge Encryption
When zk_key is provided, all values are encrypted client-side using AES-256-GCM with Argon2id key derivation. The server only stores encrypted data and cannot decrypt it.
Encryption parameters (compatible with Go client):
- Algorithm: AES-256-GCM
- Key derivation: Argon2id (time=1, memory=64MB, parallelism=4)
- Encrypted format:
$ZK$<base64(salt || nonce || ciphertext || tag)>
Development
# install dev dependencies
uv sync --all-extras
# run tests
uv run pytest
# run tests with coverage
uv run pytest --cov
# run linter
uv run ruff check .
# format code
uv run ruff format .
License
MIT License - see the main Stash repository for details.
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 stash_client-0.1.0.tar.gz.
File metadata
- Download URL: stash_client-0.1.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edfb210eff9a9a5006d30110101339289714543694597f990150e1bf8b61d017
|
|
| MD5 |
00fded4a88e79c01603a518d04127309
|
|
| BLAKE2b-256 |
364933852b7a5f26e55e2ffc6c3068a35d98edd13eaeeccbe7d936fa675b396e
|
Provenance
The following attestation bundles were made for stash_client-0.1.0.tar.gz:
Publisher:
publish-python.yml on umputun/stash
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stash_client-0.1.0.tar.gz -
Subject digest:
edfb210eff9a9a5006d30110101339289714543694597f990150e1bf8b61d017 - Sigstore transparency entry: 783407460
- Sigstore integration time:
-
Permalink:
umputun/stash@223968912eb24f1162dc03dc49318e60ef80b070 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/umputun
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@223968912eb24f1162dc03dc49318e60ef80b070 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file stash_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: stash_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ec3401231f7c43a4afbfef606fa4ce5565793d665179f8ff5ccebeb6c1e3183
|
|
| MD5 |
ba13c24af9188ffeb5fe236328b9b872
|
|
| BLAKE2b-256 |
6a24d4c14017004646f9d0ee4eefd03cf3c6d61c39224130e1706f11ae219cef
|
Provenance
The following attestation bundles were made for stash_client-0.1.0-py3-none-any.whl:
Publisher:
publish-python.yml on umputun/stash
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stash_client-0.1.0-py3-none-any.whl -
Subject digest:
0ec3401231f7c43a4afbfef606fa4ce5565793d665179f8ff5ccebeb6c1e3183 - Sigstore transparency entry: 783407503
- Sigstore integration time:
-
Permalink:
umputun/stash@223968912eb24f1162dc03dc49318e60ef80b070 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/umputun
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@223968912eb24f1162dc03dc49318e60ef80b070 -
Trigger Event:
workflow_dispatch
-
Statement type: