:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
from dataclasses import dataclass, field
from products.warehouse_sources.sources.sdk import IncrementalField, IncrementalFieldType
@dataclass(frozen=True)
class PlaidEndpointConfig:
name: str
primary_keys: list[str]
incremental_fields: list[IncrementalField] = field(default_factory=list)
partition_key: str | None = None
should_sync_default: bool = True
description: str | None = None
# One PostHog source connects one Plaid Item (the access token the user
# obtained via Plaid Link). Transactions use /transactions/get with the
# server-side start_date filter — /transactions/sync's opaque cursor can't be
# expressed as a row-field watermark in this framework.
PLAID_ENDPOINTS: dict[str, PlaidEndpointConfig] = {
"accounts": PlaidEndpointConfig(
name="accounts",
primary_keys=["account_id"],
),
"transactions": PlaidEndpointConfig(
name="transactions",
primary_keys=["transaction_id"],
incremental_fields=[
{
"label": "date",
"type": IncrementalFieldType.Date,
"field": "date",
"field_type": IncrementalFieldType.Date,
},
],
partition_key="date",
),
"investment_transactions": PlaidEndpointConfig(
name="investment_transactions",
primary_keys=["investment_transaction_id"],
# Investments at Link only adds the Holdings subscription; the first
# /investments/transactions/get call adds the separately billed Transactions one.
should_sync_default=False,
description="Syncing this table starts Plaid's Investments Transactions subscription for the Item if it does not have one yet.",
incremental_fields=[
{
"label": "date",
"type": IncrementalFieldType.Date,
"field": "date",
"field_type": IncrementalFieldType.Date,
},
],
partition_key="date",
),
# A holding has no ID of its own: Plaid returns one position per security per account.
"investment_holdings": PlaidEndpointConfig(
name="investment_holdings",
primary_keys=["account_id", "security_id"],
),
"liabilities": PlaidEndpointConfig(
name="liabilities",
primary_keys=["account_id"],
),
"institutions": PlaidEndpointConfig(
name="institutions",
primary_keys=["institution_id"],
),
"recurring_transactions": PlaidEndpointConfig(
name="recurring_transactions",
primary_keys=["stream_id"],
# Recurring Transactions is a separately billed add-on to Transactions.
should_sync_default=False,
description="Syncing this table starts Plaid's Recurring Transactions subscription for the Item if it does not have one yet.",
),
"balances": PlaidEndpointConfig(
name="balances",
primary_keys=["account_id"],
# Plaid bills Balance per request, unlike the cached balances on accounts.
should_sync_default=False,
description="Each sync of this table makes one billed Plaid Balance request.",
),
# One row per account, with the account owners' names, emails, phone numbers and addresses.
"identity": PlaidEndpointConfig(
name="identity",
primary_keys=["account_id"],
should_sync_default=False,
description="Contains the names, emails, phone numbers and addresses of the account owners.",
),
"items": PlaidEndpointConfig(
name="items",
primary_keys=["item_id"],
),
}
ENDPOINTS = tuple(PLAID_ENDPOINTS.keys())
SHOULD_SYNC_DEFAULT: dict[str, bool] = {name: config.should_sync_default for name, config in PLAID_ENDPOINTS.items()}
DESCRIPTIONS: dict[str, str] = {
name: config.description for name, config in PLAID_ENDPOINTS.items() if config.description
}
INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {
name: config.incremental_fields for name, config in PLAID_ENDPOINTS.items() if config.incremental_fields
}