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-sdk
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={
'version_id': 'v1',
'ab_testing': {'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', {
'ab_testing': {
'session_id': 'user-session-123'
}
})
# Manual variant selection
result = prompt_compose.resolve_prompt('prompt-id', {
'ab_testing': {
'variant_id': 'variant-abc'
}
})
Error Handling
The SDK provides detailed error messages for various scenarios:
ValidationError: Missing required variables or invalid configurationAPIError: Network or server errorsSDKError: 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.ab_testing properties
config: PromptConfig = {
'version_id': 'v1',
'ab_testing': {
'enabled': False,
'variant_id': 'variant-123',
'session_id': 'session-456'
}
}
result: ResolvedPrompt = sdk.resolve_prompt('prompt-id', config)
License
MIT
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 promptcompose-0.1.0.tar.gz.
File metadata
- Download URL: promptcompose-0.1.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f924ed24a8a5956dd71677f511fce6091fa79cdb7db9c57d417c5e83aba9fbf
|
|
| MD5 |
9ece6501b2f7e63c0e7e99ccc7351c08
|
|
| BLAKE2b-256 |
458ad1afa2cfe9b50836e9f9cae3c0f843d969ce528c81fcfc5e11b5fda349bc
|
File details
Details for the file promptcompose-0.1.0-py3-none-any.whl.
File metadata
- Download URL: promptcompose-0.1.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f51aee34a8feb6b561c0b843fc6c46ae23518e2d8e79e92e679c7e0fdabcc0ce
|
|
| MD5 |
deeaf586f36d67e327951e96fd324ae8
|
|
| BLAKE2b-256 |
b9c55dfda1362b5881933ca6fc47c68a17d96b7c39a761998e092fd59614de94
|