Skip to main content

A Python library for quantitative reasoning.

Project description

formative

Python library for quantitative reasoning.

Requirements

  • Python 3.10+

Installation

pip install formative-ds

Docs

Comprehensive documentation is available at docs.getformative.dev.

Usage

Causal estimation

Every analysis follows the same four steps: assume, estimate, refute, decide.

from formative.causal import DAG, OLSObservational

# 1. Encode your causal assumptions as a DAG
dag = DAG()
dag.assume("ability").causes("education", "income")
dag.assume("education").causes("income")

# 2. Estimate the causal effect
result = OLSObservational(dag, treatment="education", outcome="income").fit(df)
print(result.summary())

# 3. Refute: stress-test the result's assumptions
print(result.refute(df).summary())

# 4. Decide: is the treatment worth acting on?
print(result.decide(cost=8, benefit=15))

Confounders declared in the DAG are controlled for automatically. If a confounder is absent from the dataframe, an IdentificationError is raised before any estimation runs. Some estimators go further at step 4 — per-group decisions, or learning a treatment rule with learn_policy().

Decision rules

from formative.game import maximin, maximax, hurwicz, laplace, minimax

outcomes = {
    "stocks": {"recession": -20, "stagnation":  5, "growth": 30},
    "bonds":  {"recession":   5, "stagnation":  5, "growth":  7},
    "cash":   {"recession":   2, "stagnation":  2, "growth":  2},
}

maximin(outcomes).solve()        # safest choice (best worst case)
maximax(outcomes).solve()        # most optimistic (best best case)
hurwicz(outcomes, alpha=0.5).solve()  # blend of optimism and pessimism
laplace(outcomes).solve()        # highest average payoff
minimax(outcomes).solve()        # lowest worst-case regret

See online documentation at docs.getformative.dev for more examples and details.

Local development

Requires uv.

git clone https://github.com/maxpagels/formative
cd formative
uv sync --dev

This creates a .venv, installs all dependencies, and installs the package in editable mode.

Releasing a new version

make release BUMP=patch   # 0.1.0 → 0.1.1 (bug fixes)
make release BUMP=minor   # 0.1.0 → 0.2.0 (new features)
make release BUMP=major   # 0.1.0 → 1.0.0 (breaking changes)

One command does everything: bumps the version in pyproject.toml and uv.lock (commit + tag), builds the docs, snapshots them into site/<major.minor>/ (the versioned docs site Vercel serves statically), and pushes with tags — which triggers the publish to PyPI. It refuses to run if the working tree is dirty or uv.lock is out of date.

Running tests

uv run pytest

Importing without installing

To use formative from a script outside this repo without installing it, either prepend the path at runtime:

import sys
sys.path.insert(0, "/path/to/formative")

from formative.causal import DAG, OLSObservational

Or set PYTHONPATH before running:

PYTHONPATH=/path/to/formative python your_script.py

Project details


Download files

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

Source Distribution

formative_ds-2.2.2.tar.gz (15.7 MB view details)

Uploaded Source

Built Distribution

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

formative_ds-2.2.2-py3-none-any.whl (69.6 kB view details)

Uploaded Python 3

File details

Details for the file formative_ds-2.2.2.tar.gz.

File metadata

  • Download URL: formative_ds-2.2.2.tar.gz
  • Upload date:
  • Size: 15.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for formative_ds-2.2.2.tar.gz
Algorithm Hash digest
SHA256 6641016d2acd4938c5ea3df624312b5db3d00036b276c811f0f83307b2b054c1
MD5 2cf8915bc1fc7b7e387168890e4d7be6
BLAKE2b-256 21805cebceb0ed2161511e436b2325fa92111180664f0242c0248b979e09f75b

See more details on using hashes here.

Provenance

The following attestation bundles were made for formative_ds-2.2.2.tar.gz:

Publisher: publish.yml on maxpagels/formative

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

File details

Details for the file formative_ds-2.2.2-py3-none-any.whl.

File metadata

  • Download URL: formative_ds-2.2.2-py3-none-any.whl
  • Upload date:
  • Size: 69.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for formative_ds-2.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bd24c8918af7cb835b4f2c3b39ba098f8bb4b43ce6cee2aa1c83c8c2b22e1089
MD5 bb816fd68b60d10357e34ac399be1fd4
BLAKE2b-256 bd2299c6771f074a7a956626f4d0fe8b44344fb2d2f981083a15945416e186b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for formative_ds-2.2.2-py3-none-any.whl:

Publisher: publish.yml on maxpagels/formative

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page