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

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.1
File Size Uploaded
oarepo_previewer-1.0.1.tar.gz 12.6 kB Details

Built distribution (wheel)

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

Total release size: 31.9 kB

Release files / oarepo_previewer-1.0.1.tar.gz

Download URL oarepo_previewer-1.0.1.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2b142e2d9edb63a95e106a5f7b72ec0c162cf1d147b7d42c2f4beed99a32e848
BLAKE2b-256 checksum
How to use checksums
dac2dcab8820deb2bc4d5e1bbe1a8a9fea241512716307c92d34bdf3cdb96fed
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.1-py3-none-any.whl

Download URL oarepo_previewer-1.0.1-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29d2f8826bb295dad09a79e372b4bc91fcf3d0e102f04618af42ccf851346124
BLAKE2b-256 checksum
How to use checksums
8d548a867394bd36b61831e47eb14c8078b7a733bd295385fcdac0190d83bb4b
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

This release

1.0.1 This release

2 release files

1.0.0

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