Skip to content

Commit

Permalink
fix(airtable): use personal access token instead of api key
Browse files Browse the repository at this point in the history
  • Loading branch information
gventuri committed Jan 26, 2024
1 parent 94802b3 commit 66b9ba0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
7 changes: 3 additions & 4 deletions docs/connectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ df = SmartDataframe(connector)
df.chat('How many records are there ?')
```


### Generic SQL connector

The generic SQL connector allows you to connect to any SQL database that is supported by SQLAlchemy.
Expand Down Expand Up @@ -217,7 +216,7 @@ df.chat("What is the closing price for yesterday?")

## Airtable Connector

The Airtable connector allows you to connect to Airtable Projects Tables, by simply passing the `base_id` , `api_key` and `table_name` of the table you want to analyze.
The Airtable connector allows you to connect to Airtable Projects Tables, by simply passing the `base_id` , `token` and `table_name` of the table you want to analyze.

To use the Airtable connector, you only need to import it into your Python code and pass it to a `SmartDataframe` or `SmartDatalake` object:

Expand All @@ -228,7 +227,7 @@ from pandasai import SmartDataframe

airtable_connectors = AirtableConnector(
config={
"api_key": "AIRTABLE_API_TOKEN",
"token": "AIRTABLE_API_TOKEN",
"table":"AIRTABLE_TABLE_NAME",
"base_id":"AIRTABLE_BASE_ID",
"where" : [
Expand All @@ -242,4 +241,4 @@ airtable_connectors = AirtableConnector(
df = SmartDataframe(airtable_connectors)

df.chat("How many rows are there in data ?")
```
```
2 changes: 1 addition & 1 deletion examples/from_airtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

airtable_connectors = AirtableConnector(
config={
"api_key": "AIRTABLE_API_TOKEN",
"token": "AIRTABLE_API_TOKEN",
"table": "AIRTABLE_TABLE_NAME",
"base_id": "AIRTABLE_BASE_ID",
"where": [
Expand Down
10 changes: 5 additions & 5 deletions pandasai/connectors/airtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ def __init__(
cache_interval: int = 600,
):
if isinstance(config, dict):
if "api_key" in config and "base_id" in config and "table" in config:
if "token" in config and "base_id" in config and "table" in config:
config = AirtableConnectorConfig(**config)
else:
raise KeyError(
"Please specify all api_key,table,base_id properly in config ."
"Please specify all token, table, base_id properly in config ."
)

elif not config:
airtable_env_vars = {
"api_key": "AIRTABLE_API_TOKEN",
"token": "AIRTABLE_API_TOKEN",
"base_id": "AIRTABLE_BASE_ID",
"table": "AIRTABLE_TABLE_NAME",
}
Expand All @@ -60,7 +60,7 @@ def _init_connection(self, config: BaseConnectorConfig):
config = config.dict()
url = f"{self._root_url}{config['base_id']}/{config['table']}"
response = requests.head(
url=url, headers={"Authorization": f"Bearer {config['api_key']}"}
url=url, headers={"Authorization": f"Bearer {config['token']}"}
)
if response.status_code == 200:
self.logger.log(
Expand Down Expand Up @@ -171,7 +171,7 @@ def _request_api(self, params):
url = f"{self._root_url}{self._config.base_id}/{self._config.table}"
return requests.get(
url=url,
headers={"Authorization": f"Bearer {self._config.api_key}"},
headers={"Authorization": f"Bearer {self._config.token}"},
params=params,
)

Expand Down
2 changes: 1 addition & 1 deletion pandasai/connectors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AirtableConnectorConfig(BaseConnectorConfig):
Connecter configuration for Airtable data.
"""

api_key: str
token: str
base_id: str
database: str = "airtable_data"

Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/connectors/test_airtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TestAirTableConnector(unittest.TestCase):
def setUp(self) -> None:
# Define your ConnectorConfig instance here
self.config = AirtableConnectorConfig(
api_key="your_token",
token="your_token",
base_id="your_baseid",
table="your_table_name",
where=[["Status", "=", "In progress"]],
Expand Down

0 comments on commit 66b9ba0

Please sign in to comment.