Metadata-Version: 2.5
Name: theoryforge
Version: 0.7.0
Summary: Systematic theory development.
Project-URL: Homepage, https://github.com/pablobernabeu/theoryforge
Project-URL: Repository, https://github.com/pablobernabeu/theoryforge
Project-URL: Documentation, https://pablobernabeu.github.io/theoryforge/python/
Project-URL: R twin, https://pablobernabeu.github.io/theoryforge/r/
Project-URL: Issues, https://github.com/pablobernabeu/theoryforge/issues
Author-email: Pablo Bernabeu <pcbernabeu@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: falsifiability,metascience,psychology,reproducibility,theory
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Scientific/Engineering
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: pyyaml>=6.0
Provides-Extra: dev
Requires-Dist: jsonschema>=4; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Provides-Extra: docs
Requires-Dist: markdown-exec>=1.12.3; extra == 'docs'
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.24; extra == 'docs'
Provides-Extra: render
Requires-Dist: graphviz>=0.20; extra == 'render'
Description-Content-Type: text/markdown

# theoryforge (Python) <img src="https://raw.githubusercontent.com/pablobernabeu/theoryforge/main/python/docs/assets/logo.png" align="right" height="138" alt="theoryforge hex logo" />

<!-- badges: start -->
[![CI](https://github.com/pablobernabeu/theoryforge/actions/workflows/ci.yml/badge.svg)](https://github.com/pablobernabeu/theoryforge/actions/workflows/ci.yml)
[![docs](https://github.com/pablobernabeu/theoryforge/actions/workflows/docs.yml/badge.svg)](https://pablobernabeu.github.io/theoryforge/python/)
[![PyPI](https://img.shields.io/pypi/v/theoryforge)](https://pypi.org/project/theoryforge/)
[![Python versions](https://img.shields.io/pypi/pyversions/theoryforge)](https://pypi.org/project/theoryforge/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/license/MIT)
[![DOI 10.5281/zenodo.21229964](https://zenodo.org/badge/DOI/10.5281/zenodo.21229964.svg)](https://doi.org/10.5281/zenodo.21229964)
<!-- badges: end -->

Systematic theory development: a reproducible workflow for building, developing and testing
scientific theories. This is the feature-parity twin of
[the R package](https://pablobernabeu.github.io/theoryforge/r/) of the same name. The two
produce identical verdicts and byte-identical diagram intermediate representations.

The rendered documentation site, with the API reference and worked guides, is at
<https://pablobernabeu.github.io/theoryforge/python/>.

The [interactive web app](https://pablobernabeu.github.io/theoryforge/apps/py/) runs this
package in your browser via [Pyodide](https://pyodide.org/), with nothing to install. You can
load a theory and run the operations the app offers, from the rigour checklist through to the
literature map, and then get the Python code that reproduces each result. Each figure can be
exported as SVG or PNG.

## Installation

The package is on [PyPI](https://pypi.org/project/theoryforge/):

```bash
pip install theoryforge
```

The optional render extra adds native diagram rendering through `render_diagram()`,
which wraps the DOT views in a `graphviz.Source`:

```bash
pip install "theoryforge[render]"
```

The development version installs from the `python/` subdirectory of the repository:

```bash
pip install "git+https://github.com/pablobernabeu/theoryforge.git#subdirectory=python"
```

To work on the package itself, install an editable checkout with the development extras, from
the `python/` directory of a clone:

```bash
pip install -e ".[dev]"
```

## Quick start

The package includes the example theories and corpora, and `example_path()` gives the path
of each, so the lines below run straight after `pip install`.

```python
import theoryforge as tf

# read + check an existing theory
t = tf.read(tf.example_path("panic-network.theory.yaml"))
t.validate()                       # required fields and enums of the schema
print(t.report("json"))            # 12-item rigour checklist + gate
print(t.diagram("nomological_net"))# Graphviz DOT
# t.render_diagram("nomological_net")  # rendered inline; needs theoryforge[render]
t.redundancy_check()               # lexical jingle-jangle screen

# BUILD a theory programmatically (provenance auto-logged)
b = (tf.new_theory("panic_demo", "A demonstration theory of panic")
       .add_construct("arousal", "Physiological arousal", "bodily signs of sympathetic activation",
                      measurement=["heart_rate", "skin_conductance"], boundary_conditions=["adults"])
       .add_construct("catastrophic_interpretation", "Catastrophic interpretation",
                      "appraisal of bodily sensations as dangerous", measurement=["bsiq"])
       .add_proposition("p1", "arousal", "catastrophic_interpretation", "increases",
                        mechanism="rising arousal is read as evidence of threat")
       .add_prediction("pred1", "higher arousal predicts more catastrophic interpretation",
                       "directional", derives_from=["p1"]))
b.validate(full=True)              # also every type, unique ids and every cross-reference

# DEVELOP: appraise an amendment by content, as progressive, degenerating or neutral.
# v2 adds a proposition and a prediction derived from it, which a registered test corroborates.
v1 = tf.read(tf.example_path("panic-network.theory.yaml"))
v2 = tf.read(tf.example_path("panic-network-2026-v2.theory.yaml"))
print(v2.appraise_amendment(v1))   # -> {'verdict': 'progressive', ...}

# TEST: the pre-data severity rubric + a preregistration document
t.severity()                       # per-prediction risk + computed severity
print(t.preregister())             # markdown prereg

# LITERATURE: map the field, then position the theory against it
corpus = tf.read_corpus(tf.example_path("panic-corpus.yaml"))
tf.litmap(corpus)                  # keyword co-occurrence, themes, co-citation
t.landscape(corpus)                # -> each theme under_theorised, covered or crowded, with matched words
# tf.fetch_corpus("panic disorder theory")  # optional OpenAlex fetch (network call)
```

`example_names()` lists the bundled files, and a theory of your own is read the same way,
from the path of its YAML or JSON file.

## Test

The suite is offline and runs from the same directory as the editable install:

```bash
pytest
```

## What the package provides

The deterministic core covers theory-object I/O and validation, the 12-item rigour checklist
with its weighted aggregate score and blocker gate, ten diagram exporters and a lexical
redundancy screen. The validation is built in, and `validate(full=True)` checks the schema's
required fields, types and enums and every cross-reference. CI checks it against a JSON Schema
2020-12 validator.

The three workflow modes operate on the same object. BUILDING is a builder API that logs its
own provenance. DEVELOPMENT is the Lakatosian appraisal of an amendment. TESTING is the
severity rubric, a pre-data ranking of claim form, with its preregistration export. It also
includes `post_data_severity`, which computes how severely a bounded prediction passed its test
from the estimate and standard error recorded in its test outcome.

The literature layer starts from `read_corpus`. `litmap` derives keyword co-occurrence,
deterministic connected-component themes and co-citation, and warns when one theme holds most of
the linked keywords, which happens on real corpora. `litmap(corpus, method="simple_centres")`
gives bounded co-word themes with their centrality, density and strategic-diagram quadrant
instead, as the frozen OpenAlex corpus `openalex-panic-2026.corpus.yaml` shows. `landscape`
maps a theory and its alternatives onto those themes, names the words behind each match and
marks each theme under-theorised, covered or crowded by how many of the registered accounts
address it.
`lit_diagram` draws the co-occurrence, co-citation and theme-landscape views. Where a network
connection is available, the `fetch_corpus` OpenAlex adapter retrieves a corpus.
`new_evidence_dois` checks deterministically which candidate DOIs, from any search tool, a
theory does not yet cite.

Beyond the modes, `compile_sem` translates constructs and propositions to lavaan model syntax,
and `dossier` assembles a reviewer-facing audit bundle. `simulate` runs the construct network
as a deterministic dynamical system, `render_report` wraps the dossier in a Quarto report,
`embedding_redundancy` adds an opt-in, embedder-dependent screen, and `osf_push` deposits to
OSF, dry-run by default.

## Citation

Please cite theoryforge if it contributes to work you publish. The
[About page](https://pablobernabeu.github.io/theoryforge/python/about/) carries the citation
with a BibTeX entry, and a short note on the developer. The citation gives the concept DOI of
the Zenodo archive, <https://doi.org/10.5281/zenodo.21229964>, since PyPI assigns no DOI. The
archive holds every GitHub release of both packages. The repository also includes
`CITATION.cff`, which GitHub uses for its 'Cite this repository' button.

## Licence

MIT. See [LICENSE](https://github.com/pablobernabeu/theoryforge/blob/main/python/LICENSE).

## Contributing

Issues and pull requests are welcome. The [contributing
guide](https://github.com/pablobernabeu/theoryforge/blob/main/.github/CONTRIBUTING.md)
describes the development setup and the conventions the package follows, and everyone taking
part is asked to honour the [Code of
Conduct](https://github.com/pablobernabeu/theoryforge/blob/main/.github/CODE_OF_CONDUCT.md).

Continuous integration lints, type-checks and tests the package on every push to `main`
and on every pull request, and the cross-language parity check compares its output against
the R twin on every fixture.
