Skip to main content

A library for managing prompt templates with versioning and AI models

Project description

ZePrompter ๐Ÿš€

A powerful and intuitive Python library for managing AI prompt templates and model configurations with built-in versioning, web dashboard, and seamless API.

Why ZePrompter?

โœจ Simple API: One-line setup, intuitive manager interface
๐Ÿ”„ Smart Versioning: Automatic prompt template versioning
๐Ÿค– Model Management: Centralized AI model configuration storage
๐ŸŒ Web Dashboard: Beautiful built-in interface with authentication
๐Ÿ’พ Database Agnostic: SQLite by default, PostgreSQL/MySQL support
๐Ÿ” Secure: Login-protected dashboard and API endpoints
๐Ÿ“ Rich Metadata: Descriptions, extra fields, timestamps, and more

Quick Start

Installation

pip install ze-prompter

Basic Usage (The Easy Way!)

from ze_prompter import get_manager

# Get the manager - this handles everything for you!
manager = get_manager()

# Create a prompt template
template = manager.prompt_manager.create_prompt_template(
    name="greeting",
    content="Hello {name}, welcome to {platform}! How can I help you today?"
)

# Create a model configuration
model = manager.model_manager.create_model(
    name="gpt-4",
    description="OpenAI GPT-4 model",
    extra_fields={
        "provider": "openai",
        "max_tokens": 4096,
        "temperature": 0.7,
        "api_key": "your-api-key-here"
    }
)

print(f"Created template: {template.name} (v{template.version})")
print(f"Created model: {model.name}")

That's it! No database setup, no session management, no boilerplate code. ZePrompter handles everything automatically.

Core Features

๐ŸŽฏ Prompt Template Management

from ze_prompter import get_manager

manager = get_manager()
pm = manager.prompt_manager  # Shorthand

# Create templates
email_template = pm.create_prompt_template(
    name="customer_email",
    content="Dear {customer_name},\n\nThank you for {action}. {message}\n\nBest regards,\n{sender_name}",
    description="Customer service email template"
)

# Update templates (automatically creates new version)
updated_template = pm.update_prompt_template(
    template_id=email_template.id,
    content="Hi {customer_name}! ๐Ÿ‘‹\n\nThanks for {action}! {message}\n\nCheers,\n{sender_name}",
    description="More friendly customer service email"
)

# Get latest version
latest = pm.get_latest_template("customer_email")
print(f"Latest version: {latest.version}")

# Get all versions by name (much cleaner!)
versions = pm.get_template_versions("customer_email")
print(f"Total versions: {len(versions)}")

# Get specific version by name and version number
specific_version = pm.get_template_by_name_and_version("customer_email", 1)
print(f"Version 1 content: {specific_version.content}")

# You can also work with IDs if needed (methods with _by_id suffix)
versions_by_id = pm.get_template_versions_by_id(template_id)
template_by_id = pm.get_prompt_template_by_id(template_id)

# List all templates
all_templates = pm.list_templates()

๐Ÿค– Model Configuration Management

from ze_prompter import get_manager
manager = get_manager()
mm = manager.model_manager  # Shorthand

# Create different model configurations
openai_model = mm.create_model(
    name="gpt-4-turbo",
    description="Latest OpenAI GPT-4 Turbo",
    extra_fields={
        "provider": "openai",
        "model_id": "gpt-4-turbo-preview",
        "max_tokens": 4096,
        "temperature": 0.7,
        "top_p": 1.0,
        "api_base": "https://api.openai.com/v1"
    }
)

anthropic_model = mm.create_model(
    name="claude-3-opus",
    description="Anthropic Claude 3 Opus",
    extra_fields={
        "provider": "anthropic",
        "model_id": "claude-3-opus-20240229",
        "max_tokens": 4096,
        "temperature": 0.3
    }
)

# Get models by name
gpt4 = mm.get_model_by_name("gpt-4-turbo")
print(f"Model config: {gpt4.extra_fields}")

# List all models
models = mm.list_models()
for model in models:
    provider = model.extra_fields.get('provider', 'unknown')
    print(f"{model.name} ({provider})")

๐ŸŒ Web Dashboard

Launch the beautiful web interface:

# Option 1: Using the included runner
from ze_prompter.api.main import app
import uvicorn

uvicorn.run(app, host="0.0.0.0", port=8000)
# Option 2: Using the CLI  
python -m ze_prompter.cli serve --port 8000

Creating User Accounts

Before accessing the web dashboard, you need to create a user account:

# Create a new user account interactively
python -m ze_prompter.cli create-account

This command will prompt you for:

  • Username
  • Email
  • Password (with confirmation)
  • Whether to make the user a superuser (admin)

Example:

$ python -m ze_prompter.cli create-account
๐Ÿ”ง Creating a new user account...
Username: admin
Email: admin@example.com
Password: 
Repeat for confirmation: 
Make this user a superuser (admin)? [y/N]: y
โœ… Successfully created superuser: admin

Then visit http://localhost:8000 and login with your created account.

The dashboard provides:

  • ๐Ÿ“ Create, edit, and delete prompt templates
  • ๐Ÿค– Manage model configurations
  • ๐Ÿ“š Browse template version history
  • ๐Ÿ” Search and filter functionality
  • ๐Ÿ“Š Usage statistics and analytics
  • ๐Ÿ” Secure authentication

โšก Advanced Usage

Context Manager (Recommended for Scripts)

from ze_prompter import get_manager

with get_manager() as manager:
    # Create a bunch of templates
    templates = [
        ("welcome", "Welcome {name} to our {service}!"),
        ("goodbye", "Thanks for using {service}, {name}!"),
        ("error", "Sorry {name}, we encountered an error: {error_message}")
    ]
    
    for name, content in templates:
        manager.prompt_manager.create_prompt_template(
            name=name,
            content=content
        )
    
    print("Created all templates!")
# Database connection is automatically closed here

Custom Database Session

from ze_prompter import get_manager
from ze_prompter.models.database import SessionLocal

# Use your own session
db_session = SessionLocal()
manager = get_manager(db_session)

# Now use the manager...
template = manager.prompt_manager.create_prompt_template(
    name="custom_session_template",
    content="This uses a custom database session!"
)

# Don't forget to close when done
db_session.close()

Batch Operations

Batch import functionality is coming soon! This will allow you to efficiently import multiple templates at once.

Configuration

ZePrompter supports configuration through environment variables for easy deployment and security.

Core Configuration Variables

Variable Description Default Example
ZE_PROMPTER_DB Database connection string sqlite:///./prompt_library.db postgresql://user:pass@localhost/zeprompter
ZE_PROMPTER_SECRET JWT secret key for authentication ZEPROMPTER-UNSECURE-KEY your-super-secret-jwt-key-here

Setting Environment Variables

Create a .env file in your project root:

# Database Configuration
ZE_PROMPTER_DB=sqlite:///./prompt_library.db
# For PostgreSQL: ZE_PROMPTER_DB=postgresql://user:pass@localhost/zeprompter
# For MySQL: ZE_PROMPTER_DB=mysql://user:pass@localhost/zeprompter

# Security Configuration  
ZE_PROMPTER_SECRET=your-super-secret-jwt-key-here

Using Environment Variables

import os
from ze_prompter import get_manager

# Set configuration via environment variables
os.environ["ZE_PROMPTER_DB"] = "postgresql://user:pass@localhost/zeprompter"
os.environ["ZE_PROMPTER_SECRET"] = "my-super-secret-key"

# Manager will automatically use these settings
manager = get_manager()

Security Note: Always use a strong, unique secret key for ZE_PROMPTER_SECRET in production environments. The default value is insecure and should only be used for development.

๐Ÿš€ Quick Deploy

Deploy Ze Prompter instantly with ngrok for easy sharing and testing!

Prerequisites

  1. Install ngrok: Download from ngrok.com and ensure it's in your PATH
  2. Clone the repository:
    git clone https://github.com/olsihoxha/zeprompter
    cd zeprompter
    pip install -r requirements.txt
    

One-Command Deploy

# Deploy with ngrok tunnel (recommended for testing)
python -m ze_prompter.cli deploy

# Deploy without ngrok (local only)
python -m ze_prompter.cli deploy --no-ngrok

# Deploy on custom port
python -m ze_prompter.cli deploy --port 3000

What happens when you deploy:

  1. ๐Ÿ”ง Initializes database - Sets up SQLite database automatically
  2. ๐ŸŒ Creates ngrok tunnel - Generates public HTTPS URL for sharing
  3. ๐Ÿ“ Updates .env file - Automatically saves the public URL to ZE_PROMPTER_URL
  4. โš ๏ธ Validates configuration - Warns about potential SQLite issues with public URLs
  5. ๐ŸŽ‰ Starts the server - Your app is ready to share!

Example Output

$ python -m ze_prompter.cli deploy

๐Ÿš€ Deploying Ze Prompter...
Initializing database...
Starting ngrok tunnel...
โœ… ngrok tunnel created: https://abc123.ngrok.io
โœ… Updated .env file with ZE_PROMPTER_URL=https://abc123.ngrok.io

๐ŸŒŸ Ze Prompter is now running!
๐Ÿ“ Local URL: http://localhost:8000
๐ŸŒ Public URL: https://abc123.ngrok.io
๐Ÿ” Create an account first with: python -m ze_prompter.cli create-account
๐Ÿ“– Press Ctrl+C to stop the server

Production Considerations

When deploying with a public URL, consider upgrading your database:

# Example with PostgreSQL
export ZE_PROMPTER_DB="postgresql://user:pass@your-db-host/zeprompter"
export ZE_PROMPTER_SECRET="your-super-secure-secret-key"
python -m ze_prompter.cli deploy

Note: The CLI will warn you if you're using SQLite with a public URL, as it may cause issues with concurrent users.

REST API

When you run the web server, you get a full REST API. This section provides context about the available endpoints - these are automatically created when you start the server and can be used for programmatic access to your templates and models.

Prompt Templates

  • GET /api/prompts - List all templates
  • POST /api/prompts - Create new template
  • GET /api/prompts/{id} - Get specific template
  • PUT /api/prompts/{id} - Update template (creates new version)
  • DELETE /api/prompts/{id} - Delete template
  • GET /api/prompts/{id}/versions - Get all versions of template

Models

  • GET /api/models - List all models
  • POST /api/models - Create new model
  • GET /api/models/{id} - Get specific model
  • PUT /api/models/{id} - Update model
  • DELETE /api/models/{id} - Delete model

Authentication

  • POST /auth/login - Login to get access token
  • POST /auth/logout - Logout

Real-World Examples

AI Chatbot with Multiple Models

from ze_prompter import get_manager

def setup_chatbot_system():
    manager = get_manager()
    
    # Create prompt templates for different scenarios
    templates = [
        ("greeting", "Hello! I'm {bot_name}, your AI assistant. How can I help you today?"),
        ("help_request", "I understand you need help with {topic}. Let me {action} for you."),
        ("error_handling", "I apologize, but I encountered an issue: {error}. Let me try a different approach."),
        ("farewell", "Thank you for chatting with me! Have a great {time_of_day}!")
    ]
    
    for name, content in templates:
        manager.prompt_manager.create_prompt_template(name=name, content=content)
    
    # Configure different AI models for different use cases
    models = [
        ("fast_responses", "GPT-3.5 Turbo for quick responses", {
            "provider": "openai",
            "model": "gpt-3.5-turbo",
            "temperature": 0.7,
            "max_tokens": 150
        }),
        ("complex_tasks", "GPT-4 for complex reasoning", {
            "provider": "openai", 
            "model": "gpt-4",
            "temperature": 0.3,
            "max_tokens": 1000
        }),
        ("creative_writing", "Claude for creative tasks", {
            "provider": "anthropic",
            "model": "claude-3-opus",
            "temperature": 0.9,
            "max_tokens": 2000
        })
    ]
    
    for name, desc, config in models:
        manager.model_manager.create_model(
            name=name,
            description=desc,
            extra_fields=config
        )
    
    print("Chatbot system configured!")
    return manager

# Use the configured system
manager = setup_chatbot_system()

# Get a template and model for a user interaction
greeting_template = manager.prompt_manager.get_latest_template("greeting")
fast_model = manager.model_manager.get_model_by_name("fast_responses")

# Format the prompt
prompt = greeting_template.content.format(bot_name="ZeBot")
model_config = fast_model.extra_fields

print(f"Prompt: {prompt}")
print(f"Model: {model_config['model']} (temp: {model_config['temperature']})")

Email Template System

from ze_prompter import get_manager

def setup_email_templates():
    """Set up basic email templates"""
    with get_manager() as manager:
        templates = [
            ("welcome_email", "Welcome to {company}, {first_name}! Here's what happens next..."),
            ("newsletter", "๐Ÿ“ง {topic} Weekly Digest - {date}"),
            ("promotional", "๐ŸŽ‰ Save {discount}% on {product} - Limited time!")
        ]
        
        for name, content in templates:
            manager.prompt_manager.create_prompt_template(name=name, content=content)
        
        print(f"Created {len(templates)} email templates!")

setup_email_templates()

Development & Contributing

Development Setup

# Clone the repository  
git clone https://github.com/olsihoxha/zeprompter
cd zeprompter

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install in development mode
pip install -e .

# Install development dependencies
pip install pytest black flake8 mypy

# Run tests
pytest

# Format code
black ze_prompter/

# Type checking
mypy ze_prompter/

Support & Community

  • ๐Ÿ› Issues: Create an issue for bug reports and feature requests

License

MIT License


Made with ๐Ÿงก๏ธ by Claude & Me

ZePrompter - Making AI prompt management simple and powerful ๐Ÿš€

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

ze_prompter-0.1.0.tar.gz (29.7 kB view details)

Uploaded Source

Built Distribution

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

ze_prompter-0.1.0-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file ze_prompter-0.1.0.tar.gz.

File metadata

  • Download URL: ze_prompter-0.1.0.tar.gz
  • Upload date:
  • Size: 29.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for ze_prompter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e61fb9f0c548ff3ffc4ab0f0eadb2af3245c3f2675eb79e57d1be4dcbd82a1de
MD5 01909ca8e1c91b0fc0038e351d4323e6
BLAKE2b-256 805a9f192b5d0fd7415cdc5fd9f31de59a9219fed269741597ce339f588bf3b1

See more details on using hashes here.

File details

Details for the file ze_prompter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ze_prompter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for ze_prompter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3928766e7b75b818e02cca08420379c1f4776712c36086d7f41b8b4fe9ddba77
MD5 1a16d75bcf958ac9066e461b55ac63fa
BLAKE2b-256 7d042610c68de34fc2522ebd38e2169d73ef63bbc1bcf640ed33f81003985862

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