2 min to read
Airtable Explained
A breakdown of Pyairtable and the Airtable API.

Airtable
Airtable is a cloud native spreadsheet tool, that mimics excel and is being used by some teams as a database. At The Giving Closet Project we identified that there was an opportunity for us to improve the way that we were fulfilling requests for students’ clothing. Airtable came in as a quick and efficient way for us to organize and order workflows to make it easier for volunteers to get work done.
The API
Pyairtable
The Airtable python library makes airtbale’s easy API even easier. In just a few lines you can do most of what is needed to write records to an airtable. You can pass records to a table using a list of dictionaries - where the key is the name of the column and the value is the data that will go in the field. Airtable only allows you to insert 10 records at one time - pyairtable will handle this restriction for you. Meaning you can pass as many dicts to the batch_create method as you want.
records = [{key: value}, {key: value}]
table = pyairtable.Table(api_key=os.environ['airtable_id'], base_id=base, table_name=table)
table.batch_create(records=records)
Reading from the airtable is easy to do as well. The following snippet shows how you can retrieve all the records from a table.
table = pyairtable.Table(api_key=os.environ['airtable_id'], base_id=base, table_name=table)
records = table.all()
It uses pyairtable’s iterate method to get every record that exists on the table. Remember that this is going to consume multiple calls which count toward your API limits.
Concerns About Constraints
I do have one glaring issue with Airtable - the unique key. Airtable’s docs state that the first column in a table is unique. This isn’t the case, and it’s wild to me that they say it is. I like what you can do with airtable, but there is no constraint on the unique field. Which means that you can add duplicate records to the table.
For those of you that haven’t worked with databases - constraints are important because they ensure that you aren’t duplicating data on your tables. Without the ability to enforce uniqueness airtable can’t be trusted unless you write aditional code to check the tables before writes and enforce constraints on your own.