https://github.com/ruivieira/crystal-holst
A Crystal Jupyter notebook parser
https://github.com/ruivieira/crystal-holst
crystal jupyter parser
Last synced: 3 months ago
JSON representation
A Crystal Jupyter notebook parser
- Host: GitHub
- URL: https://github.com/ruivieira/crystal-holst
- Owner: ruivieira
- License: agpl-3.0
- Created: 2021-03-31T21:21:09.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-04-01T21:10:54.000Z (over 4 years ago)
- Last Synced: 2025-07-21T09:56:41.738Z (4 months ago)
- Topics: crystal, jupyter, parser
- Language: Crystal
- Homepage: https://ruivieira.github.io/crystal-holst/
- Size: 801 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# holst

A parser for Jupyter notebooks.
## installation
Add the dependency to your `shard.yml`:
```yaml
dependencies:
holst:
github: ruivieira/crystal-holst
```
and run `shards install`.
## examples
Parse a Jupyter notebook with `Holst::JupyterFile`:
```crystal
require "holst"
notebook = Holst::JupyterFile.new(file_path: "/path/to/notebook.ipynb")
```
Print the kernel spec and name:
```crystal
notebook.content.metadata.kernelspec # => "my-python-3.9
notebook.content.metadata.language # => python
```
Get all images in a notebook. This returns an array of `Bytes` that you can save directly to a file.
```crystal
counter = 1
notebook.images.each { |img|
File.write("image-#{i}.png", img)
counter += 1
}
```
Alternatively, call `export_images` to bulk save.
```crystal
notebook.export_images
```
By default images are save in a sub-folder `images` with prefix `images-$counter.png`. You can specify other values.
```crystal
notebook = Holst::JupyterFile.new(file_path: "/path/to/notebook.ipynb",
image_prefix: "diagram",
image_dest: "/some/other/path")
```
will save images as `/some/other/path/diagram-1.png`, `/some/other/path/diagram-2.png`, etc.
## compatibility
`holst` works with Jupyter notebooks with format 4+.
## documentation
API documentation is available [here](https://ruivieira.github.io/crystal-holst).
A git mirror is available at [https://git.sr.ht/~ruivieira/crystal-holst](https://git.sr.ht/~ruivieira/crystal-holst).