Skip to main content

factcat

Product analytics on the event model already in your warehouse. Your grain, your periods, your definitions.

Every other product analytics tool hard-codes entity = user, period = a calendar bucket, and retained = did any event. Real definitions violate all three:

from factcat import RetentionSpec, retention_sql

spec = RetentionSpec(
    table="analytics.fct_subscription_payments",
    entity="subscription_id",   # not the user
    entity_time="sub_start",
    event_time="paid_at",
    period_days=35,             # a billing cycle plus dunning, not a calendar bucket
    n_periods=12,
    retained="status = 'collected' AND within_period_offset <= 5",
)

print(retention_sql(spec, dialect="snowflake"))
from factcat import EventsSpec, events_sql

print(events_sql(EventsSpec(
    table="analytics.fct_events",
    entity="subscription_id",
    event_time="occurred_at",
    measure="uniques",
)))

Breakdowns are caller SQL plus optional top_n (default 8) and include_other (default True). breakdown_at is rows / first / last and does not replace the expression.

print(events_sql(EventsSpec(
    table="analytics.fct_events",
    entity="subscription_id",
    event_time="occurred_at",
    measure="uniques",
    breakdowns=("country",),
    top_n=8,
)))

Event measures: total, uniques, average (Total / Uniques). Property measures (on="property", of= a column): sum, average, median, distinct (mean distinct values per entity). Uniques is COUNT DISTINCT of entity when exact=True; default exact=False is approx NDV.

retained is arbitrary SQL over any column in your table, plus the derived columns offset_days, period_index and within_period_offset.

Generates SQL and queries in place. No SDK, no ingestion, no copy of your data.

SQL generation supports DuckDB, Postgres, BigQuery, Snowflake, Databricks, Spark, Trino, Presto, ClickHouse and Redshift. Execute adapters push that SQL into the caller's warehouse. Factcat has no warehouse of its own. pip install factcat is the product (SQL + chart) and includes no warehouse SDK. Run queries with pip install factcat[bigquery]. Later warehouses are extras of the same shape; factcat[all] is every shipped driver. The adapter contract is dialect plus run(sql).

from factcat import RetentionSpec, retention_sql
from factcat.warehouses import connect

sql = retention_sql(spec, dialect="bigquery")
bq = connect("bigquery", project="my-proj", location="EU")
result = bq.run(sql)

Application-default credentials by default (gcloud auth application-default login), or pass a service-account JSON path as credentials. Queries are capped at 10 GiB scanned unless you raise maximum_bytes_billed or pass None for unlimited. project and location are required so an EU dataset is not sent to US.

Full documentation: https://github.com/gordonkjlee/factcat

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

factcat-0.4.1.tar.gz (81.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

factcat-0.4.1-py3-none-any.whl (69.7 kB view details)

Uploaded Python 3

File details

Details for the file factcat-0.4.1.tar.gz.

File metadata

  • Download URL: factcat-0.4.1.tar.gz
  • Upload date:
  • Size: 81.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for factcat-0.4.1.tar.gz
Algorithm Hash digest
SHA256 76ad35f7aba27b982521ce1fe0e3aa6953b82a53e2d3cbd02ef6613173f5d441
MD5 38f416c7fb7b8133585345cf835dc553
BLAKE2b-256 83b892810cc74da679e91eaef54976e188af19e654ac6d3500f299b5e6f47c5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for factcat-0.4.1.tar.gz:

Publisher: publish.yml on gordonkjlee/factcat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file factcat-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: factcat-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 69.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for factcat-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9828ab08283e35ede712809f52af5c6ce0e5dff95caad255b74685fb460e54e1
MD5 cca60b45ad2c3c27ef489e3c2c14b2f5
BLAKE2b-256 8a83b945bed0557b6b6f5110fef1e3cf60eae8645aa7260ffbc262e57a54e390

See more details on using hashes here.

Provenance

The following attestation bundles were made for factcat-0.4.1-py3-none-any.whl:

Publisher: publish.yml on gordonkjlee/factcat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page