# 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](https://app.datacamp.com/workspace/w/7417723b-2447-4b30-ad0c-3f8cf1ea53ec/edit) (click [this link](https://app.datacamp.com/workspace/new?_tag=workspace\&title=Connect%20to%20Airtable\&accountType=personal\&utm_content=copy_duplicate_link\&utm_medium=in_product\&utm_source=workspace\&visibility=public\&workspaceId=7417723b-2447-4b30-ad0c-3f8cf1ea53ec) 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](https://airtable.com/signup).
* 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.

<figure><img src="https://4179539225-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZqboFGZzD87nn7oPsm%2Fuploads%2Fe96pqkvo0y1CuoQ916Zp%2Fairtable_pat.png?alt=media&#x26;token=c0294c9b-4802-4e05-b004-167511ad9c3b" alt=""><figcaption><p>Create a Personal Access Token in Airtable</p></figcaption></figure>

* Securely store the PAT in DataLab as an [environment variable](https://datalab-docs.datacamp.com/work/environment-variables):
  * In the DataLab editor, open up the environment variables in the menu bar (Environment > Environment variables) and click on "Add".
  * 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.

<figure><img src="https://4179539225-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZqboFGZzD87nn7oPsm%2Fuploads%2F1QRwJbtQpat3I0A8oAzg%2Fairtable_pat_env.png?alt=media&#x26;token=4e4d1c3b-a152-4f78-ae91-b7ad0c34bfa3" alt=""><figcaption><p>Store the Airtable PAT in DataLab as an environment variable</p></figcaption></figure>

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](https://app.datacamp.com/workspace/w/7417723b-2447-4b30-ad0c-3f8cf1ea53ec/edit); you can click [this link](https://app.datacamp.com/workspace/new?_tag=workspace\&title=Connect%20to%20Airtable\&accountType=personal\&utm_content=copy_duplicate_link\&utm_medium=in_product\&utm_source=workspace\&visibility=public\&workspaceId=7417723b-2447-4b30-ad0c-3f8cf1ea53ec) to create your own copy that you can edit to your use case.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://datalab-docs.datacamp.com/connect-to-data/airtable.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
