Skip to content

Data Sources

import groundwork.contrib.airtable.datasources

airtable_field

airtable_field(
name: str, **kwargs: Dict[str, Any]) ‑> dataclasses.Field

Return a dataclass field used to annotate a Resource class with the name of the column in Airtable.

For example, if you have an Airtable like this:

First Name Last Name
Stafford Beer
Clara Zetkin

You could map it onto a django model like this:

@dataclass
class People:
    id: str
    first_name: str = airtable_field('First Name')
    last_name: str = airtable_field('Last Name')

If you do not annotate your field like this, AirtableDatasource will expect your column in Airtable to have the same name as your Resource class.

Parameters

name
Airtable column name associated with this field.
kwargs
Keyword args passed to dataclasses.field.
Returns
A dataclass field descriptor identifying the corresponding Airtable column.

AirtableDatasource

Base class for implementing clients to Airtable bases and converting their responses to resource objects.

You are encouraged to use Python's inbuilt @dataclass decorator and define type hints when defining these classes as this allows type-safe serializers to be auto-generated and decreases the amount of boilerplate code that you need to write.

Example:

Let's assume we have a public airtable with the base id 4rQYK6P56My. It contains a table called 'Active Members', which looks like this:

First Name Last Name
Stafford Beer
Clara Zetkin

We can create a datasource for it as follows:

from dataclasses import dataclass
from groundwork.contrib.airtable.datasources import AirtableDatasource, airtable_field

@dataclass
class Person:
    id: str
    first_name: str = airtable_field('First Name')
    last_name: str = airtable_field('Last Name')

my_datasource = AirtableDatasource(
    base_id="4rQYK6P56My",
    table_name="Active Members",
    resource_class=Person,
)

As with other datasource types, configuration can all either be provided as keyword-args to the constructor, or overridden in subclasses.

Inherits:

Constructor:

AirtableDatasource(resource_type: ~ResourceT, base=None, table=None, **kwargs)

Class variables

api_key

str

Airtable API key. Required for private Airtable bases. If not defined, will default to the value of django.conf.settings.AIRTABLE_API_KEY.

base_id

Optional[str]

ID of the airtable base. You can find this in your base's API Docs

table_name

Optional[str]

Name of the table to fetch from.