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 PDF reports with code and produced output. It uses standard .py files as input - any valid Python 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 python code run, 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).

NOTE: this is an early experimental project, stuff might break and change

Installation

pip3 install merkury

Usage

$ merkury -h
merkury

Usage:
    merkury [-o <file>] [-f <format>] [-t <theme>] <script>

Options:
    -h --help                       Show this screen.
    -o <file>, --output <file>      Specify output file (if missing, "<script_name>_<date>").
    -f <format>, --format <format>  Specify format: html (default), pdf.
    -t <theme>, --theme <theme>     Specify color theme: dark (default), light. Valid for HTML output.
    -v, --version                   Show version.

Formatting and plots

By default merkury treats any output as simple print and puts it into <code> blocks. There is also a possibility to treat it as either raw HTML or markdown. This is achieved 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.

Example:

print("""<img src="https://www.python.org/static/img/python-logo-large.c36dccadd999.png" alt="python">""")
#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 print 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.3.tar.gz (23.7 kB view hashes)

Uploaded Source

Built Distribution

merkury-0.3-py3-none-any.whl (24.8 kB view hashes)

Uploaded Python 3

Supported by

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