Skip to main content

theoryforge (Python) theoryforge hex logo

CI docs PyPI Python versions License: MIT DOI 10.5281/zenodo.21229964

Systematic theory development: a reproducible workflow for building, developing and testing scientific theories. This is the feature-parity twin of the R package 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 runs this package in your browser via Pyodide, 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:

pip install theoryforge

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

pip install "theoryforge[render]"

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

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:

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.

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:

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 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.

Contributing

Issues and pull requests are welcome. The contributing guide describes the development setup and the conventions the package follows, and everyone taking part is asked to honour the Code of Conduct.

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.

Metadata

Release files for theoryforge 0.7.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 theoryforge 0.7.0
File Size Uploaded Provenance Actions
theoryforge-0.7.0.tar.gz 303.3 kB With provenance Details for theoryforge-0.7.0.tar.gz

Built distribution (wheel)

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

Total release size: 444.9 kB

Release files / theoryforge-0.7.0.tar.gz

Download URL theoryforge-0.7.0.tar.gz
Size 303.3 kB
Tags Source
SHA-256 checksum
How to use checksums
71d60f3b4e924259f1ede74b18362b55323718a1549d5d149d69285102c3d96e
BLAKE2b-256 checksum
How to use checksums
b14bd084473b02b29eba2f5af49897fa9bca50fead3fee62f85aae5d75b42e95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / theoryforge-0.7.0-py3-none-any.whl

Download URL theoryforge-0.7.0-py3-none-any.whl
Size 141.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d2b98a23f3d7ce9dd8019d1cb857e83f8409c2dfcb2e84bcfa332e7a159488c
BLAKE2b-256 checksum
How to use checksums
3009f51d9ef59307487501c2d8c961da5fce468009aba9dc114dd4a0499bd7af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for theoryforge 0.7.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for theoryforge-0.7.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

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