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.1.tar.gz (26.0 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.1-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: prompthub_my-0.3.1.tar.gz
  • Upload date:
  • Size: 26.0 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.1.tar.gz
Algorithm Hash digest
SHA256 4f61bb9f9cbeb9ef19b8b5e7d0af9e84be32aae2cf1ec52209b945f52ec1d1e3
MD5 9b841b4382e89ef416139d05713ab38b
BLAKE2b-256 8498032d10cf8dc6741a2f7ce638f7feb77768342f42af470567a2716dd4e6fd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: prompthub_my-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 39.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 490df127df8d2279586331ceda6322cb4d543c8181eb59630b54cde0b07a4edb
MD5 bd3feaf35d54e80840e9eac2afeabf34
BLAKE2b-256 67d7d70136a1e522997b23d6c57893f3d43d659ed37d898a54c38b1bfa1c4ac1

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