Quick Start Guide for Python SDK
Introduction
With the Python SDK from AskTable, you can quickly start interacting with AskTable. This guide will walk you through some basic operations.
Other references:
Prerequisites
- The AskTable Python SDK is installed. Please refer to the Installation Guide.
Quick Start Example
-
Initialize the SDK
from asktable import Asktable
# Replace with your API-Key
api_key = 'API_KEY_or_TEMP_TOKEN'
api_url = 'https://api.asktable.com/v1'
at = Asktable(api_key=api_key, base_url=api_url) -
List Data Sources
datasources = at.datasources.list()
for ds in datasources.items:
print(f"ID: {ds.id}, Name: {ds.name}") -
Create a Data Source
new_datasource = at.datasources.create(
name='NewDataSource',
engine='excel',
access_config={
"location_url": "your-excel-file-url",
"location_type": "http"
}
)
print(f"Created DataSource ID: {new_datasource.id}") -
Quick Query
answer = at.single_turn.q2a.create(
question="your-question",
datasource_id="your-datasource-id"
)
print(answer.text) -
Create a Bot
datasource_ids = ['ds_1']
bot = at.bots.create(
datasource_ids=datasource_ids,
name="testt",
)
print(bot.id) -
Create a Chat
chat = at.chats.create(
bot_id=bot.id,
name="test",
)
print(chat.id) -
Conversation Query
msg = at.chats.messages.create(
chat_id=chat.id,
question="What is the score of the top student?",
)
print(msg.content['text'])
By following these steps, you can quickly get started and perform basic operations using the AskTable Python SDK.