Python SDK for the Abra-Q API — manage datasources, run queries, and handle IAM from Python and Jupyter notebooks
Project description
abra-q
Python SDK for the Abra-Q API — manage datasources, run natural-language queries, and handle IAM, all from Python or a Jupyter notebook.
Installation
pip install abra-q
Or with uv:
uv add abra-q
Quick Start
from abra_q import AbraQ
client = AbraQ("<host provided by AbraDynamics team>")
client.login("user@example.com", "password")
# List datasources
datasources = client.datasources.list()
# Ask a question in natural language
result = client.datasources.prompt("my-datasource-id", "Show me top 10 customers by revenue")
print(result["query"]) # Generated SQL
print(result["explanation"]) # AI explanation
# Run raw SQL
rows = client.datasources.query("my-datasource-id", "SELECT * FROM customers LIMIT 5")
Using in Jupyter Notebooks
from abra_q import AbraQ
client = AbraQ("<host provided by AbraDynamics team>")
client.login("analyst@company.com", "password")
# Natural-language query
result = client.datasources.prompt("sales-db", "Monthly revenue for the last year")
print(result["query"])
# Execute the generated query
data = client.datasources.query("sales-db", result["query"])
# Convert to pandas DataFrame (optional)
import pandas as pd
df = pd.DataFrame(data["rows"], columns=[c["name"] for c in data["columns"]])
df.head()
API Reference
Client
client = AbraQ(base_url, timeout=30)
client.login(email, password)
client.logout()
Datasources — client.datasources
| Method | Description |
|---|---|
list() |
List all accessible datasources |
get(id) |
Get datasource details |
create(...) |
Create a new datasource |
delete(id) |
Delete a datasource |
test_connection(...) |
Test connection before creating |
prompt(id, text) |
Generate SQL from natural language |
query(id, sql) |
Execute raw SQL |
enhance(id) |
AI-enhance table/column descriptions |
reacquaint(id) |
Resync schema |
sample_queries(id) |
Get sample queries |
generate_sample_queries(id) |
Generate sample queries with AI |
Datasets — client.datasets
| Method | Description |
|---|---|
parse(file_path) |
Parse a CSV/Excel file |
import_dataset(sheets=...) |
Import parsed data as a datasource |
Query Builder — client.query_builder
| Method | Description |
|---|---|
intelligent_prompt(prompt, datasource_ids) |
Multi-datasource natural language query |
list_sessions() |
List query builder sessions |
create_session() |
Create a new session |
get_session(id) |
Get session details |
Saved Queries — client.queries
| Method | Description |
|---|---|
get(query_id) |
Get a saved query |
execute(query_id) |
Execute a saved query |
Both accept an optional api_key parameter for agent-based authentication.
IAM — client.iam
Manage policies, roles, groups, agents, and user policies:
# Policies
client.iam.list_policies()
client.iam.create_policy(id="pol-1", name="ReadOnly", statement=[...])
# Roles
client.iam.list_roles()
client.iam.create_role(id="role-1", name="Analyst")
client.iam.attach_role_policy("role-1", "pol-1")
# Groups
client.iam.list_groups()
client.iam.add_user_to_group("group-1", "user-1")
# Agents (API keys)
client.iam.create_agent(id="bot-1", description="ETL bot")
client.iam.assign_agent_role("bot-1", "role-1")
Users — client.users
| Method | Description |
|---|---|
me() |
Get current user profile |
list() |
List all users |
create(email) |
Create a user |
delete(id) |
Delete a user |
change_password(current, new) |
Change password |
Preferences — client.preferences
| Method | Description |
|---|---|
get() |
Get all preferences |
set_llm_model(model) |
Set LLM model |
set_embedding_model(model) |
Set embedding model |
set_vector_threshold(label, threshold) |
Set similarity threshold |
Error Handling
from abra_q import AbraQ, AuthenticationError, PermissionDeniedError, NotFoundError
client = AbraQ("host provided by AbraDynamics team")
try:
client.login("user@example.com", "wrong-password")
except AuthenticationError as e:
print(f"Login failed: {e}")
try:
client.datasources.get("nonexistent-id")
except NotFoundError:
print("Datasource not found")
except PermissionDeniedError:
print("You don't have access")
License
Apache 2.0
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 abra_q-0.1.0.tar.gz.
File metadata
- Download URL: abra_q-0.1.0.tar.gz
- Upload date:
- Size: 72.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ebb601f4dc0d45fb71e7f60988c56f7927e435a0474ab587934a859a63409b8
|
|
| MD5 |
8c2ae1ae595a9ee7f532ba149014ca47
|
|
| BLAKE2b-256 |
1247733ecae6b484a0bfdb754abeabeb82c7a2ba019e5418629847176a37de19
|
File details
Details for the file abra_q-0.1.0-py3-none-any.whl.
File metadata
- Download URL: abra_q-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08e5d88dcbfc5c2b11c624e3834568e79ebf786145081abfe8f3809ec0c0eb10
|
|
| MD5 |
b5f0e500325fc7f6e774d0ad0a580a90
|
|
| BLAKE2b-256 |
c7c27c30275df62c77f292b7c252957522dbe3402bd50dbed764c29c3d20e2b2
|