Using our SDK
How to use the Parallel SDK
Getting Started
Installing the SDK client
To get started, reach out to our team for access to the SDK.
pip install -U <path to your .whl file>
Initialize the client
To begin using the SDK, initialize the client with your API key:
from parallel_beta import Parallel
client = Parallel(api_key="your-api-key")
Tasks
Create a task
Creates a new task with a specification and input/output schemas:
task = client.tasks.create(
name="Budget",
description="Get budget for a city",
prompt="What was the budget for {city} in {year}?",
input_schema={
"properties": {
"city": {"type": "string"},
"year": {"type": "string"}
},
"required": ["city", "year"],
"additionalProperties": False,
"type": "object"
},
output_schema={
"properties": {
"budget": {"type": "string"},
"evidence": {"type": "string"},
"reasoning": {"type": "string"}
},
"type": "object"
}
)
Retrieve Task
Fetches an existing task by its ID:
task = client.tasks.retrieve(task_id="task_id")
Understanding Task Objects
Task objects contain information about the task, including its ID, name, description, and schema:
Task(
task_id="task-id",
name="Budget",
description="Get budget for a city",
prompt="What was the budget for {city} in {year}?",
input_schema={
"additionalProperties": False,
"type": "object",
"properties": {
"city": {"type": "string"},
"year": {"type": "string"}
},
"required": ["city", "year"]
},
output_schema={
"type": "object",
"properties": {
"budget": {"type": "string"},
"evidence": {"type": "string"},
"reasoning": {"type": "string"}
}
},
functions=[],
metadata={},
warnings=[],
)
Task Runs
Create Run
There are several ways to create a task run:
Standard synchronous run - Waits for completion:
task_run = client.tasks.runs.create(
task_id="task_id",
runner="helium",
arguments={
"city": "New York City",
"year": "2023"
}
)
Enqueue run - Returns immediately with a run id and executes the run asynchronously:
task_run = client.tasks.runs.create(
task_id="task_id",
runner="helium",
arguments={
"city": "New York City",
"year": "2023"
},
enqueue_run=True
)
Retrieve Run
Retrieves the current state and output of a task run:
run = client.tasks.runs.retrieve(
task_id="task_id",
run_id="run_id"
)
Understanding Task Run Objects
Task run objects contain information about the task and run status, including IDs, state, and output:
TaskRun(
# Run Status - possible values: queued, running, complete, failed
status="queued",
# Task and Run IDs
task_id="6e16dd09-92d7-4a72-9541-25cab5d3257a",
run_id="feb0cae1-8524-12d2-6941-1d7daf63d049",
# Runner/Processor used
runner="neon",
# Task output (if completed)
output={
"budget": "$232.9 billion",
"evidence": "https://nyassembly.gov/Reports/...",
"reasoning": "The budget for New York in 2023 consists of both ..."
}, # or None if not completed
modified_at=datetime.datetime(2025, 1, 31, 21, 12, 54, 907024)
)
The output will correspond to the output schema provided during task creation.
City Budget document finder
This example demonstrates how to create a task to find the most recent official budget document for a city/town. It first creates a task, then runs it for a list of cities, and finally displays the results in a table.
Note: The python code example requires the package rich
to be installed. The TypeScript code example
requires the package cli-table3
to be installed.
import time
from typing import List, Tuple
from parallel_beta import Parallel
from rich.console import Console
from rich.live import Live
from rich.table import Table
PARALLEL_API_KEY = "your-api-key"
task_spec = """
Find the most recent official budget document for the specified city/town.
City Name: ${City_Name}
State: ${State}
Domain (if provided): ${Domain}
Requirements:
1. The budget document must be from an official government source
2. Verify the document is the most recent available budget
3. Ensure the URL points directly to the budget document (PDF or similar)
4. If multiple budget documents exist (e.g. proposed vs adopted), prefer the final/adopted version
Please:
1. Search the official city/town government website
2. Verify the website is authentic (proper .gov domain or matches provided domain)
3. Navigate to the finance/budget section
4. Locate the most recent budget document
5. Verify the document is an official budget (not a draft/proposal unless that's the only available version)
"""
console = Console()
def create_city_budget_task(client: Parallel):
"""Creates a task for finding city budget documents using the Parallel SDK"""
task = client.tasks.create(
name="City Budget Document Finder",
description="Locate official municipal budget documents from government sources",
processor="neon",
prompt=task_spec,
input_schema={
"properties": {
"City_Name": {"type": "string", "description": "Name of the city"},
"State": {
"type": "string",
"description": "State where the city is located",
},
"Domain": {
"type": "string",
"description": "Official domain of the city government",
},
},
"required": ["City_Name", "State"],
"type": "object",
},
output_schema={
"properties": {
"budget_year": {
"type": "string",
"description": "The year of the most recent budget document",
},
"budget_url": {
"type": "string",
"description": "Direct URL to the official budget document",
},
"source_validity": {
"type": "string",
"description": "Explanation of why this is an official source",
},
"last_updated": {
"type": "string",
"description": "When this information was last verified (YYYY/MM)",
},
},
"type": "object",
},
timeout=10,
)
return task
def run_budget_search(client: Parallel, cities: List[Tuple[str, str, str]]):
"""Run budget document search for multiple cities"""
# Create the task
task = create_city_budget_task(client)
results = []
# Run task for each city
for city_name, state, domain in cities:
try:
# Enqueue task runs to execute in parallel
run = client.tasks.runs.create(
task_id=task.task_id,
arguments={"City_Name": city_name, "State": state, "Domain": domain},
runner="neon",
enqueue_run=True,
timeout=10,
)
results.append(run)
except Exception as e:
console.print(f"[red]Error processing {city_name}, {state}: {str(e)}[/]")
return results, task.task_id
def display_results(results: List[dict], cities: List[Tuple[str, str, str]]):
"""Display results in a formatted table"""
table = Table(show_header=True, header_style="bold magenta")
table.add_column("City")
table.add_column("State")
table.add_column("Budget Year")
table.add_column("URL")
table.add_column("Last Updated")
table.add_column("Status")
table.add_column("Run ID")
for idx, result in enumerate(results):
city_name, state, _ = cities[idx]
try:
default_value = "N/A" if "complete" in result.status else "Pending"
output = result.output or {}
table.add_row(
city_name,
state,
output.get("budget_year", default_value),
output.get("budget_url", default_value),
output.get("last_updated", default_value),
result.status,
result.run_id,
)
except Exception as e:
table.add_row(
city_name, state, "Error", str(e), default_value, "failed", "N/A"
)
return table
def main():
# Initialize client
client = Parallel(api_key=PARALLEL_API_KEY)
# Define test cities
test_cities = [
("City of Fairhope", "AL", "fairhopeal.gov"),
("Charter Township of Fenton", "MI", "fentontownship.org"),
("City of Foley", "AL", "cityoffoley.org"),
# ... add more cities as needed
]
console.print("[bold green]Starting budget document search...[/]")
# Run the search
results, task_id = run_budget_search(client, test_cities)
run_ids = [result.run_id for result in results]
console.print(f"\n[bold blue]Results for task id {task_id}:[/]")
# Poll for results and update a table in real time
with Live(display_results(results, test_cities), refresh_per_second=1) as live:
while not all("complete" in result.status for result in results):
time.sleep(1)
results = [
client.tasks.runs.retrieve(task_id=task_id, run_id=run_id)
for run_id in run_ids
]
live.update(display_results(results, test_cities))
# keep the live view open so the complete table can auto-resize
console.input()
if **name** == "**main**":
main()
Example output:
Starting budget document search...
Results for task id 0c274fd9-6568-4c1b-a675-de8918e403d2:
| City | State | Budget Year | URL | Last Updated | Status | Run ID |
|------|--------|-------------|-----|--------------|---------|---------|
| City of Fairhope | AL | 2024 | <https://publicrecords.fairhopeal.gov/WebLink/DocView.aspx?id=22101&dbid=0&repo=Fairhope> | 2023-10-16 | complete | 9e8a7ab1-63bf-4f94-b178-41393884b6a6 |
| Charter Township of Fenton | MI | 2025 | <https://www.fentontownship.org/media/11741> | 2024-11-19 | complete | 89ba3eb4-8784-4041-8ae7-7b2af5a847a2 |
| City of Foley | AL | 2024 | <https://cityoffoley.org/wp-content/uploads/2024/01/FY2024-City-of-Foley-Budget-Award-Presentation.pdf> | 2024-01-30 | complete | 0fe28013-5d64-4c27-8696-e7f2ce39e19d |