Skip to main content

Prompt version control system built on SQLite

Project description

PromptHub

Prompt version control system built on SQLite. Store, version, diff, and roll back LLM prompts — no external services required.

from prompthub import Storage

store = Storage("prompts.db")
prompt = store.create_prompt("my-prompt")
prompt.add_version([("system", "You are helpful."), ("user", "Hello")])

Installation

pip install prompthub                    # core only — zero dependencies
pip install prompthub[langchain]         # + LangChain adapter
pip install prompthub[openai]            # + OpenAI tokenizer
pip install prompthub[anthropic]         # + Anthropic tokenizer
pip install prompthub[huggingface]       # + HuggingFace tokenizer
pip install prompthub[all]              # everything

Features

  • Version control — every add_version() stores a compact diff (Insert/Delete/Replace operations); full snapshots every N versions
  • Rollback — soft rollback (new version with old content) or hard rollback (delete history)
  • Diff — line diff, char diff, structured message diff between any two versions
  • Tags — label prompts with custom PromptTag values; filter with a boolean DSL
  • Token counting & cost estimation — attach model tags, count tokens, compute cost per 1M tokens from OpenRouter tariffs
  • LangChain adapter — wrap any Prompt in LangChainPromptAdapter to work with ChatPromptTemplate
  • Zero dependencies — SQLite only; LLM integrations are optional extras

Quick Start

from prompthub import Storage, PromptTag
from prompthub.core.tokenizers.openai_tag import OpenAIModelTag

store = Storage("prompts.db")

# Create prompt with initial version
prompt = store.create_prompt(
    "assistant",
    messages=[("system", "You are concise."), ("user", "Hi!")],
    tags=[PromptTag("production")],
    model_tags=[OpenAIModelTag("gpt-4o")],
)

# Add a new version
prompt.add_version([("system", "You are very concise."), ("user", "Hi!")])

# Diff two versions
diff = prompt.compare_versions_structured(1, 2)

# Soft rollback to version 1 (creates version 3)
prompt.rollback(target_seq=1)

# Fetch latest content as raw messages
messages = store.fetch_prompt("assistant")

# Fetch and work with LangChain
from prompthub.adapters import LangChainPromptAdapter
lc = LangChainPromptAdapter(store.get_prompt("assistant"))
template = lc.get_version_content(2)   # -> ChatPromptTemplate

Project Structure

prompthub/
├── __init__.py              # Public API: Storage, Prompt, PromptGroup, PromptTag, ModelTag
├── adapters/                # High-level adapters (user-facing)
│   └── langchain.py         # LangChainPromptAdapter
├── facade/
│   ├── storage.py           # Storage — main entry point
│   ├── prompt.py            # Prompt — versions, tags, diff, rollback
│   └── prompt_group.py      # PromptGroup — bulk queries
├── core/
│   ├── domain/              # Domain models: operations, diff, tags, tariffs
│   ├── adapters/            # LLM serializers: LangChainAdapter + registry
│   └── tokenizers/          # Token counting: OpenAI, Anthropic, HuggingFace
├── infrastructure/
│   ├── pricing_gateway.py   # Fetch tariffs from OpenRouter API
│   └── tariff_manager.py    # Write tariffs to DB
├── repository/              # SQL layer: PromptRepo, query DSL, schema
└── search/
    └── filters.py           # Boolean filter DSL: FieldEquals, TagFilter, ...

License

MIT

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

prompthub_my-0.3.0.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

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

prompthub_my-0.3.0-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

Details for the file prompthub_my-0.3.0.tar.gz.

File metadata

  • Download URL: prompthub_my-0.3.0.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.5 Windows/11

File hashes

Hashes for prompthub_my-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b7ea6d43a38428f3b9a49a15a65db283c16e9bd066bbb85fb17d198f284d0c47
MD5 f668bcdf25f95e0917cebacd3c538acb
BLAKE2b-256 597c83774f7e002f821ff5924bb739b1555d837bcbd804d15693c970772602eb

See more details on using hashes here.

File details

Details for the file prompthub_my-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: prompthub_my-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 39.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.5 Windows/11

File hashes

Hashes for prompthub_my-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f95cb3df639565321bdb377c02a4825399d24e16ed6a511c491ee2463435791e
MD5 d68adc03755a5c29faee1be1beec0e59
BLAKE2b-256 fa2d06082e1208cb27e718f73e99ce8acb99d69a614f522593349b25f38aefb6

See more details on using hashes here.

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