Share on facebook
Share on linkedin
Share on twitter
Share on reddit

Connecting Python to superQuery

These instructions explain how to connect your Python account to superQuery’s query optimization engine.
When connected, your queries will pass through superQuery — where it will be automatically optimized — before being executed in BigQuery. 

The result: a significant reduction in query costs and execution time.


  1. Click on the Integrations link in the sidebar of superQuery:

  2. Enable your desired connection by clicking “Connect”
  3. After clicking “Connect” you’ll see the username and password screen, like so:



  1.  Whitelist your IP Address if necessary
  2.  Copy the hostname and port from this window into your service of choice.
    • server:
    • port: 3306

6.  Finalize the connection.


  • Download python3
  • python3 packages to install:
    • pymysql

Connecting to superQuery from python

  1. Create and run this python script:
    import pymysql.cursors 
    # Connect to the database.
    connection = pymysql.connect(host='',
    print ("connection successful!")
       with connection.cursor() as cursor:
           # SQL
           sql = "SELECT COUNT(*) FROM `yourproject.yourdataset.yourtable`"
           # Execute query.
           print ("cursor.description: ", cursor.description)
           for row in cursor:
           # SQL
           sql = "explain;"
           # Execute query.
           print ("cursor.description: ", cursor.description)
           for row in cursor:
       # Close connection.
  2. Enter the following details into the script:
    1. Your username and password into the ‘xxxx’ parts
    2. yourproject, yourdataset and yourtable into the indicated parts of the script.
  3. Run the script and you will see the query results displayed:

    1. First the query result then

    2. The query “explain” result containing query statistics and the execution plan information.

      An example of the query results and the “explain” result can be seen below.

      Query result:

      {'f0_': 5129852580}

      Explained results:

      {'statistics': '
      "cacheLastUpdateTime":"2019-03-14 08:27:47.755",

Boom! You’re all set.

Query on! 🙂

We use 🍪 to ensure you get the best experience.