Getting Started¶
Installation¶
Add the pyAirtable library to your project just as you would any other:
$ pip install pyairtable
Access tokens¶
To begin, you will need an API key or a personal access token. If you do not have one yet, see the Airtable guide to personal access tokens.
This library will not persist your access token anywhere. Your access token should be securely stored.
A common method is to store it as an environment variable
and load it using os.environ
.
Note
Airtable has deprecated API keys and they will stop working with in February 2024. Both can be used with pyAirtable, and our code/docs may still refer to “API keys” instead of “access tokens”.
Quickstart¶
The Api
class represents a connection to Airtable, while the
Table
class exposes methods for retrieving, creating, and modifying
records in Airtable:
>>> import os
>>> from pyairtable import Api
>>> api = Api(os.environ['AIRTABLE_API_KEY'])
>>> table = api.table('appExampleBaseId', 'tblExampleTableId')
>>> table.all()
[
{
"id": "rec5eR7IzKSAOBHCz",
"createdTime": "2017-03-14T22:04:31.000Z",
"fields": {
"Name": "Alice",
"Email": "alice@example.com"
}
}
]
>>> table.create({"Name": "Bob"})
{
"id": "recwAcQdqwe21asdf",
"createdTime": "...",
"fields": {"Name": "Bob"}
}
>>> table.update("recwAcQdqwe21asdf", {"Name": "Robert"})
{
"id": "recwAcQdqwe21asdf",
"createdTime": "...",
"fields": {"Name": "Robert"}
}
>>> table.delete("recwAcQdqwe21asdf")
{'id': 'recwAcQdqwe21asdf', 'deleted': True}
See Working with Tables for more details on how to get and set data in Airtable.