AskTable
sidebar.freeTrial

Query MySQL with Python and AskTable in 20 Minutes

AskTable Team
AskTable Team 2025-03-27

Here is a Python-first walkthrough: install AskTable, connect MySQL, and query with natural language—in three steps.

Step 1: Install AskTable locally (~10 minutes)

(If you use SaaS, skip this.)
Docs: https://docs.asktable.com/docs/pricing-and-deployment/private-deployment-all-in-one

After install, sign in with the default account, open Project settings, create an API key, and keep it handy.

Step 2: Add a database (~5 minutes)

Use the web UI:

  1. Open your AskTable URL (local or cloud).
  2. Click Add data and enter connection details—host, port, user, password, etc.

Add database

Step 3: Query in natural language (~5 minutes)

Install the Python SDK:

pip install asktable

Query with a few lines:

from asktable import Asktable

# Initialize the client
at = Asktable(api_key="<ASKTABLE_API_KEY>")

# Datasource ID and question
datasource_id = "<YOUR_DATASOURCE_ID>"
question = "How many users registered today?"

# Run the query
answer = at.answers.create(
    datasource_id=datasource_id,
    question=question
).answer

print(answer.text)

Bonus: generate SQL (~5 minutes)

sql = at.sqls.create(
    datasource_id=datasource_id,
    question=question
).query

print(sql.prepared_statement)

cta.readyToSimplify

sidebar.noProgrammingNeededsidebar.startFreeTrial

cta.noCreditCard
cta.quickStart
cta.dbSupport