Skip to main content

Turn Python scripts into HTML reports

Project description

Merkury

Merkury is a command line utility to run Python scripts and render static HTML or Markdown reports with code and produced output. 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 and papermill. While these have their advantages (and problems), when everything you need is to generate a report from a data analysis script, they might be an overkill. This project is meant to address that scenario.

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

Usage

$ merkury -h
merkury

Usage:
    merkury [options] <script>

Options:
    -h --help                       Show this screen.
    -o <file>, --output <file>      Specify report file (if missing, <script_name>_<date>).
    -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)
    -c, --toc                       Generate Table of Contents
    -v, --version                   Show version and exit.

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.

Formatting and plots

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

Python

When it comes to report formatting, there are 3 types of outputs in a Python script: Standard <code> block (default), HTML, or Markdown.

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

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

Acknowledgements

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

merkury-0.11.tar.gz (29.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

merkury-0.11-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file merkury-0.11.tar.gz.

File metadata

  • Download URL: merkury-0.11.tar.gz
  • Upload date:
  • Size: 29.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for merkury-0.11.tar.gz
Algorithm Hash digest
SHA256 5bd30b0013bb9c24ac736b94238c283bd8c0c08a5134b09d599312f13a23c96b
MD5 b1cf38e051cf09dba0e09787e0c022eb
BLAKE2b-256 0ab7446043d992166daf5f35f4888bd03b29b0296103f834625ee3de11a98a44

See more details on using hashes here.

File details

Details for the file merkury-0.11-py3-none-any.whl.

File metadata

  • Download URL: merkury-0.11-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for merkury-0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 ecc5265519d3e8e05c6ecead5135dcb843bcc2a0248df694fd2126db2dcf38fe
MD5 ac918b37087e16d7776554f1e91187ff
BLAKE2b-256 ad254fc812c1bff016aaac8cb59dcb8f500f914189468251e748e29e9018eb8a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page