Sync an Airtable base to a Postgres schema in real time
Project description
Airtable Postgres Sync
The goal of this library is to provide an out-of-the-box solution for replicating an entire Airtable base in a Postgres schema. There are two modes of operation:
- One-off-sync: This mode will replicate the Airtable base in the specified Postgres schema and then exit. This is useful for creating snapshots of the base for analysis or for storage as a backup.
- Perpetual sync: This mode will replicate the Airtable base in the specified Postgres schema and then continue to watch for changes in the base. When a change is detected, the change will be applied to the Postgres schema. This is useful for creating a replica of the base that can be used for analysis in real time.
Installation
To install the library, run the following command:
pip install airtable-postgres-sync
Permissions
To use this library, you will need to create a personal access token in Airtable. This token will need to have the following scopes:
- data.records:read
- schema.bases:read
- webhook:manage
You will also need to give the Postgres user that you are using read and write access to the schema you are syncing to.
Usage
To use the library, you will need to create a config file. The config file defines all the parameters that are needed to connect to Airtable and Postgres, as well as how your program will listen for changes. The file must be in YAML format and must contain the following fields:
AIRTABLE_PG_SYNC:
DB_INFO:
HOST: # Postgres host
PORT: # Postgres port
USER: # Postgres user
PASSWORD: # Postgres password
DB_NAME: # Postgres database name
SCHEMA_NAME: # Postgres schema name
AIRTABLE_INFO:
BASE_ID: # Airtable base id to sync
PAT: # Airtable personal access token
LISTENER_INFO:
WEBHOOK_URL: # The url that Airtable will send change notifications to
PORT: # The port to listen for change notifications on
The library can be used in two ways:
- As a command line tool
To trigger a one-time sync, run the following command:
airtable-pg-sync one-time-sync --config /path/to/config.yml
To trigger a perpetual sync, run the following command:
airtable-pg-sync perpetual-sync --config /path/to/config.yml
- As a python library
To trigger a sync from within a python program, run the following code:
from airtable_pg_sync import Sync
Sync(config_path="/path/to/config.yml", perpetual=True / False).run()
Bugs, Feature Requests, and Contributions
If you find a bug or have a feature request, please open an issue on GitHub. Any contributions are welcome and appreciated. If you would like to contribute, please open a pull request on GitHub.
Ideas for contributions:
- Add support for other databases
- Add support for Postgres -> Airtable sync
License
This library is licensed under the MIT License. See the LICENSE file
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for airtable_pg_sync-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3af3b640acdaff39c5ce058ae53f2436a6d3c26829810ac1994b96315fa07ab4 |
|
MD5 | 8c3c05262533b813205d351dab30b685 |
|
BLAKE2b-256 | 0b47e224951c85de6a1060d7c76041188d7c9f20c55a86d96741f792e43c81e7 |