Skip to main content

Knitj

python pypi commits since last commit license code style

Knitj is an alternative front-end to Jupyter kernels. Inspired by knitr and R Markdown, Knitj renders a mix of markdown and source code into HTML by evaluating the code in a Jupyter kernel.

In addition to a one-off conversion, Knitj can serve the HTML document via HTTP and watch the source file for changes. When the source file is changed, Knitj reevaluates only the changed bits (defined by boundaries between markdown and source code), and pushes the updates into the HTML document via WebSocket.

Example

Either of the two following files renders into the same HTML document below with

knitj $SOURCE >$SOURCE.html
```python
#::hide
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
```

## Example

Let's plot

$$ f(x)=\frac{\sin x}x $$

```python
x = np.linspace(-20, 20, 200)
plt.plot(x, np.sin(x)/x)
```
# ::hide
import numpy as np
from matplotlib import pyplot as plt
# ::%matplotlib inline

# ::>
# ## Example
#
# Let's plot
#
# $$ f(x)=\frac{\sin x}x $$

x = np.linspace(-20, 20, 200)
plt.plot(x, np.sin(x)/x)

Alternatively, one can start the Knitj server, which starts watching the source file for changes and opens a browser window with the rendered and live-updated HTML document

$ knitj --server test.py
[22:19:14.718] INFO:knitj: Entered Knitj
[22:19:14.722] INFO:knitj.document: File change: 3/0 new cells, 0 dropped
[22:19:14.732] INFO:knitj.document: 2 code cells loaded from output
[22:19:14.732] INFO:knitj.kernel: Starting kernel...
[22:19:15.145] INFO:knitj.kernel: Kernel started
[22:19:15.160] INFO:knitj.knitj: Started web server on port 8081
[22:19:15.441] INFO:knitj.knitj: Started broadcasting to browsers
[22:19:15.462] INFO:knitj.source: Started watching file test.md for changes
[22:19:15.881] INFO:knitj.webserver: Browser connected: 4542074160
[22:19:41.477] INFO:knitj.document: File change: 1/3 new cells, 1 dropped
[22:19:41.683] INFO:knitj.document: 72fea2: Got an error
[22:19:41.698] INFO:knitj.document: 72fea2: Cell done
[22:19:41.716] INFO:knitj.document: 72fea2: Got an error execution reply
^C[22:19:46.179] INFO:knitj.webserver: Closing websockets
[22:19:46.180] INFO:knitj.webserver: Browser disconnected: 4542074160
[22:19:46.181] INFO:knitj.kernel: Kernel shut down
[22:19:46.186] INFO:knitj: Leaving Knitj

Installing

Install and update using Pip.

pip install -U knitj

The following dependencies are installed:

To use Knitj, you also need some Jupyter kernel on your system. If you don’t have one, you can get the IPython kernel with

pip install ipykernel

Usage

usage: knitj [-h] [-s] [-f FORMAT] [-o FILE] [-k KERNEL] [-b BROWSER] [-n]
             [FILE]

positional arguments:
  FILE                  input file

optional arguments:
  -h, --help            show this help message and exit
  -s, --server          run in server mode
  -f FORMAT, --format FORMAT
                        input format
  -o FILE, --output FILE
                        output HTML file
  -k KERNEL, --kernel KERNEL
                        Jupyter kernel to use
  -b BROWSER, --browser BROWSER
                        browser to open
  -n, --no-browser      do not open a browser

Metadata

Release files for knitj 0.2.2

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

Source distribution (sdist)

Source distribution for knitj 0.2.2
File Size Uploaded
knitj-0.2.2.tar.gz 38.5 kB Details

Built distribution (wheel)

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

Total release size: 167.9 kB

Release files / knitj-0.2.2.tar.gz

Download URL knitj-0.2.2.tar.gz
Size 38.5 kB
Tags Source
SHA-256 checksum
How to use checksums
374542a544c66b6c21a4bdecd8349c6589942f5dd681f5f3fa5403d2520fd92f
BLAKE2b-256 checksum
How to use checksums
97e930124e55e47c5f81c68ac468d86654348b3a12b61dbf40ec5eabee11ea01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.4 CPython/3.6.6 Darwin/18.0.0

Release files / knitj-0.2.2-py3-none-any.whl

Download URL knitj-0.2.2-py3-none-any.whl
Size 129.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f54d37e064dec6c3abe748116d50fd3967adb824eebcc175f5a3a03b0f7ee1b9
BLAKE2b-256 checksum
How to use checksums
e9cf36e7bf91e4626bfb20a3e94d00fbe6f51c264ef213c9f02feff7ed2fd385
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.4 CPython/3.6.6 Darwin/18.0.0

Release history Release notifications | RSS feed

0.3.1

2 release files

0.3.0

2 release files

This release

0.2.2 This release

2 release files

0.2.1

1 release file

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