PromptQL Natural Language API SDK for Python
A Python SDK for interacting with the PromptQL Natural Language API.
Installation
pip install promptql-api-sdk
Or with Poetry:
poetry add promptql-api-sdk
Features
- Full support for the PromptQL Natural Language API (v1 and v2)
- Type-safe interface with Pydantic models
- Support for streaming responses
- Conversation management
- Support for all LLM providers (Hasura, Anthropic, OpenAI)
- Support for build-based configuration (v2 API)
Quick Start
v2 API (Recommended)
The v2 API uses build-based configuration and is the recommended approach:
from promptql_api_sdk import PromptQLClient
# Initialize the client with build version
client = PromptQLClient(
api_key="your-promptql-api-key",
build_version="your-build-version", # or use build_id=UUID("your-build-id")
timezone="America/Los_Angeles",
)
# Send a simple query
response = client.query("What is the average temperature in San Francisco?")
print(response.assistant_actions[0].message)
# Use streaming for real-time responses
for chunk in client.query("Tell me about the weather in New York", stream=True):
if hasattr(chunk, "message") and chunk.message:
print(chunk.message, end="", flush=True)
Note: To use applied build, do not specify build_version or build_id.
client = PromptQLClient(
api_key="your-promptql-api-key",
timezone="America/Los_Angeles",
)
v1 API (Legacy)
The v1 API requires DDN /v1/sql URL and explicit LLM provider configuration:
from promptql_api_sdk import PromptQLClient
from promptql_api_sdk.types.models import HasuraLLMProvider
# Initialize the client
client = PromptQLClient(
api_key="your-promptql-api-key",
ddn_url="your-ddn-url/v1/sql",
llm_provider=HasuraLLMProvider(), # Required for v1 API
timezone="America/Los_Angeles",
)
# Send a simple query
response = client.query("What is the average temperature in San Francisco?")
print(response.assistant_actions[0].message)
Private DDN
If you are using a private DDN, you need to provide the base URL for the PromptQL API:
client = PromptQLClient(
api_key="your-promptql-api-key",
build_version="your-build-version",
timezone="America/Los_Angeles",
api_base_url="https://promptql.fqdn.hasura.app/api",
)
Note: The api_base_url should not include the /query endpoint.
For more details refer to the PromptQL API Endpoint documentation.
Conversation Management
The SDK provides a Conversation class to help manage multi-turn conversations:
# Create a conversation
conversation = client.create_conversation(
system_instructions="You are a helpful assistant that provides weather information."
# Note: system_instructions are ignored in v2 API as they come from build's PromptQL config
)
# Send messages in the conversation
response = conversation.send_message("What's the weather like in London?")
print(response.message)
# Send a follow-up message
response = conversation.send_message("How about tomorrow?")
print(response.message)
# Get all artifacts created during the conversation
artifacts = conversation.get_artifacts()
LLM Provider Configuration (v1 API only)
The SDK supports multiple LLM providers for v1 API:
from promptql_api_sdk.types.models import HasuraLLMProvider, AnthropicLLMProvider, OpenAILLMProvider
# Hasura (default)
hasura_provider = HasuraLLMProvider()
# Anthropic
anthropic_provider = AnthropicLLMProvider(api_key="your-anthropic-api-key")
# OpenAI
openai_provider = OpenAILLMProvider(api_key="your-openai-api-key")
# Use with the client (v1 API only)
client = PromptQLClient(
api_key="your-promptql-api-key",
ddn_url="your-ddn-url/v1/sql",
llm_provider=anthropic_provider,
)
Note: In v2 API, LLM configuration is managed through the DDN build's PromptQL settings.
API Version Differences
v2 API (Recommended)
- Uses build-based configuration (
build_versionorbuild_id) (optional, uses applied build if not specified) - LLM configuration and system instructions come from build's PromptQL config
v1 API (Legacy)
- Uses direct DDN
/v1/sqlURL - Requires explicit LLM provider configuration
- System instructions specified in requests
Error Handling
from promptql_api_sdk import PromptQLClient
from promptql_api_sdk.exceptions import PromptQLAPIError
client = PromptQLClient(...)
try:
response = client.query("What is the weather like?")
except PromptQLAPIError as e:
print(f"API Error: {e}")
License
MIT
Metadata
Release files for promptql-api-sdk 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| promptql_api_sdk-0.2.0.tar.gz | 9.5 kB | Without provenance | Details for promptql_api_sdk-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| promptql_api_sdk-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for promptql_api_sdk-0.2.0-py3-none-any.whl |
Total release size: 20.3 kB
Release files / promptql_api_sdk-0.2.0.tar.gz
| Download URL | promptql_api_sdk-0.2.0.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3362ce324268a0f0ba48105e36925490c854cfef34ad6b62bc5e74ea7182a7e4
|
|
BLAKE2b-256 checksum How to use checksums |
ba0ef1e7a27cc4de11c861b3ff05c080be4d329ad0fc5334355a6788389edc8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.13.5 Linux/6.15.7-arch1-1
|
Release files / promptql_api_sdk-0.2.0-py3-none-any.whl
| Download URL | promptql_api_sdk-0.2.0-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
713163a2d6185e0baf50afacf3a3c46911f7ff7158e3213832f60ec2de0dee07
|
|
BLAKE2b-256 checksum How to use checksums |
0d55ee3e8bf4e0300d333e06e8cfa499adc9e049391477528688ac4788518105
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.13.5 Linux/6.15.7-arch1-1
|
Security for promptql-api-sdk 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.