Skip to main content

oarepo-previewer

OARepo module delivering contrib previewers to invenio-previewer for custom file extensions.

Installation

pip install oarepo-previewer

The Flask app extension (registered via the invenio_base.apps entry point) inserts the previewers listed in OAREPO_PREVIEWER_ENABLED at the front of invenio-previewer's PREVIEWER_PREFERENCE.

Shipped previewers

Molecular Viewer (mol)

A unified molecular structure previewer powered by Molstar, supporting a wide range of molecular and crystallographic file formats:

Extension Format
.mvsj MolViewSpec JSON description
.mvsx MolViewSpec ZIP container
.pdb Protein Data Bank
.ent PDB legacy format
.cif Crystallographic Information File
.bcif Binary CIF (compressed)
.mcif Magnetic CIF
.mmcif Macro-molecular CIF
.mol / .sdf / .sd MDL Molfile
.mol2 Tripos Mol2
.gro GROMACS structure
.xyz XYZ coordinate format
.pdbqt PDBQT (AutoDock)

The previewer leverages Molstar's native support for these formats, providing 3D visualization directly in the browser. Configuration is handled via the template which loads Molstar and initializes the viewer with the file URI.

Configuration

# invenio.cfg
OAREPO_PREVIEWER_ENABLED = ["mol"]  # default
OAREPO_PREVIEWER_MOL_MAX_FILE_SIZE_BYTES = 200 * 1024 * 1024

Set OAREPO_PREVIEWER_ENABLED = [] to manage PREVIEWER_PREFERENCE manually.

Content Security Policy (Molstar)

Molstar may issue fetch calls to external databases when a previewed file (e.g. an .mvsj/.mvsx MolViewSpec description) contains URLs pointing to remote resources. If your app sets APP_DEFAULT_SECURE_HEADERS, the default Content Security Policy will block these requests, so the policy needs to be relaxed for the molecular viewer to work.

invenio.cfg settings could be for instance:

# invenio.cfg
APP_DEFAULT_SECURE_HEADERS = {
    "content_security_policy": {
        "default-src": [
            "'self'",
            "fonts.googleapis.com",
            "*.gstatic.com",
            "data:",
            "'unsafe-inline'",
            "blob:",
            "http://127.0.0.1:9000/",  # Development S3 server
            "https://licensebuttons.net/",
        ],
        "script-src": [
            "'self'",
            "blob:",
            "'wasm-unsafe-eval'",
        ],
        "connect-src": [
            "'self'",
            "http://127.0.0.1:9000",  # Development S3 server
            "https://*.rcsb.org",  # RCSB PDB (Protein Data Bank)
            "https://*.ebi.ac.uk",  # EBI (European Bioinformatics Institute)
            "https://*.pdbj.org",  # PDBj (Protein Data Bank Japan)
            "https://modelarchive.org",  # ModelArchive
            "https://*.expasy.org",  # ExPASy
            "https://pubchem.ncbi.nlm.nih.gov",  # PubChem
        ],
    }
}

The connect-src database entries are actually only needed if previewed files reference remote resources — Molstar fetches them from the databases above. If your records never contain such references, you can omit them (or add more if needed). Keep the development S3 entries (127.0.0.1:9000) out of production deployments and replace them with your actual file storage origin.

Adding a contrib previewer

  1. Create a module in oarepo_previewer/previewers/ exposing previewable_extensions (list of extensions without a dot) and the can_preview(file) / preview(file) functions — see (invenio_previewer/extensions/json_prismjs.py) for the contract. Templates go to oarepo_previewer/templates/semantic-ui/oarepo_previewer/.

  2. Register it in pyproject.toml:

    [project.entry-points."invenio_previewer.previewers"]
    mol = "oarepo_previewer.previewers.mol "
    
  3. Add its name to the default OAREPO_PREVIEWER_ENABLED in oarepo_previewer/config.py.

Development

./run.sh --help   # oarepo library runner (tests, linting, ...)
./run.sh tests

License

MIT — Copyright (C) 2026 CESNET z.s.p.o. See the LICENSE file.

Metadata

Release files for oarepo-previewer 1.0.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 oarepo-previewer 1.0.0
File Size Uploaded
oarepo_previewer-1.0.0.tar.gz 12.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for oarepo-previewer 1.0.0
File Interpreter ABI Platform
oarepo_previewer-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.9 kB

Release files / oarepo_previewer-1.0.0.tar.gz

Download URL oarepo_previewer-1.0.0.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6f4c1143b532256bdf6554e938678787211862cd50f4823e16197d965ce10702
BLAKE2b-256 checksum
How to use checksums
59554e05d0b1ec24fb47a28c454bae9bbee318b3c36bda3a57b13826edc42876
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / oarepo_previewer-1.0.0-py3-none-any.whl

Download URL oarepo_previewer-1.0.0-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f5a4192d36088cae9c880769ba5acee86e114b2e66e85b1d8cfde79d948df4e6
BLAKE2b-256 checksum
How to use checksums
987c06ace3241b44e82da733272bcea177ca4c6e95435afa93c69981d5d2074c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

1.0.1

2 release files

This release

1.0.0 This release

2 release files

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