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

  • 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: Client(rapidapi_key="..."), billed 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.1.0

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.0
File Size Uploaded Provenance Actions
counterfact-0.1.0.tar.gz 6.0 kB Without provenance Details for counterfact-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 12.3 kB

Release files / counterfact-0.1.0.tar.gz

Download URL counterfact-0.1.0.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a9a1821a0a9aaa3320c87de400657efa25c523dea8ab66199dadbe0d84ff9c6f
BLAKE2b-256 checksum
How to use checksums
c5e019f590f2eabaeeb558b417c5662c8f6a26a0370e3eda9e41184b2583ad66
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.0-py3-none-any.whl

Download URL counterfact-0.1.0-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e12a4da2d18babbb0851f76182f70dbc0ebf93ace0b008fd516eefd771393c5
BLAKE2b-256 checksum
How to use checksums
d7e7f339a7af95f01c986fd68d57cbb223b34664ee5ae5a567e61282fca3bb67
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.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.

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