Stashed payloads with nice URIs
Project description
kstash
kstash converts payloads into addressable stashes.
It allows programs to communicate using stash addresses instead of entire payloads, reducing the strain on messaging systems.
Installation
pip install kstash
Requirements
- Python >= 3.13
- AWS credentials configured (for S3 storage)
Basics
Use kstash to put a payload into an addressable stash.
Then provide kstash with the address to recover the payload.
import kstash
stash = kstash.create("my-payload", "some-data")
loaded = kstash.retrieve(stash.address)
stash == loaded
Simple Storage (S3)
By default, kstash.create() saves large payloads to S3.
# Optional: Test Backend Setup
import boto3
from moto import mock_aws
mock_aws().start()
conn = boto3.resource("s3", region_name="us-east-1")
conn.create_bucket(Bucket="stashes")
import kstash
# Process A: Sends a message containing the address of a stashed payload.
context = {"as_of": "today", "bin": b"0" * 1024 * 512}
stash = kstash.create("context", context, namespace="stashes")
message = {"context": str(stash.address), "command": "gen_report"}
assert str(stash.address) == "s3://stashes/context.c6ab205fe81dcad3eec3ab48b96b0618"
# Process B: Rebuilds the message from the stash's address.
loaded_stash = kstash.retrieve(message["context"])
assert loaded_stash == stash
Shared Links
Use stash.share() to produce a short-lived HTTPS link to the stash.
See kstash.Config.share_ttl_sec for configuration details.
import time
# Process A: Sends a message containing a shared link.
shared_link = stash.share(ttl_sec=5)
# Process B: Rebuilds the message from the shared link.
time.sleep(3)
loaded_stash = kstash.retrieve(shared_link)
assert loaded_stash == shared_stash
# Process B: Fails to retrieve the stash from an expired link.
time.sleep(3)
loaded_stash = kstash.retrieve(shared_link)
# Error: StashNotFound, share link expired
Inline Data Optimization
kstash.create() embeds small payloads in the stash's address.
See kstash.Config.max_inline_len for configuration details.
import kstash
stash = kstash.create("colorcode", 12, namespace="stashes")
assert str(stash.address) == "inline://stashes/colorcode?data=DA%3D%3D"
loaded_stash = kstash.retrieve(stash.address)
assert loaded_stash == stash
loaded_stash.data
Backends
Storage backends can be disabled to address specific deployment or test scenarios.
See kstash.Config.backends for more details.
import kstash
config = kstash.Config(backends=["mem"])
stash = kstash.create("object", {"data": 123}, config=config)
assert str(stash.address) == "mem://default/object.34472d91b2f84052bf26d4eaa862ef86"
loaded_stash = kstash.retrieve(stash.address, config=config)
assert loaded_stash == stash
Development Setup
uv sync
source .venv/bin/activate
pytest
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 kstash-0.2.0.tar.gz.
File metadata
- Download URL: kstash-0.2.0.tar.gz
- Upload date:
- Size: 34.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db9a300309b1532e39320517af6c5dcb312b6ea684a6b578e2e4988b57191d17
|
|
| MD5 |
ada52b2fb74733890e5adb1fdffcd5a7
|
|
| BLAKE2b-256 |
e2984f72e920efb9b371aae78eac43f9693be4445eb8996deb9f735d0285ce2c
|
Provenance
The following attestation bundles were made for kstash-0.2.0.tar.gz:
Publisher:
release.yml on ccortezia/kstash
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kstash-0.2.0.tar.gz -
Subject digest:
db9a300309b1532e39320517af6c5dcb312b6ea684a6b578e2e4988b57191d17 - Sigstore transparency entry: 217207571
- Sigstore integration time:
-
Permalink:
ccortezia/kstash@0cf09a08a7400a55fab3fedd8607dd042c7bfdd0 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/ccortezia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0cf09a08a7400a55fab3fedd8607dd042c7bfdd0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file kstash-0.2.0-py3-none-any.whl.
File metadata
- Download URL: kstash-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
368e5b3b16d59f0851be7c2e6d7f9f29767996b28dcfb548a5996e8b5c8663e8
|
|
| MD5 |
d6946cf3d89b9f09be014e4437489d90
|
|
| BLAKE2b-256 |
ee5a2020c56f1131bfd3971b5b65d3db36ae96554aa6ecf18023db1b66f0468e
|
Provenance
The following attestation bundles were made for kstash-0.2.0-py3-none-any.whl:
Publisher:
release.yml on ccortezia/kstash
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kstash-0.2.0-py3-none-any.whl -
Subject digest:
368e5b3b16d59f0851be7c2e6d7f9f29767996b28dcfb548a5996e8b5c8663e8 - Sigstore transparency entry: 217207574
- Sigstore integration time:
-
Permalink:
ccortezia/kstash@0cf09a08a7400a55fab3fedd8607dd042c7bfdd0 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/ccortezia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0cf09a08a7400a55fab3fedd8607dd042c7bfdd0 -
Trigger Event:
push
-
Statement type: