Skip to main content

Merkury

Merkury is a command line utility to run Python scripts and render static HTML or Markdown reports. It uses standard .py files as input - any valid script that can be run from command line, can also be turned into a report.

It's a lightweight alternative to tools such as jupyter/papermill and can be used as a BI-as-code solution with Python-based workflow.

Non-goals of the project:

  • interactive code execution in the browser (see jupyter),
  • generating data apps that require backend server (see e.g. dash),
  • converting any input into static HTML (see e.g. nikola).

Installation

pip3 install merkury

# if you also need server mode
pip3 install merkury[server]

There is also docker image available:

# default command runs in server mode
podman run \
    --rm \
    -p 8000:8000 \
    -v path/to/script/dir:/etc/merkury/scripts \
    ghcr.io/ppatrzyk/merkury:0.13

Usage

Merkury can run in the following modes:

Single file

merkury -f html -o report.html myscript.py

Batch

Runs concurrently all python scripts inside given directory and produces report for each one.

merkury -f html -o path/to/reports batch path/to/scripts

Server

Starts server that exposes execution endpoints for each script in provided directory.

merkury -s localhost:8000 server path/to/scripts

With this configuration, there is:

  • Homepage with script list at /,
  • For each script (e.g., s.py):
    • Execution endpoint to run it (and refresh report html) at /execute/s,
    • Report endpoint to view latest report at /read/s.

Options

$ merkury -h
merkury

Usage:
    merkury [options] <script_path>
    merkury [options] batch <dir_path>
    merkury [options] server <dir_path>

Options:
    -h --help                         Show this screen.
    -o <file>, --output <file>        Specify report file (if missing, <script_name>.<format>).
    -f <format>, --format <format>    Specify report format: html (default), md.
    -a <author>, --author <author>    Specify author (if missing, user name).
    -t <title>, --title <title>       Specify report title (if missing, script file name).
    -p <count>, --parallel <count>    Parallel processes (if missing, cpu cores).
    -s <address>, --server <address>  Server address (if missing, localhost:8000).
    -d, --timestamp                   Add timestamp to default report file name.
    -i, --no-input                    Hide input blocks in generated report.
    -c, --toc                         Generate Table of Contents.
    -l, --debug                       Print debug messages.
    -v, --version                     Show version and exit.

Source:
    https://github.com/ppatrzyk/merkury

Formatting

Formatting of output inside report is controlled by inserting magic comments inside input script. There are following optional directives:

By default merkury treats any output as standard code print and puts it into <code> blocks. Only If your output is actually HTML or Markdown, you need to indicate that by placing a magic comment inside a code chunk.

HTML

You need to put a comment #HTML after a line that outputs raw HTML. For example:

print(pandas_df.to_html(border=0))
# HTML

In addition to writing HTML by hand or using libraries that allow formatting output as HTML, merkury provides utility functions to format plots from common libraries. See plotting docs for details.

Markdown

It's also possible to render text formatted in markdown. You need to put magic comment #MARKDOWN after print statement.

For example:

print("""
# I'm a markdown header

List:

* l1
* l2

""")
# MARKDOWN

Title

In produced report, code will be broken into sections. Each section ends with a statement printing some output (e.g., print()). You can optionally give titles to each section by placing magic comment #TITLE <your_section_title> inside code chunk.

PDF reports

It is also possible to obtain PDF reports with usage of additional conversion tools (e.g., pandoc). For example:

merkury -o /dev/stdout -f md <your_script> | pandoc --highlight-style=tango -t pdf -o report.pdf

Note, in case your report file contains raw html chunks (such as plots or images), you will need use wkhtmltopdf pdf engine.

DEV

dev installation:

pip3 install -e .[dev,server]

docker build:

podman build -t ghcr.io/ppatrzyk/merkury:0.13 .

docs:

merkury --no-input docs/index.py
merkury --toc docs/intro-py.py
merkury docs/plotting.py

Acknowledgements

Release files for merkury 0.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for merkury 0.13
File Size Uploaded
merkury-0.13.tar.gz 36.6 kB Details

Built distribution (wheel)

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

Total release size: 72.4 kB

Release files / merkury-0.13.tar.gz

Download URL merkury-0.13.tar.gz
Size 36.6 kB
Tags Source
SHA-256 checksum
How to use checksums
238fac232f37236510e2fcd291bb2ee8c469a76ff3983c8bdd18a188fb88c465
BLAKE2b-256 checksum
How to use checksums
e64c65258e5bdbee1cbda4a8339e9e50931709a6ef9390b25201b1a3d2adcf59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.0

Release files / merkury-0.13-py3-none-any.whl

Download URL merkury-0.13-py3-none-any.whl
Size 35.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
967febc851e144903691a3e4bdb58a80d7802325b9e3a2bf2ec057bab30b255a
BLAKE2b-256 checksum
How to use checksums
bcaba9163ae7974c84262b0c6451022d7ccd37c787a6e35fbc5cd1fd592cfb4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.0

Release history Release notifications | RSS feed

0.14

2 release files

This release

0.13 This release

2 release files

0.12

2 release files

0.11

2 release files

0.10

2 release files

0.9

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

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