Shared Python utilities for SQL, Excel, and date helpers.
Project description
analytics_toolkit
Python toolkit for AB-test analysis, SQL workflows, Excel reports, and date helpers.
Version: 1.3.7.6
Depends: Python (>=3.8,<3.15)
Imports: clickhouse-connect (>=0.5.14,<1), lz4 (>=4.3.2,<5), numpy (>=1.24.2,<2), openpyxl (>=3.1.1,<4), orjson (>=3.8.7,<4), pandas (>=1.4.4,<3), psycopg2-binary (>=2.9.5,<3), python-dateutil (>=2.8.2,<3), pytz (>=2022.7), requests (>=2.28.2,<3), scipy (>=1.10.1,<2), sqlglot (>=20,<31), sqlparse (>=0.4.3,<1), tqdm (>=4.65.0,<5), trino (>=0.320,<1), zstandard (>=0.20.0,<1)
Suggests: apache-airflow (>=2.4,<3; optional extra airflow)
Install: pip install analytics-toolkit
PyPI: pypi.org/project/analytics-toolkit
License: MIT
Source: github.com/Karapsin/analytics_toolkit
Issues: GitHub Issues
Installation
From PyPI:
pip install analytics-toolkit
From GitHub:
pip install git+https://github.com/Karapsin/analytics_toolkit.git
Areas
analytics_toolkit.ab_utils: AB-test metric comparison helpers.analytics_toolkit.sql: SQL read, execute, load, and transfer helpers.analytics_toolkit.excel: Excel report helpers for long-format dataframes.analytics_toolkit.dates: date and period helpers.analytics_toolkit.general: shared logging and file path helpers.
SQL Workflows
sql.transfer streams query results between configured SQL backends, with
batching, retries, and table creation or replacement handled by one call.
from analytics_toolkit import sql
rows = sql.transfer(
from_db="trino",
to_db="gp",
from_sql="select user_id, order_id, amount from iceberg.analytics.orders",
to_table="sandbox.orders_copy",
write_mode="replace",
batch_size=50_000,
progress=True,
)
sql.read/sql.read_sql: run a query and return a dataframe.sql.execute/sql.execute_sql: run DDL or DML without returning a dataframe.sql.execute_read: run setup SQL and return the final result as a dataframe.sql.load_df: load a pandas dataframe into a configured backend table.sql.transfer: move rows from a source query to a target table across backends.
AB Metrics
compute_test_metrics compares experiment groups across mean and ratio metrics,
with optional CUPED statistics and bootstrap multiple-comparison adjustment.
from analytics_toolkit.ab_utils import compute_test_metrics
result = compute_test_metrics(
experiment_df,
group="group_name",
control="control",
user_id="user_id",
ratio_metrics=[
{"name": "ctr", "numerator": "clicks", "denominator": "views"},
],
pre_exp_metrics_df=pre_experiment_df,
multiple_comparisons_adjustment=True,
multiple_comparisons_adjustment_resamples=1000,
)
Example output with CUPED and bootstrap columns enabled:
| metric_type | group_1 | group_2 | metric_name | n0 | n1 | outliers_cutoff | outliers_n_control | outliers_n_test | metric_control | metric_test | variance_control | variance_test | delta_abs | delta_relative | mde_abs | mde_relative | s.e. | p-value | s.e. CUPED | p-value CUPED | mde_abs CUPED | mde_relative CUPED | s.e. bootstrap | bootstrap_adj_p |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| mean | test | control | revenue | 10000 | 10050 | 250.0 | 3 | 4 | 12.40 | 13.10 | 45.20 | 47.80 | 0.70 | 0.056 | 0.42 | 0.034 | 0.15 | 0.003 | 0.11 | 0.001 | 0.31 | 0.025 | 0.14 | 0.012 |
| ratio | test | control | ctr | 10000 | 10050 | 1.0 | 0 | 0 | 0.082 | 0.087 | 0.0009 | 0.0010 | 0.005 | 0.061 | 0.003 | 0.037 | 0.001 | 0.008 | 0.001 | 0.006 | 0.002 | 0.024 | 0.001 | 0.019 |
Date Helpers
Date helpers cover reporting ranges, period boundaries, offsets, and stable string formatting for SQL and filenames.
from analytics_toolkit.dates import add_days, first_day, gen_dates_list, last_day
report_days = gen_dates_list("2026-06-01", "2026-06-07")
# ["2026-06-01", "2026-06-02", "2026-06-03", "2026-06-04", "2026-06-05", "2026-06-06", "2026-06-07"]
month_start = first_day("2026-06-08", "month")
# "2026-06-01"
month_end = last_day("2026-06-08", "month")
# "2026-06-30"
next_run = add_days("2026-06-08", 1)
# "2026-06-09"
gen_dates_list: build daily, weekly, monthly, or quarterly sequences.first_day/last_day: get week, month, or quarter boundaries.add_days,add_weeks,add_months,add_quarters: shift dates.sanitize_date: convert a date to compactYYYYMMDDtext.
Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file analytics_toolkit-1.3.7.6.tar.gz.
File metadata
- Download URL: analytics_toolkit-1.3.7.6.tar.gz
- Upload date:
- Size: 226.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3472dc651836cee372b6406c5211259cb75dd7f5c5d76fa3ff672393c46e8cc4
|
|
| MD5 |
3607661e75c416033249465ce70546cf
|
|
| BLAKE2b-256 |
5dfe78f2bd06552c972c724ddb9b9493459e5adfdf9186ed92725dcb2b767dbb
|
Provenance
The following attestation bundles were made for analytics_toolkit-1.3.7.6.tar.gz:
Publisher:
publish.yml on Karapsin/analytics_toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
analytics_toolkit-1.3.7.6.tar.gz -
Subject digest:
3472dc651836cee372b6406c5211259cb75dd7f5c5d76fa3ff672393c46e8cc4 - Sigstore transparency entry: 1754822487
- Sigstore integration time:
-
Permalink:
Karapsin/analytics_toolkit@34813ba64b90eb9f8848b44ba8711379f957eaec -
Branch / Tag:
refs/tags/v1.3.7.6 - Owner: https://github.com/Karapsin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@34813ba64b90eb9f8848b44ba8711379f957eaec -
Trigger Event:
release
-
Statement type:
File details
Details for the file analytics_toolkit-1.3.7.6-py3-none-any.whl.
File metadata
- Download URL: analytics_toolkit-1.3.7.6-py3-none-any.whl
- Upload date:
- Size: 193.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b1b4c3b5b63235264c8dd734c2b41af0e92f411f27974526628e21bc1ccc2f8
|
|
| MD5 |
bd1ec2c3288027dc8e09c3551bf0906e
|
|
| BLAKE2b-256 |
7311d1a186d87916a9a578a1eb7c1ef39ba076d2e13de83dba2c6bad9c157caa
|
Provenance
The following attestation bundles were made for analytics_toolkit-1.3.7.6-py3-none-any.whl:
Publisher:
publish.yml on Karapsin/analytics_toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
analytics_toolkit-1.3.7.6-py3-none-any.whl -
Subject digest:
2b1b4c3b5b63235264c8dd734c2b41af0e92f411f27974526628e21bc1ccc2f8 - Sigstore transparency entry: 1754822491
- Sigstore integration time:
-
Permalink:
Karapsin/analytics_toolkit@34813ba64b90eb9f8848b44ba8711379f957eaec -
Branch / Tag:
refs/tags/v1.3.7.6 - Owner: https://github.com/Karapsin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@34813ba64b90eb9f8848b44ba8711379f957eaec -
Trigger Event:
release
-
Statement type: