Skip to main content

lexsync (Python)

PyPI python-tests Lifecycle: experimental Code: MIT Data: CC BY-SA 4.0 DOI 10.5281/zenodo.22906962

Lexical optimisation and hardware-timed experiment generation.

lexsync selects stimuli matched in parallel across several lexical dimensions (length, frequency, orthographic neighbourhood density and OLD20), counterbalances them across conditions and lists, and generates the 'PsychoPy', 'OpenSesame' and 'jsPsych' scripts that present them. The two laboratory targets carry hardware triggers injected at stimulus onset for EEG/ERP synchronisation, and the browser target is a single shareable HTML file.

This is the feature-parity twin of the R package of the same name. The two are built from one repository and released under one version, and their engines select byte-identical stimuli under the deterministic matching methods.

Documentation, including the guides and the API reference, is at https://pablobernabeu.github.io/lexsync/python/.

Install

The package is on PyPI:

pip install lexsync

The corpora extra adds the 'wordfreq' connector, which builds lexica for thirty registered languages ('wordfreq' covers 42) through a single dependency, and the experiment extra adds 'PsychoPy' and 'pyserial'. The experiment extra is needed only to run a generated experiment on hardware, not to generate one. 'PsychoPy' currently supports Python 3.10 to 3.12. On a newer interpreter, installing that extra fails with a message naming psychopy, while the rest of the package installs on any supported version. Getting started explains why and suggests an interpreter for hardware work. An extra goes in brackets after the package name:

pip install "lexsync[corpora]"
pip install "lexsync[experiment]"

The development version installs from the repository, where the Python package sits in the python_workflow/ subdirectory:

pip install "git+https://github.com/pablobernabeu/lexsync.git#subdirectory=python_workflow"

Quick start

The package bundles a 3000-word slice of an English lexicon and a copy of the global schema, so the example below runs straight after installation, from any working directory, with no corpus to download and nothing to configure. It contrasts high- with low-frequency words while equating them, item by item, on length, orthographic neighbourhood density and OLD20.

from importlib.resources import files

import yaml

import lexsync

data = files("lexsync") / "data"
schema = yaml.safe_load((data / "schema.yaml").read_text(encoding="utf-8"))

design = {
    "name": "quick_start",
    "language": "english",
    "n_per_condition": 60,
    "pool_filters": {"length": [3, 8], "frequency": [3.8, 7.0]},
    "conditions": [
        {"name": "high_frequency", "define_by": {"frequency": [5.2, 7.0]}},
        {"name": "low_frequency", "define_by": {"frequency": [3.8, 4.4]}},
    ],
    "match_on": ["length", "n_density", "old20"],
    "counterbalance": {"lists": 1},
}

lexicon = lexsync.load_lexicon(str(data / "en_example.csv"), schema, language="english")
pool = lexsync.build_pool(lexicon, design["pool_filters"])
stimuli = lexsync.match_stimuli(pool, design, schema)

report = lexsync.match_report(
    stimuli, ["length", "frequency", "n_density", "old20"], schema
)
print(report["comparisons"].to_string(index=False))

The report measures what the matching achieved. Frequency, the manipulation, separates the conditions by nearly five standard deviations. Each control dimension passes a two one-sided tests procedure against a bound of d = 0.5, so it is shown to be equivalent rather than merely failing to differ significantly. The Matching and designs guide explains the report column by column.

Use

The example below builds a matched stimulus set from a design file and writes the experiment scripts for it. It reads the schema, the derived corpus and the design from the repository, so clone the repository and run it from the root of the clone:

git clone https://github.com/pablobernabeu/lexsync.git
cd lexsync
import yaml, lexsync

schema = yaml.safe_load(open("config/schema.yaml"))
design = yaml.safe_load(open("config/design_en_freqcontrast.yaml"))
lex = lexsync.load_lexicon(design["lexicon"], schema, "english")   # en_v2.csv

# The design leaves out the words its exclude_words file lists, as `lexsync run` does.
with open(design["exclude_words"]["path"], encoding="utf-8") as handle:
    excluded = {w.strip() for w in handle if w.strip() and not w.startswith("#")}
lex = lex[~lex["word"].isin(excluded)]
pool = lexsync.build_pool(lex, design["pool_filters"])
stim = lexsync.match_stimuli(pool, design, schema)
# Not optional: this assigns the counterbalancing lists and draws the trial
# order. Exporting without it writes every trial of one condition and then every
# trial of the next, with no `trial` column and no `list` column.
stim = lexsync.counterbalance(stim, design, schema)

report = lexsync.match_report(stim, ["length", "frequency", "n_density", "old20"], schema)
lexsync.export_experiments(stim, design, schema, "output/experiments")

The same operations are available from the command line. The first command below runs a whole design, again from the root of the clone, and the other two list the registered corpora and derive a new lexicon:

lexsync run config/design_en_freqcontrast.yaml
lexsync corpora list
lexsync fetch fr            # build a French lexicon via wordfreq

Outside a clone, name the schema with --schema or leave it out. When it is left out, lexsync run looks for schema.yaml beside the designs and falls back to the copy bundled with the package. It reports on standard error which file it used. A command that fails prints lexsync's message and exits with status 1, and lexsync --traceback run ... shows the Python traceback as well.

Citation

Cite the software. The authoritative record is CITATION.cff at the root of the repository, which GitHub renders into several formats through its 'Cite this repository' button. PyPI assigns no DOI, so the formatted reference for this package on the About page gives its version and the concept DOI of the Zenodo archive, https://doi.org/10.5281/zenodo.22906962. CITATION.cff describes both packages, so it gives the same DOI and lists each package's identifiers, among them the DOI that CRAN assigned to the R package. A manuscript describing lexsync is in preparation.

Cite the corpus as well as the software. The corpora are third-party work with their own terms, and each is credited, with its licence and retrieval date, in corpora/ATTRIBUTION.md.

Licence

MIT for the code. The bundled corpus derivatives are released under CC BY-SA 4.0 instead. They are the three example lexica installed as lexsync/data/en_example.csv, lexsync/data/es_example.csv and lexsync/data/zh_example.csv, derived from 'wordfreq' and, for English, screened against SUBTLEX-US. CC BY-SA 4.0 asks anyone who redistributes them to credit the corpus authors, say that changes were made and keep the same terms on any adaptation. LICENSE.note, installed alongside LICENSE, states these terms inside the distribution. The repository keeps the fuller record, including the retrieval date and checksum of every derived file, in LICENSE-DATA.

Contributing

Issues and pull requests are welcome, on the issue tracker of the repository that holds both twins. A report that includes the design YAML and the run log can be acted on, because together they record the inputs and every step that ran.

Metadata

Release files for lexsync 0.2.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 lexsync 0.2.0
File Size Uploaded Provenance Actions
lexsync-0.2.0.tar.gz 552.9 kB With provenance Details for lexsync-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 882.6 kB

Release files / lexsync-0.2.0.tar.gz

Download URL lexsync-0.2.0.tar.gz
Size 552.9 kB
Tags Source
SHA-256 checksum
How to use checksums
acb988c2451380f005afcb242192af06499432b15cc82c92dfe7dca7ac252e8e
BLAKE2b-256 checksum
How to use checksums
5f26cfa3b13e75a01fa6a3c4aa76d616d2568174654f77800ba1d5ce91793f7d
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 / lexsync-0.2.0-py3-none-any.whl

Download URL lexsync-0.2.0-py3-none-any.whl
Size 329.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a1b6be4fd9df5f3291469f11d313e4db69253ef75e0afb89189c28b43254edc
BLAKE2b-256 checksum
How to use checksums
511f3577fda832c5eb67e298ff1be4526e800c918e74fdfb2837c2f336ea359b
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 lexsync 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.

Full provenance

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

Select from 2 files

Attestation for lexsync-0.2.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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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