Transformers
A transformer function reads data from one or more tables in the Tabsdata server, transforms the data, then writes the transformed data to tables in the server.
Transformers in Action
Transformer Code Anatomy
1from tabsdatak.api import transformer, TableFrameSpec2import tabsdatak.api.tableframe as tdf341@transformer(2 input_tables=["world/country", "world/city"],3 output_tables=["big_cities"],8)45def find_big_cities(country: TableFrameSpec, city: TableFrameSpec) -> tuple[TableFrameSpec]:6 countries = country.rename({"name": "country_name"}).drop(11 ["population", "continent"]12 )13 joined = city.join(countries, left_on="country_code", right_on="code")7 return (joined.filter(tdf.col("population") > 3_000_000),)
Defines the input and output Tables for the Transformer.
Tabsdata Tables to read. Use
collection/tableto reference a Table in another Collection.Tables where the transformed data is written. These belong to the Transformer's Collection.
Reads the country and city data, joins it, and returns cities with a population above three million.
The arguments receive the data from
input_tablesin the order listed. An argument isNoneif the requested Table version does not exist.Renames the country name column, removes unused columns, and joins the country and city data.
The returned data is written to the Tables listed in
output_tables, in that order. ReturningNonefor a Table leaves its current version unchanged.
For step-by-step guidance on building a transformer, see Transformers under How-to Guides.