Skip to main content

Lightweight Rust integration in Jupyter notebook

Project description

rust-magic Build Status

Allows to try rust in Jupyter notebook. Implemented via line/cell magics:


  1. Install rust and jupyter-notebook

  2. cargo install cargo-script

  3. pip install rust-magic

  4. Enjoy :)

Third-party crates

are supported via normal cargo script syntax (see below for a more compact notation):

Compiler options

can be provided in the cell mode:

NB Here's a copy-pastable form of all the examples above.

Syntax highlighting

To enable rust syntax highlighting in %%rust cells run the following snippet in a python jupyter cell:

from import ConfigManager
c = ConfigManager()
c.update('notebook', {"CodeCell": {"highlight_modes": {"text/x-rustsrc": {"reg": ["^%%rust"]}}}})

This only needs to be run once: it stores the setting in a config file in home directory.

Long cells

Jupyter "doesn't like" long cells: when a cell gets longer than the screen its output is not readily visible. Here're a few ways how to handle the problem with rust_magic:

a) putting dependencies into a separate cell (more)

b) collapsing function bodies with codefolding jupyter extension

c) putting function definitions into separate cells (more)

Faster compile times

can be acheived by caching dependencies compile results with sccache. Rust-magic automatically uses it if it is installed in the system (cargo install sccache).

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

rust_magic-0.3.3.tar.gz (6.6 kB view hashes)

Uploaded source

Built Distribution

rust_magic-0.3.3-py3-none-any.whl (8.4 kB view hashes)

Uploaded py3

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