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
Run it offline with the open model
No API key, and no data leaves your computer. The first run downloads the open research model (Rudraneel93/counterfact-v2, 35 MB, free for non-commercial use) from Hugging Face.
pip install "counterfact[local]"
from counterfact import Local
r = Local().analyze(df, metric="sales", change_at="2025-10-06", time_col="week")
print(r)
The hosted Client uses the newest production model and adds robustness checks and plain-language explanations.
What you get back
verdict: "worked", "hurt" or "can't tell yet"effectper period,effect_percent,likely_range(holds about 9 times in 10),total_effectquick_before_after: the naive comparison, for contrastrobustness: fake-change-date checks and leave-one-comparison-out checkscounterfactual: what would most likely have happened without the change, period by period
Keys
- Counterfact Pro (₹1,999/month) includes 2,000 API calls: counterfact-site.vercel.app/#pricing. Your Pro access code is your API key.
cf.usage()shows calls left. - RapidAPI: subscribe at rapidapi.com/RudraneelDas/api/counterfact (free tier with 50 calls a month, pay as you go, or monthly plans), then
Client(rapidapi_key="..."). Billing is through RapidAPI.
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.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| counterfact-0.2.0.tar.gz | 7.8 kB | Without provenance | Details for counterfact-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| counterfact-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for counterfact-0.2.0-py3-none-any.whl |
Total release size: 16.3 kB
Release files / counterfact-0.2.0.tar.gz
| Download URL | counterfact-0.2.0.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
94518d3d0470e20533642f0cd32a11bde52e2f642c048006a6b0418592334373
|
|
BLAKE2b-256 checksum How to use checksums |
f5fc7151d1c64ef9ddf518a5cd52fd09a7872793873d5a55150bce360a0d3540
|
| 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.2.0-py3-none-any.whl
| Download URL | counterfact-0.2.0-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
528f9ab20879e9c7b1c8f39823e32c70cdee9e928ac948a2d338c9a635c5c311
|
|
BLAKE2b-256 checksum How to use checksums |
c964b080d40dcce1ffa8c9f3228bbd02083e1368f6c2c4a2c56cabb3d13ca489
|
| 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.2.0
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.