Primitives
Primitives are reusable Python functions that replace SQL snippets. Hashing, date operations, categorization — import and compose them instead of copy-pasting SQL.
from fyrnheim.primitives import hash_email, date_trunc_monthfrom fyrnheim import ComputedColumn
ComputedColumn(name="email_hash", expression=hash_email("email"))ComputedColumn(name="signup_month", expression=date_trunc_month("created_at"))Primitives generate Ibis expressions, so they compile to the correct SQL for every backend (DuckDB, BigQuery, ClickHouse, etc.).
Available Primitives
Section titled “Available Primitives”Hashing
Section titled “Hashing”hash_email(column)— SHA-256 hash of a lowered, trimmed emailhash_id(column)— SHA-256 hash of a column valuehash_md5(column)— MD5 hash of a column valuehash_sha256(column)— SHA-256 hash of a column valueconcat_hash(*columns)— Concatenate columns and hash the result
date_trunc_month(column)— Truncate a date to the first of the monthdate_trunc_quarter(column)— Truncate a date to the first of the quarterdate_trunc_year(column)— Truncate a date to the first of the yeardays_since(column)— Number of days between a date column and todaydate_diff_days(start, end)— Number of days between two date columnsextract_year(column)— Extract year from a dateextract_month(column)— Extract month from a dateextract_day(column)— Extract day from a dateearliest_date(*columns)— The earliest (minimum) date across columnslatest_date(*columns)— The latest (maximum) date across columns
Categorization
Section titled “Categorization”categorize(column, mapping)— Map column values to categories via a dictionarycategorize_contains(column, mapping)— Categorize by substring matchinglifecycle_flag(column, states)— Produce a boolean flag based on column valueboolean_to_int(column)— Convert a boolean column to 0/1
to_json_struct(column)— Parse a JSON string column into a structjson_extract_scalar(column, path)— Extract a scalar value from JSONjson_value(column, path)— Extract a value from JSON
Aggregations
Section titled “Aggregations”sum_(column)— Sum of a columncount_(column)— Count of a columncount_distinct(column)— Count of distinct valuesavg_(column)— Average of a columnmin_(column)— Minimum valuemax_(column)— Maximum valuerow_number_by(partition, order)— Row number within a partitioncumulative_sum(column)— Cumulative sumlag_value(column)— Previous row’s valuelead_value(column)— Next row’s valuefirst_value(column)— First value in a windowlast_value(column)— Last value in a windowany_value(column)— Any non-null value
Strings
Section titled “Strings”extract_email_domain(column)— Extract the domain from an email addressis_personal_email_domain(column)— Check if an email domain is a personal provideraccount_id_from_domain(column)— Derive an account ID from an email domain
parse_iso8601_duration(column)— Parse an ISO 8601 duration string