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.
Quick Guideline
Install Rust and Maturin
Create a new Rust project
cargo new segul-python --lib
cd segul-python
Create Python project
maturin new
Add SEGUL API as a dependency
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 Python binding
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()
}
Build the Python library
maturin develop
Test the Python library
import segul_python
print(segul_python.alphabet())