Skip to main content

counterfact

Did your change really work? Measure the real effect of a price change, campaign, launch or policy on any time series. You get an honest likely range, and a plain "can't tell yet" when the data can't support a claim.

pip install counterfact            # add [pandas] and [plot] for DataFrames and charts
import pandas as pd
from counterfact import Client

cf = Client(api_key="YOUR_KEY")    # or set COUNTERFACT_API_KEY
df = pd.read_csv("weekly_sales.csv")
r = cf.analyze(df, metric="sales", change_at="2025-10-06", time_col="week",
               comparisons=["sales_other_region", "category_sales"])
print(r)
# sales, change at 2025-10-06: WORKED
#   effect per period: +40.9 (+9.5%)   likely range: +18.6 to +63.2
#   checks: fake change dates flagged 0 of 3, verdict stable when dropping a comparison 3 of 3
print(r.explanation)   # plain-language summary
r.plot()               # needs matplotlib

What you get back

  • verdict: "worked", "hurt" or "can't tell yet"
  • effect per period, effect_percent, likely_range (holds about 9 times in 10), total_effect
  • quick_before_after: the naive comparison, for contrast
  • robustness: fake-change-date checks and leave-one-comparison-out checks
  • counterfactual: what would most likely have happened without the change, period by period

Keys

How it works

Counterfact is a transformer pretrained on millions of synthetic worlds where the true cause and effect is known, and calibrated on 1,200 real Indian and US data windows. An open research version is on Hugging Face: Rudraneel93/counterfact-v2.

Licence

This client is MIT licensed. Use of the API is subject to the Counterfact terms.

Metadata

Release files for counterfact 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for counterfact 0.1.1
File Size Uploaded Provenance Actions
counterfact-0.1.1.tar.gz 6.2 kB Without provenance Details for counterfact-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for counterfact 0.1.1
File Interpreter ABI Platform Actions
counterfact-0.1.1-py3-none-any.whl Python 3 none any Details for counterfact-0.1.1-py3-none-any.whl

Total release size: 12.7 kB

Release files / counterfact-0.1.1.tar.gz

Download URL counterfact-0.1.1.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ce9ecf4f488930ffd2157bc5bcf7caf12f51b54b3420d3bdb4f2d076691044bc
BLAKE2b-256 checksum
How to use checksums
d63391fe6509a5c3446bed24dd6d2ba4148a9bdd604330cf199f9e48380f640d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / counterfact-0.1.1-py3-none-any.whl

Download URL counterfact-0.1.1-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e495b4c92c91989f9e2d9eaeb6e57987323f979de74aca1f76a693855b92ab5d
BLAKE2b-256 checksum
How to use checksums
76f184092cb86d2374e830b42737c190eb0afe43d45cbbbd5926d8590b29e1ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for counterfact 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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