Skip to main content

PyPI CICD Downloads

pandoc-run-python

This is a Pandoc filter!

More specifically it is a filter that allows you to run Python code blocks in your markdown and insert the output of them back into your markdown file. It exists because I enjoy literate programming too much.

It supports capturing the following output of Python code blocks:

  • anything printed to stdout
  • matplotlib-based figures

Warning 🚨

Make sure that you trust the Python code in your markdown files, they will be executed as-is. A cell with content like os.system("sudo rm -rf /") would be painful. In other words, if at any point in the future I send you a markdown file called money_factory.md you should NOT run it.

How to install

pip install pandoc-run-python

Also check out the notes on auto-formatting for information on how to install black as a dependency.

What does it do?

Let's say you have the following markdown file:

## What is fast, loud and crunchy?

```python
print("A rocket chip!")
```

When you use this as en example to explain what the output of this print statement would be, you'd probably don't want to type the expected output of this command manually. Ideally you want it to be actually evaluated and the output inserted into the markdown file. This way you would automatically end up with something like this:

## What is fast, loud and crunchy?

```python
print("A rocket chip!")
```

```
A rocket chip!
```

pandoc-run-python to the rescue!

Coincidentally, the above is exactly what the pandoc-run-python filter provides. How can you achieve this? You need to slightly alter your markdown to specify that a python codeblock needs to be evaluated. More specifically you need to add classes to the codeblock as we did below (I don't like the syntax neither, but this is the pandoc way to do it).

## What is fast, loud and crunchy?

``` {.python .run}
print("A rocket chip!")
```

If the previous example would be in a file call loud.md, using this pandoc filter you could execute the following command to generate the processed markdown.

pandoc loud.md -F pandoc-run-python -t markdown
## What is fast, loud and crunchy?

``` {.python .run}
print("A rocket chip!")
```

``` {.python-output}
A rocket chip!
```

Auto-formatting

By default, black is run on all code chunks that have the python class, also those that do not have the run class. You can avoid this auto-formatting behaviour by adding the no-black class to the code chunk.

However, black is an optional dependency. If it cannot be imported code formatting will be skipped. You can install this package also together with black by running pip install pandoc-run-python[black].

Code chunk configuration

This filter runs on all code chunks that has at least the python and run class.

The following classes are used to determine filter logic:

  • python and run: evaluate code and insert output in a new codeblock / image below the original python codeblock
  • no-black: skip running of the black formatter on python code chunks

Metadata

Release files for pandoc-run-python 0.1.25

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

Source distribution (sdist)

Source distribution for pandoc-run-python 0.1.25
File Size Uploaded Provenance Actions
pandoc_run_python-0.1.25.tar.gz 5.8 kB Without provenance Details for pandoc_run_python-0.1.25.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pandoc-run-python 0.1.25
File Interpreter ABI Platform Actions
pandoc_run_python-0.1.25-py3-none-any.whl Python 3 none any Details for pandoc_run_python-0.1.25-py3-none-any.whl

Total release size: 12.3 kB

Release files / pandoc_run_python-0.1.25.tar.gz

Download URL pandoc_run_python-0.1.25.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4a66e3a1054ae9a324067fb7ccdfd551644bf696250cdbd8b75855878e451c36
BLAKE2b-256 checksum
How to use checksums
cdcb8aedc6233f9fe43a20a4ed5b205bf847161a25a75018662fcf44da4de8db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release files / pandoc_run_python-0.1.25-py3-none-any.whl

Download URL pandoc_run_python-0.1.25-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5bd8bd7f655f483f2ccbf252a3345ee2635ea1015678f27c64f6b22df455ceb3
BLAKE2b-256 checksum
How to use checksums
3c490479d2f96df69bd77e94c92a8b2e5a7d0dc7fc16c395d18d0b147b7377f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Security for pandoc-run-python 0.1.25

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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