Skip to main content

A lightweight library for LLM prompt management, observability/tracing, and optimization

Project description

promptly

A lightweight, developer-friendly library for LLM prompt management, observability/tracing, and optimization. Currently with support for Python.

Features

  • Prompt Templates: Jinja2-based templating system for dynamic prompts
  • Multi-Provider Support: OpenAI, Anthropic, Google AI (Gemini), and extensible client architecture
  • Built-in Tracing: Comprehensive observability for prompt execution
  • Genetic Optimization: LLM-powered genetic algorithms for automated prompt improvement
  • Async Support: Full async/await support for high-performance applications
  • CLI Interface: Command-line tools for prompt management
  • Type Safety: Full type hints and Pydantic models

Installation

# Install UV if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install promptly
uv pip install promptly

# With development dependencies
uv pip install promptly[dev]

# With CLI tools
uv pip install promptly[cli]

# With UI components
uv pip install promptly[ui]

Quick Start

import asyncio
from promptly import PromptRunner, OpenAIClient, PromptTemplate

async def main():
    # Initialize client
    client = OpenAIClient(api_key="your-api-key")

    # Create a prompt template
    template = PromptTemplate(
        name="greeting",
        template="Hello {{ name }}, how are you today?",
        variables=["name"]
    )

    # Create runner with tracing
    runner = PromptRunner(client)

    # Execute prompt
    response = await runner.run(
        template=template,
        variables={"name": "Alice"},
        model="gpt-3.5-turbo"
    )

    print(response.content)

asyncio.run(main())

Prompt Optimization

Promptly includes an advanced genetic algorithm optimizer that uses LLMs to automatically improve your prompts through iterative evaluation and mutation. The optimizer can work with test cases for accuracy-based optimization or without test cases for general quality improvement.

Quick Example:

# Optimize with test cases
promptly optimize \
  --base-prompt "Answer this question: {{question}}" \
  --test-cases my_tests.json \
  --population-size 10 \
  --generations 5

# Quality-based optimization (no test cases needed)
promptly optimize \
  --base-prompt "Write a {{genre}} story about {{character}}" \
  --population-size 8 \
  --generations 4

For complete documentation on optimization features, configuration options, and examples, see OPTIMIZER_README.md.

CLI Usage

# Run a simple prompt
promptly run "What is the capital of France?" --model="gpt-3.5-turbo"

# Run with tracing
promptly run "Explain quantum computing" --trace

# View traces
promptly trace

Development

For developers who want to contribute to or extend promptly:

License

MIT License - see LICENSE file for details.

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

promptly_llm-0.2.0.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

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

promptly_llm-0.2.0-py3-none-any.whl (34.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: promptly_llm-0.2.0.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for promptly_llm-0.2.0.tar.gz
Algorithm Hash digest
SHA256 60d97845dccb382a995df45c162fb1553a502abaa9921186921ad5a6c8a1ce9e
MD5 9c02fb10ba4eac1b1d83dd9e621befa5
BLAKE2b-256 4e330d27cd6bffdc234b2329c096da2b7bef07e0286de01b20adc66e85c236b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptly_llm-0.2.0.tar.gz:

Publisher: release.yml on orgpromptly/promptly

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: promptly_llm-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 34.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for promptly_llm-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 716c6cf8ea23b5072a110f20bae3d2ef77def51e2252b1591f35abb4a158f261
MD5 afe0ba53ce60cf3ab8b6101f28564fc1
BLAKE2b-256 33478a22a7d585fbd9fdbda00d061170bc4e4a9e5b33d24c8d3f7b872636a8c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptly_llm-0.2.0-py3-none-any.whl:

Publisher: release.yml on orgpromptly/promptly

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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