Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Airtable switch from API key to personal access token #866

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/airtable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Overview
********

The Airtable class allows you to interact with an `Airtable <https://airtable.com/>`_ base. In order to use this class
you must generate an Airtable API Key which can be found in your Airtable `account settings <https://airtable.com/account>`_.
you must generate an Airtable personal access token which can be found in your Airtable `settings <https://airtable.com/create/tokens>`_.

.. note::
Finding The Base Key
Expand All @@ -18,20 +18,20 @@ you must generate an Airtable API Key which can be found in your Airtable `accou
**********
QuickStart
**********
To instantiate the Airtable class, you can either store your Airtable API
``AIRTABLE_API_KEY`` as an environmental variable or pass in your api key
To instantiate the Airtable class, you can either store your Airtable personal access token
``AIRTABLE_PERSONAL_ACCESS_TOKEN`` as an environmental variable or pass in your personal access token
as an argument. You also need to pass in the base key and table name.

.. code-block:: python

from parsons import Airtable

# First approach: Use API credentials via environmental variables and pass
# First approach: Use personal access token via environmental variable and pass
# the base key and the table as arguments.
at = Airtable(base_key, 'table01')

# Second approach: Pass API credentials, base key and table name as arguments.
at = Airtable(base_key, 'table01', api_key='MYFAKEKEY')
# Second approach: Pass personal access token, base key and table name as arguments.
at = Airtable(base_key, 'table01', personal_access_token='MYFAKETOKEN')


You can then call various endpoints:
Expand Down
13 changes: 8 additions & 5 deletions parsons/airtable/airtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ class Airtable(object):
table_name: str
The name of the table in the base. The table name is the equivilant of the sheet name
in Excel or GoogleDocs.
api_key: str
The Airtable provided api key. Not required if ``AIRTABLE_API_KEY`` env variable set.
personal_access_token: str
The Airtable personal access token. Not required if ``AIRTABLE_PERSONAL_ACCESS_TOKEN``
env variable set.
"""

def __init__(self, base_key, table_name, api_key=None):
def __init__(self, base_key, table_name, personal_access_token=None):

self.api_key = check_env.check("AIRTABLE_API_KEY", api_key)
self.client = client(base_key, table_name, self.api_key)
self.personal_access_token = check_env.check(
"AIRTABLE_PERSONAL_ACCESS_TOKEN", personal_access_token
)
self.client = client(base_key, table_name, self.personal_access_token)

def get_record(self, record_id):
"""
Expand Down
2 changes: 1 addition & 1 deletion test/test_airtable/test_airtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)


os.environ["AIRTABLE_API_KEY"] = "SOME_KEY"
os.environ["AIRTABLE_PERSONAL_ACCESS_TOKEN"] = "SOME_TOKEN"
BASE_KEY = "BASEKEY"
TABLE_NAME = "TABLENAME"

Expand Down