Airtable

This article covers all the necessary steps to connect to Airtable and query Airtable data with Python from inside DataLab. These steps and the necessary sample code are also available in this workbook (click this link to create your own copy).

Setup

You need to take a couple of setup steps in Airtable and DataLab to set up a so-called personal access token that you can use to programmatically access data in Airtable.

  • Create an Airtable account if you haven't already here.

  • Make sure your Airtable account contains a 'base' (a database). If you don't have data lying around, click "Start with templates" on your Airtable Homepage.

  • Create the personal access token:

    • Click on your avatar icon top right, and select "Developer Hub"

    • In the "Personal access tokens" tab, click "Create new token"

    • Specify a name for your token, e.g. 'DataLab Access'

    • Add a scope. data.records:read is enough if you want to fetch data from Airtable. If you also want to write back results of your calculations to Airtable, add data.records:write as well.

    • Add a base to access. You can select just one base or all current and future bases in your workbook. Make sure you at least select the base that you want to access from inside DataLab.

    • Click "Create token"

    • Copy the generated personal access token (PAT) to your clipboard for later use.

  • Securely store the PAT in DataLab as an environment variable:

    • In the DataLab editor, open the 'Environment' side panel and click on "+" next to "Environment variables"

    • Set Name to AIRTABLE_PAT

    • In Value paste the PAT that you copied to your clipboard in the previous step.

    • Set the "Environment Variable Set Name" to something meaningful, e.g. "Airtable PAT"

    • Click "Create", "Next" and finally, "Connect". Your workbook session will restart, and AIRTABLE_PAT will now be available as an environment variable in your workbook.

If you've done all of the steps above successfully, you're now ready to run some Python code to connect to Airtable data! The code is available in this workbook; you can click this link to create your own copy that you can edit to your use case.

Last updated