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

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

docs:

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

Acknowledgements

Release files for merkury 0.12

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.12
File Size Uploaded
merkury-0.12.tar.gz 35.7 kB Details

Built distribution (wheel)

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

Total release size: 70.3 kB

Release files / merkury-0.12.tar.gz

Download URL merkury-0.12.tar.gz
Size 35.7 kB
Tags Source
SHA-256 checksum
How to use checksums
16cae0bf1858c5f97d4b9ecacfb3801bc9dd7cff112bc0f15140358ac3ff12ee
BLAKE2b-256 checksum
How to use checksums
ed07f2ed1d4ee7c68fe6ee0fa7d56357f2a3e86f62ce5c277d20dcc22d66b6c1
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.12-py3-none-any.whl

Download URL merkury-0.12-py3-none-any.whl
Size 34.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c52486bf3ab3c25e86600d2ad730127188a3c4d693c57e1db4355c12d8102c13
BLAKE2b-256 checksum
How to use checksums
0b423ff91771cb0fc096a6e2b9b1adbb368f408d08143403d1ce35e782c87e37
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

0.13

2 release files

This release

0.12 This release

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