Open source SDK for prompt versioning, A/B testing, and cost tracking
Project description
PromptSim Core
Open source SDK for prompt versioning, A/B testing, and cost tracking for ChatGPT applications.
Features
- 🔄 Prompt Versioning: Git-like versioning for your prompts
- 🧪 A/B Testing: Simple experimentation with statistical significance
- 💰 Cost Tracking: Automatic OpenAI cost calculation and monitoring
- 📊 Local Storage: SQLite-based local storage with data portability
- ☁️ Cloud Ready: Seamless upgrade to PromptSim Cloud
- 🔒 Zero Lock-in: Full data export/import capabilities
Quick Start
pip install promptsim
from promptsim import PromptSim
# Local mode (no external dependencies)
client = PromptSim(storage="local")
# Create a prompt
client.create_prompt(
key="welcome_message",
template="Hello {name}! Welcome to our {product}.",
model="gpt-3.5-turbo"
)
# Use the prompt
response = client.complete(
prompt_key="welcome_message",
variables={"name": "Alice", "product": "ChatGPT app"},
user_id="user_123"
)
print(response.text) # "Hello Alice! Welcome to our ChatGPT app."
print(response.cost_usd) # 0.0001
Testing Your Installation
After installing PromptSim, you can verify everything works correctly:
Quick Test
# Test basic functionality (no OpenAI API key required)
from promptsim import PromptSim
client = PromptSim(storage="local")
prompt = client.create_prompt(
key="test",
template="Hello {name}!"
)
print(f"Created prompt: {prompt.key} v{prompt.version}")
Comprehensive Test Suite
# Run the built-in test runner
python -c "import promptsim; exec(open(promptsim.__file__.replace('__init__.py', '../run_tests.py')).read())"
# Or if you have the source code:
python run_tests.py
Manual Testing Steps
- Test Basic Functionality (no API key needed):
from promptsim import PromptSim
# Create client
client = PromptSim(storage="local", db_path="test.db")
# Create and version prompts
v1 = client.create_prompt(key="test", template="Hello {name}!")
v2 = client.create_prompt(key="test", template="Hi {name}!")
# List prompts
prompts = client.list_prompts()
print(f"Created {len(prompts)} prompt versions")
# Export data (for backup/migration)
data = client.export_data()
print(f"Exported {len(data['prompts'])} prompts")
- Test with OpenAI (requires API key):
import os
os.environ["OPENAI_API_KEY"] = "your-key-here"
from promptsim import PromptSim
client = PromptSim(storage="local")
client.create_prompt(
key="welcome",
template="Welcome {name} to {product}!"
)
response = client.complete(
prompt_key="welcome",
variables={"name": "Alice", "product": "PromptSim"},
user_id="user123"
)
print(f"Response: {response.text}")
print(f"Cost: ${response.cost_usd:.6f}")
- Test CLI Interface:
# Create a prompt
python -m promptsim.cli create "test_cli" "Hello {name}!" --name "CLI Test"
# List prompts
python -m promptsim.cli list --verbose
# Export data
python -m promptsim.cli export --output backup.json
Running Unit Tests
If you want to run the full test suite:
# Install test dependencies
pip install promptsim[test]
# Run tests
pytest tests/ -v
Troubleshooting
Import Error: Make sure you've installed all dependencies:
pip install openai tiktoken sqlalchemy requests pydantic
OpenAI API Error: The core functionality works without OpenAI. Set your API key only when you need to make actual completions:
export OPENAI_API_KEY="your-openai-api-key"
Permission Error: If you get database permission errors, make sure you have write access to the current directory or specify a different path:
client = PromptSim(storage="local", db_path="/tmp/promptsim.db")
Installation
From PyPI (Recommended)
pip install promptsim
From TestPyPI (Latest Development)
pip install -i https://test.pypi.org/simple/ promptsim
Local Development
git clone https://github.com/promptsim/promptsim-core
cd promptsim-core
pip install -e .
Storage Options
Local SQLite (Default)
client = PromptSim(storage="local", db_path="./prompts.db")
Cloud API
client = PromptSim(
storage="cloud",
api_key="pk_live_...",
host="api.promptsim.com"
)
Local Files (JSON)
client = PromptSim(storage="files", data_dir="./prompt_data")
License
MIT License - see LICENSE file.
Contributing
We welcome contributions! See CONTRIBUTING.md for guidelines.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file promptsim-0.1.0.tar.gz.
File metadata
- Download URL: promptsim-0.1.0.tar.gz
- Upload date:
- Size: 25.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cf203ebc7870770a8687387b9ccd7261f3c5cb65bfa740cf7e97c2aedc92405
|
|
| MD5 |
eec82d7ef87f54af2e8114e49774940e
|
|
| BLAKE2b-256 |
79854b5d595f7f0ebe75a216d0baad9ccd48996e5239470d652b8c340afdb9ca
|
File details
Details for the file promptsim-0.1.0-py3-none-any.whl.
File metadata
- Download URL: promptsim-0.1.0-py3-none-any.whl
- Upload date:
- Size: 28.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e74fbcd52eceff05975c901820e8e7ba7f11f35bc25cd3365a9b22c0510940f
|
|
| MD5 |
0f093b30af64494d7622a6bac153a3cc
|
|
| BLAKE2b-256 |
8c7ba4919c5db2a2524bd91aabdb74f0fe58e005f4ea2cd8f2e6baff7b298453
|