Repository navigation
feat: add publish() to PromptClient - #34
techkayacodes wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
An in-flight get() or list() can repopulate the cache with stale data after publish() evicts it, requiring coordinated cache invalidation and regression tests for overlapping reads and publishes.
1 open issue
What changed in this PR
Adds PromptClient.publish() so Python callers can publish prompt versions through the public SDK rather than using the private stub, addressing issue #23.
Changes:
- Forwards publish requests and metadata, deriving slots automatically when omitted.
- Evicts cached prompt reads and matching list entries after default or main-branch publishes.
- Adds publish tests and README documentation.
| File | Description |
|---|---|
| tests/test_client.py | Extends the fake stub and tests slot derivation, request forwarding, and cache invalidation. |
| README.md | Documents the publish API and adds a usage example. |
| priompt_sdk/client.py | Implements slot derivation, publish(), and branch-aware cache eviction. |
Review effort: Balanced
| if self._cache_ttl and branch in ("", "main"): | ||
| self._cache.pop(uri, None) | ||
| for key in list(self._cache): | ||
| if isinstance(key, tuple) and key[0] == "list" and uri.startswith(key[1]): | ||
| self._cache.pop(key, None) |
There was a problem hiding this comment.
Addressed! Coordinated cache reads, fills, and invalidations with self._cache_lock and a self._cache_gen generation counter so in-flight get() / list() calls that overlap a publish() (or subscribe() reload) won't repopulate self._cache with stale pre-publish responses, and added deterministic threading.Event-based regression tests for both get() and list() (42/42 passing locally).

Issue
Fixes #23
What changed
PromptClient.publish(uri, template, slots=None, message="", branch="")inpriompt_sdk/client.py, wired toPromptServiceStub.PublishPromptwithmetadata=self._mdand returningPublishPromptResponse._derive_slots(template)to extract ASCII{slot}names in first-seen, deduplicated order whenslots is Nonewhile skipping escaped{{/}}literal braces (matchingvalidate.Slotsinpriompt/proto). Explicitslots(includingslots=[]) are forwarded as-is.get(uri)and matchinglist(prefix)entries (uri.startswith(prefix)) only whenbranch in ("", "main"), keeping the cache warm for non-main branch publishes.FakeStuband added 11 unit tests intests/test_client.pycovering slot derivation, explicit slots, request/metadata forwarding, and cache invalidation across"","main", and non-main branches.publish()inREADME.md.How I tested it
pytestin a Python 3.13.18.venv(uv pip install -e . pytest) and ranpytest -v tests/test_client.py: 40 passed in 0.46s.Checklist
#23and PR linksFixes #23README.mdupdated