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


You need to take a couple of setup steps in Airtable and Workspace 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. 'DataCamp Workspace 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 workspace. Make sure you at least select the base that you want to access from inside Workspace.
    • Click "Create token"
    • Copy the generated personal access token (PAT) to your clipboard for later use.
Create a Personal Access Token in Airtable
  • Securely store the PAT in Workspace as an environment variable:
    • In the Workspace 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 workspace session will restart, and AIRTABLE_PAT will now be available as an environment variable in your workspace.
Store the Airtable PAT in Workspace as an environment variable
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 workspace; you can click this link to create your own copy that you can edit to your use case.