Jupyter extension which executes Rust functions in Python
Project description
rustdef
Jupyter extension for jupyter notebook and rust user.
You can define functions in rust and run them as python functions. This extension is built on PyO3 and maturin.
Examples
Prerequisite
- Python >= 3.6 and pip >= 19.3
- Jupyter notebook
- Rust
- cargo-edit
Install
$ pip install rustdef
Usage
Define rust functions,
%%rustdef
#[pyfunction]
fn my_func(x: i64, y: &str) -> i64 {
println!("{}", y);
x + y.len() as i64
}
Add dependencies, (e.g. num
crate)
%rustdef deps add num@0.4.0
Defined dependencies are valid only in the current notebook.
Show dependencies,
%rustdef deps show
num = "0.4.0"
[pyo3]
version = "0.13.2"
features = [ "extension-module",]
pyo3
is included by default.
Develop
How it works?
Roughly, definitions in rustdef are available in python after the following steps.
- Each rustdef magic cell is populated with module definition of pyo3
- A new crate is generated for the rustdef cell
- The crate is compiled into a python wheel by
maturin
- Install the wheel with pip
- Functions with
#[pyfunction]
attributes are exported into interpreter name space in notebook - Ready to call the function in notebook!
Build
maturin
is required.
$ pip install maturin
$ maturin build
$ pip install target/wheels/rustdef-{version}-{python}-{platform}.whl
ToDo
- execute within rustdef cell
- class/module supports
- customizable module name
- use functions defined in another cell
- verbose flag
- serde support
- windows support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distributions
Close
Hashes for rustdef-0.3.1-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77d0a6bb890fb7ab8883f66e94a6e5026a2036d7ac642374be4a662961fd7b64 |
|
MD5 | 7fb040595c7cb892c98793421ff72b22 |
|
BLAKE2b-256 | a88a6413fae0d1eae2b46e00b7c490dfa9fc62a30385871ea582114b89fb3097 |
Close
Hashes for rustdef-0.3.1-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3d802213beba3edbe6c9c19a7eea9f7f953a9d875285a8569bbfa748e81a0dc |
|
MD5 | 8266e38d59098491ed06f78d2386bb12 |
|
BLAKE2b-256 | 47aee91fc0c2cf998d2e9f57ef1dcb2004c1a886deba690fe68ec8d687f6d27b |
Close
Hashes for rustdef-0.3.1-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e8033705e7dadbbd71ef46611c299747d41726e46144318da746217e9434bed |
|
MD5 | 1c4409e0f50d535c410aed0ac448b576 |
|
BLAKE2b-256 | e5375e4631881419bea63bb629dfdf5e5c11a59c14d25c3da4e09f9bca23caa1 |
Close
Hashes for rustdef-0.3.1-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e5739065aecc9ddb08ed48d462a214d53adaa11a26697d80e9ee117dca6974a |
|
MD5 | f3293446e66d83dd017a03cff34393d3 |
|
BLAKE2b-256 | 81d61c993cd9f9c9ab937627d32efd7aff920ec69ed85ae1777ec79c791ca629 |
Close
Hashes for rustdef-0.3.1-cp37-cp37m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b067445c7a89314440dc98a3eb7a2d47ba6e4ec95fbfa3956f7a1c84214f95e8 |
|
MD5 | 8a19e2f394008d9460472c811b14d424 |
|
BLAKE2b-256 | e29761507e22122980a91b072fc2fa409946ead9aa205b06de6ee2975457b5ff |
Close
Hashes for rustdef-0.3.1-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e848e91969af55b3454843f1bb24f4c8906dea1206ac626f49b36338461c4321 |
|
MD5 | 78f099fd7d70705820977815f1064798 |
|
BLAKE2b-256 | f5041a0105d9360cfc6f682fe314d7f5932e682f3ecb1e3432d065ecd49e6d06 |
Close
Hashes for rustdef-0.3.1-cp36-cp36m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 074acfa3b0bfbcff7d24d4c3c27f78a32fa8ce7c12366b255710c5b19c88c041 |
|
MD5 | 17b49aa4c9e9f5c30576234cdc1baf44 |
|
BLAKE2b-256 | f588d205b20e5a45e058a788f742d8234b264fc64abb1376ee953c4f394359e0 |
Close
Hashes for rustdef-0.3.1-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcc75298e9ca18d2184f34ad3c1dfc7fed5f3d002527fbf3bd1f9c096b5f4afe |
|
MD5 | 4e18cf2284ced4a13ba6e1cd481a1b17 |
|
BLAKE2b-256 | d1264e10a6d0a7d187bbd590fcdc76fc0409362a05e73283b3da7fb7a4059b47 |