Metadata-Version: 2.4
Name: prompthub-my
Version: 0.3.0
Summary: Prompt version control system built on SQLite
License-Expression: MIT
License-File: LICENSE
Keywords: llm,prompt,versioning,langchain,openai,anthropic
Author: Matthew
Requires-Python: >=3.10
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Provides-Extra: all
Provides-Extra: anthropic
Provides-Extra: core
Provides-Extra: huggingface
Provides-Extra: langchain
Provides-Extra: openai
Requires-Dist: anthropic (>=0.25) ; extra == "all"
Requires-Dist: anthropic (>=0.25) ; extra == "anthropic"
Requires-Dist: langchain-core (>=0.1) ; extra == "all"
Requires-Dist: langchain-core (>=0.1) ; extra == "langchain"
Requires-Dist: openai (>=1.0) ; extra == "all"
Requires-Dist: openai (>=1.0) ; extra == "openai"
Requires-Dist: transformers (>=4.30) ; extra == "all"
Requires-Dist: transformers (>=4.30) ; extra == "huggingface"
Project-URL: Homepage, https://github.com/DaniilSelin/prompthub
Project-URL: Issues, https://github.com/DaniilSelin/prompthub/issues
Project-URL: Repository, https://github.com/DaniilSelin/prompthub
Description-Content-Type: text/markdown

# PromptHub

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

```python
from prompthub import Storage

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

## Installation

```bash
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

```python
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

