Airtable Python Wrapper
airtable-python-wrapper is a Python API client wrapper for the Airtable API, enabling programmatic interaction with Airtable bases and tables. The latest version is 0.15.3, released in July 2021. While functional, this library has effectively been superseded by 'pyairtable' for its 1.x+ releases, and no new releases are expected under the `airtable-python-wrapper` name.
Common errors
-
ModuleNotFoundError: No module named 'airtablib' (or 'airtable_wrapper')
cause Incorrect module name in the import statement. The package `airtable-python-wrapper` installs the module `airtable`.fixChange your import statement to `from airtable import Airtable`. -
ImportError: cannot import name 'Api' from 'airtable'
cause Attempting to import a class named `Api` which does not exist in the `airtable-python-wrapper` library. The main class is `Airtable`.fixChange your import statement to `from airtable import Airtable` and use `Airtable(...)` to instantiate. -
ImportError: cannot import name 'Airtable' from 'airtable' (path/to/your/project/airtable.py)
cause This usually happens when your own Python script or a file in your project directory is named `airtable.py`, causing Python to import your local file instead of the installed library.fixRename your script or any conflicting file named `airtable.py` to something else (e.g., `my_airtable_script.py`) to avoid module name collisions. -
requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url: ... [Error: {'type': 'INVALID_FILTER_BY_FORMULA', 'message': 'The formula for filtering records is invalid: unknown field names: id'}]cause Attempting to use `id` (Airtable's internal record ID) directly in a formula without explicitly creating a formula field in Airtable named 'id' with the formula `RECORD_ID()`.fixIf you need to filter or search by record ID using formulas, create a new field in your Airtable base, name it 'Record ID' (or similar), set its type to 'Formula', and use the formula `RECORD_ID()`. Then refer to this new field name in your Python formula, e.g., `airtable.get_all(formula='{Record ID} = "recXXXXXXX"')`.
Warnings
- breaking The `airtable-python-wrapper` library has been renamed to `pyairtable` for its 1.x+ releases. New features and ongoing development are in `pyairtable`, and `airtable-python-wrapper` will not receive further updates beyond 0.15.3. Migration to `pyairtable` is recommended for active projects.
- breaking As of version 0.15.0, API key configuration via environment variables was dropped. The `api_key` must now be passed directly as an argument to the `Airtable` constructor.
- breaking Python 2 and IronPython support were dropped starting from version 0.15.0.
- gotcha The `Airtable` constructor expects the `base_id` (a string like 'appXXXXXXX') not the human-readable 'base name'. Using the base name will lead to connection errors.
Install
-
pip install airtable-python-wrapper
Imports
- Airtable
from airtable import Api
from airtable import Airtable
- Airtable
from airtablib import Airtable
from airtable import Airtable
- Airtable
from airtable_wrapper import AirtableAPI
from airtable import Airtable
Quickstart
import os
from airtable import Airtable
# It's recommended to store sensitive information like API keys in environment variables
AIRTABLE_API_KEY = os.environ.get('AIRTABLE_API_KEY', 'YOUR_API_KEY')
AIRTABLE_BASE_ID = os.environ.get('AIRTABLE_BASE_ID', 'YOUR_BASE_ID')
AIRTABLE_TABLE_NAME = os.environ.get('AIRTABLE_TABLE_NAME', 'YOUR_TABLE_NAME')
# Initialize Airtable client
airtable = Airtable(AIRTABLE_BASE_ID, AIRTABLE_TABLE_NAME, api_key=AIRTABLE_API_KEY)
# Fetch all records from the table
records = airtable.get_all()
print(f"Fetched {len(records)} records.")
# print(records[0]) # Uncomment to see an example record
# Insert a new record
new_record_data = {'Name': 'New Task', 'Status': 'To Do'}
inserted_record = airtable.insert(new_record_data)
print(f"Inserted new record with ID: {inserted_record['id']}")
# Update a record (using its ID)
# Note: You'll need a valid record ID for this to work.
# Example: record_to_update_id = inserted_record['id']
# updated_data = {'Status': 'Done'}
# updated_record = airtable.update(record_to_update_id, updated_data)
# print(f"Updated record with ID: {updated_record['id']}")
# Search for records by field value
found_records = airtable.search('Name', 'New Task')
print(f"Found {len(found_records)} records matching 'New Task'.")