pyrompt.stores#
Storage layer for pyrompt using dol abstractions.
Provides clean Mapping/MutableMapping interfaces to filesystem storage.
Functions
Get platform-appropriate base path for pyrompt data. |
|
|
Get the path for a collection. |
|
Create all stores for a collection. |
|
Create a JSON metadata store. |
|
Create a file store for prompts with clean interface. |
|
Create a template store that handles multiple extensions. |
- pyrompt.stores.get_default_base_path()[source]#
Get platform-appropriate base path for pyrompt data.
- Returns:
%LOCALAPPDATA%/pyrompt - macOS/Linux: ~/.local/share/pyrompt
- Return type:
- pyrompt.stores.mk_collection_path(collection_name, base_path=None)[source]#
Get the path for a collection.
- pyrompt.stores.mk_collection_stores(collection_name, base_path=None, create_metadata=False)[source]#
Create all stores for a collection.
- pyrompt.stores.mk_metadata_store(rootdir, for_type='prompts')[source]#
Create a JSON metadata store.
- Parameters:
- Returns:
MutableMapping[str, dict] with JSON file storage
Example
>>> store = mk_metadata_store('/tmp/meta') >>> store['greeting'] = {'author': 'thor', 'version': '1.0'} >>> meta = store['greeting']
- pyrompt.stores.mk_prompt_store(rootdir, extension='txt')[source]#
Create a file store for prompts with clean interface.
Keys don’t show extension
Values are strings (not bytes)
Supports tab completion
- Parameters:
- Returns:
MutableMapping[str, str] with file-backed storage
Example
>>> store = mk_prompt_store('/tmp/prompts') >>> store['greeting'] = "Hello, {name}!" >>> print(store['greeting']) Hello, {name}!
- pyrompt.stores.mk_template_store(rootdir, extensions=None)[source]#
Create a template store that handles multiple extensions.
Keeps the extension in the key so we can detect template engine.
- Parameters:
- Returns:
MutableMapping[str, str] with file-backed storage
Example
>>> store = mk_template_store('/tmp/templates') >>> store['greeting.jinja2'] = "Hello {{ name }}!" >>> store['simple.txt'] = "Hello {name}!"