Skip to main content

AITÆM: All Interesting Things Are Essentially Metrics

CI PyPI version Python versions Docs

This is the aitaem library, pronounced "i-tame".

Full documentation: https://chaturv3di.github.io/aitaem/

Why?

TL;DR: Point this Python library toward your OLAP database or a local CSV file and start generating insights, i.e. metrics, slices, segments, and time series, in no time. This library is LLM friendly (more on that later).

Business leaders, PMs, EMs, and even individual contributors constantly require deep understanding of their businesses and products. Another term for this understanding is "data insights". The most common way to obtain these insights is to rely on a data scientist or a business analyst to dive into the data and compute the insights. Why is this a bad idea?

  1. Practically: Dashboards are limited in how much they can hold apriori. There's always a new question which existing dashboards cannot answer. There are always either too many dashboards or too few
  2. Operationally: It is a waste of time if a DS or a BA has to dive into the source tables and (re)write SQL queries to compute customized metrics, slices, or segments repeatedly
  3. Scientifically: The accuracy of ad-hoc analysis depends upon the individual; the same analysis done by different individuals can yield different results
  4. Organisationally: Inter-org trust should be built upon processes/toolings rather than on individuals

What?

This library provides powerful functionality in a compact API. The core consists of two componenents.

  1. Specifications: A simple declarative structure to modularly define metric specs, slice/breakdown specs, and segment specs
  2. Computation: A small collection of Python classes with compact signatures which compute the metrics

Additionally, there are utilities to connect to various data backends (simultaneously) and helpers to visualize/render charts and trends.

Quick Start

Installation

pip install aitaem

Three-Step API

from aitaem import SpecCache, ConnectionManager, MetricCompute

# 1. Load metric, slice, and segment specs from YAML files or directories
cache = SpecCache.from_yaml(
    metric_paths="examples/metrics/",
    slice_paths="examples/slices/",
    segment_paths="examples/segments/",
)

# 2. Configure the data backend (DuckDB, BigQuery, etc.)
conn = ConnectionManager()
conn.add_connection("duckdb", path=":memory:")  # or path to .duckdb file

# 3. Compute metrics
mc = MetricCompute(cache, conn)
table = mc.compute(
    metrics="ctr",
    slices="campaign_type",
    segments="platform",
    time_window=("2024-01-01", "2024-04-01"),
)
print(table.to_pandas())

Standard Output Format

Every compute() call returns a lazy ibis.Table with exactly these 11 columns. Call .to_pandas() to materialise into a DataFrame.

Column Description
period_type "all_time" or a named period
period_start_date ISO date string or None
period_end_date ISO date string or None
entity_id Entity column value when by_entity is set; None otherwise
metric_name Name of the metric (e.g. "ctr")
metric_format Format hint from the spec (e.g. "percentage"), or None
slice_type Slice name or "none" for the all-data baseline
slice_value Slice value (e.g. "Search") or "all"
segment_name Segment name or "none" for the all-data baseline
segment_value Segment value (e.g. "Google Ads") or "all"
metric_value Computed numeric result

Example: Ad Campaigns Dataset

The examples/ directory contains sample YAML specs and a CSV dataset for an ad campaigns use case. You can run the following end-to-end:

from aitaem import SpecCache, ConnectionManager, MetricCompute
from aitaem.helpers import load_csvs_to_duckdb

# Load the sample CSV into a DuckDB file and get back a connector
connector = load_csvs_to_duckdb("examples/data/ad_campaigns.csv", "examples/data/ad_campaigns.duckdb")

conn = ConnectionManager()
conn.add_connection("duckdb", connector=connector)

cache = SpecCache.from_yaml(
    metric_paths="examples/metrics/",
    slice_paths="examples/slices/",
    segment_paths="examples/segments/",
)

mc = MetricCompute(cache, conn)

# CTR by campaign type for Q1 2024
table = mc.compute(
    metrics="ctr",
    slices="campaign_type",
    time_window=("2024-01-01", "2024-04-01"),
)
print(table.to_pandas()[["slice_value", "metric_value"]])

Download files

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

Source Distribution

aitaem-1.0.0.tar.gz (584.2 kB view details)

Uploaded Source

Built Distribution

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

aitaem-1.0.0-py3-none-any.whl (116.4 kB view details)

Uploaded Python 3

File details

Details for the file aitaem-1.0.0.tar.gz.

File metadata

  • Download URL: aitaem-1.0.0.tar.gz
  • Upload date:
  • Size: 584.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for aitaem-1.0.0.tar.gz
Algorithm Hash digest
SHA256 76f7f9ced80af3f804896976dadaa15e21d32b74af493c7322213bc3e9c7d1f0
MD5 4602764f74b449f2db9e6415b07efe4c
BLAKE2b-256 a691a7551be56fbb94c9614f7e251128ee1d0ab77980382ecbf507f0f72c63d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for aitaem-1.0.0.tar.gz:

Publisher: publish.yml on chaturv3di/aitaem

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

File details

Details for the file aitaem-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: aitaem-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 116.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for aitaem-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c9ffc0501893f8fa3d979381e34c6d4f93e7410edfb24b27269b7735461cbea
MD5 4ce00f8d637b78fdd425769f95bb7f8b
BLAKE2b-256 cf604571ed8aab79e74eb2bda5dcc17e0d8860881dea3574b634e4c51fd9ed80

See more details on using hashes here.

Provenance

The following attestation bundles were made for aitaem-1.0.0-py3-none-any.whl:

Publisher: publish.yml on chaturv3di/aitaem

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

Release history Release notifications | RSS feed

2.0.0

2 files

This release

1.0.0 This release

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

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