Skip to main content
Version: 0.5.4 (latest)

Airtable

Need help deploying these sources, or figuring out how to run them in your data stack?
Join our Slack community or book a call with a dltHub Solutions Engineer.

Airtable is a cloud-based platform that merges spreadsheet and database functionalities for easy data management and collaboration.

This Airtable dlt verified source and pipeline example loads data using “Airtable API” to the destination of your choice.

Sources and resources that can be loaded using this verified source are:

NameDescription
airtable_sourceRetrieves tables from an Airtable base
airtable_resourceRetrives data from a single Airtable table

Setup Guide

Grab Airtable personal access tokens

  1. Click your account icon top-right.
  2. Choose "Developer Hub" from the dropdown.
  3. Select "Personal access token" on the left, then "Create new token".
  4. Name it appropriately.
  5. Add read scopes for "data records" and "schema bases".
  6. Add a base to specify the desired base for data access.
  7. Hit "Create token" and save the displayed token securely for credential use.

Note: The Airtable UI, which is described here, might change. The full guide is available at this link.

Grab Airtable IDs

Upon logging into Airtable and accessing your base or table, you'll notice a URL in your browser's address bar resembling:

https://airtable.com/appve10kl227BIT4GV/tblOUnZVLFWbemTP1/viw3qtF76bRQC3wKx/rec9khXgeTotgCQ62?blocks=hide

Between each slash, you'll find identifiers for the base, table, and view as explained in this documentation on finding Airtable IDs:

  • Base IDs start with "app", currently set to "appve10kl227BIT4GV".

  • Table IDs start with "tbl", currently set to "tblOUnZVLFWbemTP1".

  • View IDs start with "viw", currently set to "viw3qtF76bRQC3wKx".

  • Record IDs start with "rec", currently set to "rec9khXgeTotgCQ62".

    Airtable IDs

Initialize the verified source

To get started with your data pipeline, follow these steps:

  1. Enter the following command:

    dlt init airtable duckdb

    This command will initialize the pipeline example with Airtable as the source and duckdb as the destination.

  2. If you'd like to use a different destination, simply replace duckdb with the name of your preferred destination.

  3. After running this command, a new directory will be created with the necessary files and configuration settings to get started.

For more information, read the guide on how to add a verified source..

Add credentials

  1. In the .dlt folder, there's a file called secrets.toml. It's where you store sensitive information securely, like access tokens. Keep this file safe.

    Use the following format for service account authentication:

    [sources.airtable]
    access_token = "Please set me up!" # please set me up!
  2. Finally, enter credentials for your chosen destination as per the docs.

  3. Next you need to configure ".dlt/config.toml", which looks like:

    [sources.airtable]
    base_id = "Please set me up!" # The id of the base.
    table_names = ["Table1","Table2"] # A list of table IDs or table names to load.

    Optionally, you can also input "base_id" and "table_names" in the script, as in the pipeline example.

For more information, read the General Usage: Credentials.

Run the pipeline

  1. Before running the pipeline, ensure that you have installed all the necessary dependencies by running the command:

    pip install -r requirements.txt
  2. You're now ready to run the pipeline! To get started, run the following command:

    python airtable_pipeline.py
  3. Once the pipeline has finished running, you can verify that everything loaded correctly by using the following command:

    dlt pipeline <pipeline_name> show

    For example, the pipeline_name for the above pipeline example is airtable, you may also use any custom name instead.

For more information, read the guide on how to run a pipeline.

Sources and resources

dlt works on the principle of sources and resources.

Source airtable_source

This function retrieves tables from given Airtable base.

@dlt.source
def airtable_source(
base_id: str = dlt.config.value,
table_names: Optional[List[str]] = None,
access_token: str = dlt.secrets.value,
) -> Iterable[DltResource]:
...

base_id: The base's unique identifier.

table_names: A list of either table IDs or user-defined table names to load. If not specified, all tables in the schema are loaded.

access_token: Your personal access token for authentication.

Resource airtable_resource

This function retrieves data from a single Airtable table.

def airtable_resource(
api: pyairtable.Api,
base_id: str,
table: Dict[str, Any],
) -> DltResource:
...

table: Airtable metadata, excluding actual records.

Customization

Create your own pipeline

If you wish to create your own pipelines, you can leverage source and resource methods from this verified source.

  1. Configure the pipeline by specifying the pipeline name, destination, and dataset as follows:

    pipeline = dlt.pipeline(
    pipeline_name="airtable", # Use a custom name if desired
    destination="duckdb", # Choose the appropriate destination (e.g., duckdb, redshift, post)
    dataset_name="airtable_data" # Use a custom name if desired
    )
  2. To load the entire base:

    base_id = "Please set me up!"     # The id of the base.

    airtables = airtable_source(base_id=base_id)
    load_info = pipeline.run(load_data, write_disposition="replace")
  3. To load selected tables from a base table:

    base_id = "Please set me up!"     # The id of the base.
    table_names = ["Table1","Table2"] # A list of table IDs or table names to load.

    airtables = airtable_source(
    base_id = base_id,
    table_names = table_names
    )
    load_info = pipeline.run(airtables, write_disposition = "replace")

    You have the option to use table names or table IDs in the code above, in place of "Table1" and "Table2".

  4. To load data and apply hints to a specific column:

    base_id = "Please set me up!"       # The id of the base.
    table_names = ["Table1","Table2"] # A list of table IDs or table names to load.
    resource_name = "Please set me up!" # The table name we want to apply hints.
    field_name = "Please set me up!" # The table field name for which we want to apply hints.

    airtables = airtable_source(
    base_id="Please set me up!",
    table_names=["Table1","Table2"],
    )

    airtables.resources[resource_name].apply_hints(
    primary_key=field_name,
    columns={field_name: {"data_type": "text"}},
    )
    load_info = pipeline.run(airtables, write_disposition="replace")
    print(load_info)

Additional Setup guides

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.