calbaker/rust_pyo3_clap


Language: Rust


Description

This crate, which I’ll use for the complex example in SEES (after providing a much simpler, less intimidating example), demonstrates:

  • How to make a core crate which conditionally compiles pyo3 interface stuff
  • How to make a pyo3 api crate that exposes the core structs to python
  • How to make a crate that uses clap to make a CLI app using the core crate
  • How to use procedural macros to eliminate boiler plate
  • That rust is ~100x faster than python in solving the Fibonacci sequence to 42 places
  • How to use a cargo workspace to organize a collection of co-dependent crates

How to make it run

Compiling and such

  1. Install rust
  2. At the top level, run cargo test --release, and this will test the code and generate the CLI app in targe/release.
  3. Create and activate a suitable python environment, e.g.
    1. python3.10 -m venv .venv
    2. Activate:
      • linux/unix: source /.venv/bin/activate
      • windows: .\.venv\Scripts\activate.ps1 or .\.venv\Scripts\activate.bat, depending on your terminal environment
  4. run pip install maturin.
  5. run maturin develop --release within fib-py to build the python package.

Stuff you can run

  • python demo.py -- show that rust python is 100x faster than pure python
  • ./target/release/fib-cli 42 -- demonstrate how to run directly as a CLI app

Presentation

sees-rust-as-python-backend.md

Project Statistics

Sourcerank 2
Repository Size 23.4 KB
Stars 1
Forks 0
Watchers 1
Open issues 0
Dependencies 0
Contributors 1
Tags 0
Created
Last updated
Last pushed

Top Contributors See all

Chad Baker

Something wrong with this page? Make a suggestion

Last synced: 2024-02-08 09:12:44 UTC

Login to resync this repository