Skip to main content
Version: 2.0.0

Subscribers

A subscriber function reads data from tables in the Tabsdata server and writes the data to an external system.

Subscribers in Action

Tabsdata server
collection · warehouse
Table
vendors
//sales
Committed
Table
items
//sales
Committed
Connection
conn-mysql-dest.yaml
Subscriber
write_sales
Database
MySQL
MySQL · external
Not yet synced

Subscriber Code Anatomy

sales-sub.py
1from tabsdatak.api import subscriber, TableFrameSpec
2import tabsdatak.api.tableframe as tdf
3from tabsdatak.conn.mysql import MySQLDest
4
5
1@subscriber(
2 destination=MySQLDest(
8 tables=["vendors", "items"],
9 if_table_exists="replace",
10 ),
3 input_tables=["sales/vendors", "sales/items"],
12)
45def write_sales(vendors: TableFrameSpec, items: TableFrameSpec):
6 vendors = vendors.filter(tdf.col("active") == 1)
7 return (vendors, items)
  • Declares the tables to read and where to write them.

    • Connector class that performs the write. Address and credentials come from the collection's connection.

    • Tables to ship out, as collection/table, mapped positionally to function body arguments.

  • Plain Python over TableFrames. Usually short, since the connector does the writing.

    • One parameter per input table, in order.

    • Shapes the frames before they are written out.

    • One frame per destination table, in order. None skips that write.

For step-by-step guides on building a subscriber for a specific external system, see Subscribers under How-to Guides.