py.run executes Python source code from Rust. Pass the code as a string, then provide optional global and local namespaces; a PyDict commonly supplies local variables and imported modules. section 6.5
Run Python with Rust-provided locals
Python::with_gil(|py| {\n let locals = PyDict::new(py);\n locals.set_item("json", py.import("json").unwrap()).unwrap();\n locals.set_item("INPUT", input).unwrap();\n py.run(code, None, Some(&locals)).unwrap();\n});\n\nHere, code can read json and INPUT as ordinary Python names. In a Criterion benchmark, place py.run inside b.iter while constructing namespaces outside the measured loop. section 6.5
