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.2.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.2.0-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: prompthub_my-0.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 8d0dbebfcc2232078c98f23bd485c979f6cf354753225b0a42e0575ffcdbe405
MD5 bd298c302d33f2d2ee6fb02325cfc5e7
BLAKE2b-256 eb3a8e6fea9254bd5f905375e53b8cea9f2b9677b2cd3909bd1a2522951dcca6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: prompthub_my-0.2.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbff969e5a52f69c57f490fe1a3cb6e78ee4c6bd3f97149e6001eb2a7fe02620
MD5 9f8627c97ad7e97689d3de367f3ff430
BLAKE2b-256 9de8331a913bff0ff3f9059924bc96f5594f7ad9125301cc25bc074ffd908698

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