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
Section titled “Quick Guideline”Install Rust and Maturin
Section titled “Install Rust and Maturin”Create a new Rust project
Section titled “Create a new Rust project”cargo new segul-python --lib
cd segul-pythonCreate Python project
Section titled “Create Python project”maturin newAdd SEGUL API as a dependency
Section titled “Add SEGUL API as a dependency”cargo add segulOr 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
Section titled “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
Section titled “Build the Python library”maturin developTest the Python library
Section titled “Test the Python library”import segul_python
print(segul_python.alphabet())Copyright © 2026 H. Handika & J. A. Esselstyn.