python-mod

Crates.iopython-mod
lib.rspython-mod
version0.2.1
sourcesrc
created_at2023-10-27 08:17:16.201143
updated_at2024-01-16 05:42:24.875199
descriptionA macro library for including a Python module in Rust. At this point, very imcomplete.
homepage
repositoryhttps://github.com/rexlunae/python-mod-rs.git
max_upload_size
id1015730
size15,567
Erica Stith (rexlunae)

documentation

README

python-mod

A Rust module for importing a module written in Rython, which is a limited subset of Python that can be compiled to Rust. Rython is generally a subset of Python.

At the time of writing, Rython is a very limited subset of Python. This will hopefully change over time.

Usage

This module just exports macros for embedding Rython code inside Rust.

use py_mod::python_module;

Modules are imported in the same place as Rust module declarations, and they are imported from the same directory as the file declaring the module.

The following will import either py_module.py or py_module/__init__.py from the current source library directory:

python_module!(py_module);

The module can then be used like this:

fn test() {
    py_module::run_function();
}

You can also insert a prefix of Rust code into the top of the generated module by inserting it after the module name:

python_module!{py_module

    use std::result::Result;
};

This is useful for creating modules that require importing native Rust code.

Notes

Rython uses PyO3 to parse Python into a Rust data structure.

Commit count: 0

cargo fmt