|
| 1 | +--- |
| 2 | +sidebar_position: 3 |
| 3 | +sidebar_label: Python |
| 4 | +description: "Get started with the Python SDK for PromptQL." |
| 5 | +keywords: |
| 6 | + - hasura ddn |
| 7 | + - promptql apis |
| 8 | + - apis |
| 9 | + - sdk |
| 10 | + - python |
| 11 | +--- |
| 12 | + |
| 13 | +# Python SDK |
| 14 | + |
| 15 | +## Introduction |
| 16 | + |
| 17 | +The Python SDK is available [here](https://pypi.org/project/promptql-api-sdk/). |
| 18 | + |
| 19 | +:::info The Python SDK currently supports the Natural Language API |
| 20 | + |
| 21 | +Support for the Execute Program API will be released soon. |
| 22 | + |
| 23 | +::: |
| 24 | + |
| 25 | +## Install |
| 26 | + |
| 27 | +```sh title="The SDK can be installed using pip:" |
| 28 | +pip install promptql-api-sdk |
| 29 | +``` |
| 30 | + |
| 31 | +```sh title="Or Poetry:" |
| 32 | +poetry add promptql-api-sdk |
| 33 | +``` |
| 34 | + |
| 35 | +## Connect |
| 36 | + |
| 37 | +```python title="You'll connect to an instnace by creating a client:" |
| 38 | +from promptql_api_sdk import PromptQLClient |
| 39 | +from promptql_api_sdk.types.models import HasuraLLMProvider |
| 40 | + |
| 41 | +# Initialize the client |
| 42 | +client = PromptQLClient( |
| 43 | + api_key="your-promptql-api-key", |
| 44 | + ddn_url="your-ddn-url", |
| 45 | + llm_provider=HasuraLLMProvider(), |
| 46 | + timezone="America/Los_Angeles", |
| 47 | +) |
| 48 | +``` |
| 49 | + |
| 50 | +## Query the Natural Language API |
| 51 | + |
| 52 | +```python title="Then, use your client to query the Natural Language API:" |
| 53 | +# Send a simple query |
| 54 | +response = client.query("What is the average temperature in San Francisco?") |
| 55 | +print(response.assistant_actions[0].message) |
| 56 | + |
| 57 | +# Use streaming for real-time responses |
| 58 | +for chunk in client.query("Tell me about the weather in New York", stream=True): |
| 59 | + if hasattr(chunk, "message") and chunk.message: |
| 60 | + print(chunk.message, end="", flush=True) |
| 61 | +``` |
0 commit comments