Skip to content

Developing Python Library using SEGUL API

We recommend to use PyO3 and Maturin to develop python library using SEGUL API. The PyO3 and Maturin documentation provides a comprehensive guide on how to use the tools. You can also checkout pysegul to see how we use SEGUL API in Python.

  1. Install Rust
  2. Install Maturin
Terminal window
cargo new segul-python --lib
cd segul-python
Terminal window
maturin new
Terminal window
cargo add segul

Or add it manually in your Cargo.toml file:

[dependencies]
segul = "0.*"

Find out more about available SEGUL functions and how to use them in the SEGUL API documentation.

Add the following code in your src/lib.rs:

use pyo3::prelude::*;
use segul::helper::alphabet::DNA_STR_UPPERCASE;
// pyO3 recommend the same function name as the module name
#[pymodule]
fn segul_python(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(alphabet, m)?)?;
Ok(())
}
// Wrap SEGUL API function using pyO3 `pyfunction` macro
#[pyfunction]
fn alphabet() -> String {
DNA_STR_UPPERCASE.to_string()
}
Terminal window
maturin develop
import segul_python
print(segul_python.alphabet())