Skip to main content

SDK for integrating with PromptCompose API to resolve and manage AI prompts.

Project description

PromptCompose SDK (Python)

Official Python SDK for integrating with the PromptCompose API to resolve and manage AI prompts with A/B testing capabilities.

Installation

pip install promptcompose

Quick Start

from promptcompose import PromptCompose

# Initialize the SDK
prompt_compose = PromptCompose(
    api_key='your-api-key',
    project_id='your-project-id',
    debug=True
)

# Initialize connection
prompt_compose.init()

# Resolve a prompt with variables
result = prompt_compose.resolve_prompt(
    prompt_id='prompt-id',
    config={
        'versionId': 'v1',
        'abTesting': {'enabled': False}
    },
    variables={
        'user_name': 'John',
        'product_name': 'Widget'
    }
)

print(result.content)

Features

  • Prompt Resolution: Resolve prompts with dynamic variable interpolation
  • A/B Testing: Built-in support for A/B testing with multiple rollout strategies
  • Version Management: Handle multiple prompt versions seamlessly
  • Type Hints: Full type hints included with comprehensive docstrings
  • IntelliSense: Complete IntelliSense support for all IDEs
  • Error Handling: Comprehensive error handling with detailed messages

API Reference

Constructor

PromptCompose(api_key: str, project_id: str, debug: bool = False)

Methods

init()

Performs initial handshake with the API to verify credentials.

list_prompts()

Retrieves all prompts for the project.

get_prompt(prompt_id: str)

Retrieves a specific prompt by ID.

resolve_prompt(prompt_id: str, config: Optional[PromptConfig] = None, variables: Optional[Dict[str, Union[str, int]]] = None)

Resolves a prompt with optional A/B testing and variable interpolation.

list_ab_tests()

Retrieves all A/B tests for the project.

get_ab_test(ab_test_id: str)

Retrieves a specific A/B test by ID.

report_ab_result(ab_test_id: str, result: ReportABResult)

Reports A/B test results for analytics.

A/B Testing

The SDK supports three A/B testing strategies:

  • Sequential: Tests variants in order
  • Weighted: Random selection with specified weights
  • Manual: Explicit variant selection
# Sequential A/B testing
result = prompt_compose.resolve_prompt('prompt-id', {
    'abTesting': {
        'sessionId': 'user-session-123'
    }
})

# Manual variant selection
result = prompt_compose.resolve_prompt('prompt-id', {
    'abTesting': {
        'variantId': 'variant-abc'
    }
})

Error Handling

The SDK provides detailed error messages for various scenarios:

  • ValidationError: Missing required variables or invalid configuration
  • APIError: Network or server errors
  • SDKError: General SDK errors

IntelliSense Support

The SDK provides comprehensive IntelliSense support for all Python IDEs:

Type Hints

  • Full type definitions with comprehensive docstrings
  • Autocomplete for all methods and properties
  • Type checking for parameters and return values
  • Import suggestions for all exported types
from promptcompose import PromptCompose, PromptConfig, ResolvedPrompt

# Full IntelliSense support with docstrings
sdk = PromptCompose('api-key', 'project-id')

# IntelliSense will show autocomplete for config.abTesting properties
config: PromptConfig = {
    'versionId': 'v1',
    'abTesting': {
        'enabled': False,
        'variantId': 'variant-123',
        'sessionId': 'session-456'
    }
}

result: ResolvedPrompt = sdk.resolve_prompt('prompt-id', config)

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

promptcompose-0.1.1.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

promptcompose-0.1.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file promptcompose-0.1.1.tar.gz.

File metadata

  • Download URL: promptcompose-0.1.1.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for promptcompose-0.1.1.tar.gz
Algorithm Hash digest
SHA256 48f778f6264370805467b265ed9623fea7c7ba429c20aa76c6d94aefdca75429
MD5 54fc1f727de90e308cf68149b7edf2cc
BLAKE2b-256 c972440d6043a5c954ff8c79f1d1126274b91b28b65916311785c416bb6ba267

See more details on using hashes here.

File details

Details for the file promptcompose-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: promptcompose-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for promptcompose-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 836580d999b2aa18a370e31225d4c3c56246514817bde5a0397ca64cd7b2aa30
MD5 789d63d001dde403e58865853f2d500a
BLAKE2b-256 e47740e82b11147437ec2d8efe183acf4052f80edf9feffc05442d98fecbaa15

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