Skip to main content

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.

CI

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kstash-0.2.0.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kstash-0.2.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

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

Hashes for kstash-0.2.0.tar.gz
Algorithm Hash digest
SHA256 db9a300309b1532e39320517af6c5dcb312b6ea684a6b578e2e4988b57191d17
MD5 ada52b2fb74733890e5adb1fdffcd5a7
BLAKE2b-256 e2984f72e920efb9b371aae78eac43f9693be4445eb8996deb9f735d0285ce2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for kstash-0.2.0.tar.gz:

Publisher: release.yml on ccortezia/kstash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for kstash-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 368e5b3b16d59f0851be7c2e6d7f9f29767996b28dcfb548a5996e8b5c8663e8
MD5 d6946cf3d89b9f09be014e4437489d90
BLAKE2b-256 ee5a2020c56f1131bfd3971b5b65d3db36ae96554aa6ecf18023db1b66f0468e

See more details on using hashes here.

Provenance

The following attestation bundles were made for kstash-0.2.0-py3-none-any.whl:

Publisher: release.yml on ccortezia/kstash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page