Skip to main content

Stitch

Build Status

A knitr- RMarkdown-like library, in Python.

Note: You might want to consider Jan Schulz’s knitpy instead. It’s probably more mature at this point. However, I wanted to see if there was a simpler way of doing things.

The high-level goal of this type of library (knitr/RMarkdown, knitpy, and stitch) is to make writing reproducible reports easier.

Documentation is available here.

Examples

See the project’s examples page for a side-by-side comparison of input markdown and stitched HTML.

More complex examples are linked to from there as well.

Install

stitch supports Python 3.5 and above. At the moment stitch can be installed from pip via

pip install knotr

I know, it’s confusing. I’ve filed a claim for stitch on PyPI, but I think the people working that support queue are over-worked. Once that gets processed, I’ll put it up on conda-forge as well. If you need a mnemonic, it’s “I want knitr, but not the one written in R.” Also I wanted to confuse R users. And knots are kind of like a buggy version of knits.

stitch requires pandoc>=1.18. This can be installed using your system package manager, or pypandoc.

Design

The goal was to keep stitch itself extremely simple by reusing existing libraries. A high level overview of our tasks is

  1. Command-line Interface

  2. Parse markdown file

  3. Execute code chunks, capturing the output

  4. Collate execution output into the document

  5. Render to final output

Fortunately the building blocks are all there.

We reuse

  • pandoc via pypandoc for parsing markdown and rendering the final output

  • jupyter for language kernels, executing code, and collecting the output

  • Use pandocfilters to collate the execution output into the document

So all stitch has to do is to provide a command-line interface, scan the document for code chunks, manage some kernels, hand the code to the kernels, pass the output to an appropriate pandocfilter.

The biggest departure from knitpy is the use of pandoc’s JSON AST. This is what you get from pandoc -t json input.md

This saves us from having do any kind of custom parsing of the markdown. The only drawback so far is somewhat inscrutable Haskell exceptions if stitch happens to produce a bad document.

Documentation

Stitch’s documentation has an odd build process, so standard tools like readthedocs weren’t flexible enough. To make the docs, install stitch and all the extra dependencies. Clone https://github.com/pystitch/pystitch.github.io

Checkout the src branch.

Run make html.

Release files for knotr 0.4.1

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

Source distribution (sdist)

Source distribution for knotr 0.4.1
File Size Uploaded
knotr-0.4.1.tar.gz 33.8 kB Details

Built distribution (wheel)

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

Total release size: 56.1 kB

Release files / knotr-0.4.1.tar.gz

Download URL knotr-0.4.1.tar.gz
Size 33.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5647ef7f37a467284c4538e8c17f2ebba698258fbf45c5a68a38d0f9062de000
BLAKE2b-256 checksum
How to use checksums
59f4bfdea99dfe607e11113ff8fa3bd81ff20a2e4b236366f985f119746db504
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / knotr-0.4.1-py3-none-any.whl

Download URL knotr-0.4.1-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b4ca9dd72e96e0cdc6511a73d6301bc734f746722044a721ca36cc8aa080913
BLAKE2b-256 checksum
How to use checksums
786b1af9b92787e9520aa6624ad1aa7f208803e609af5ae7bc17db86b406c953
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

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