18 breaking releases

0.24.0 Dec 29, 2022
0.23.0 Nov 8, 2022
0.22.0 Jun 5, 2022
0.20.0 Mar 6, 2022
0.6.0 Feb 13, 2020

#1213 in Development tools

Download history 4008/week @ 2024-07-20 3640/week @ 2024-07-27 3137/week @ 2024-08-03 3161/week @ 2024-08-10 3400/week @ 2024-08-17 4298/week @ 2024-08-24 3870/week @ 2024-08-31 3424/week @ 2024-09-07 2997/week @ 2024-09-14 3935/week @ 2024-09-21 3053/week @ 2024-09-28 2904/week @ 2024-10-05 3363/week @ 2024-10-12 3975/week @ 2024-10-19 3031/week @ 2024-10-26 2714/week @ 2024-11-02

13,547 downloads per month

Python-2.0 OR MPL-2.0

1MB
22K SLoC

Rust 20K SLoC // 0.1% comments Python 2.5K SLoC // 0.0% comments

pyembed

pyembed is a Rust library crate facilitating the control of Python interpreters within Rust applications. It is a glorified wrapper around the pyo3 crate (which provides a Rust interface to Python's C APIs). Its main value proposition over using pyo3 directly is that it provides additional value-add features such as integration with the oxidized_importer extension module for importing Python modules and resources from memory.

pyembed is part of the PyOxidizer Project but it is usable by any Rust project embedding Python.


lib.rs:

Control an embedded Python interpreter.

The pyembed crate contains functionality for controlling an embedded Python interpreter running in the current process.

pyembed provides additional functionality over what is covered by the official Embedding Python in Another Application docs and provided by the CPython C API. For example, pyembed can utilize a custom Python meta path importer that can import Python module bytecode from memory using 0-copy.

This crate was initially designed for and is maintained as part of the PyOxidizer project. However, the crate is generic and can be used outside the PyOxidizer project.

The most important types in this crate are [OxidizedPythonInterpreterConfig] and [MainPythonInterpreter]. An [OxidizedPythonInterpreterConfig] defines how a Python interpreter is to behave. A [MainPythonInterpreter] creates and manages that interpreter and serves as a high-level interface for running code in the interpreter.

Dependencies

Under the hood, pyembed makes direct use of the pyo3 crate for low-level Python FFI bindings as well as higher-level interfacing.

It is an explicit goal of this crate to rely on as few external dependencies as possible. This is because we want to minimize bloat in produced binaries.

Features

The optional allocator-jemalloc feature controls support for using jemalloc as Python's memory allocator. Use of Jemalloc from Python is a run-time configuration option controlled by the [OxidizedPythonInterpreterConfig] type and having jemalloc compiled into the binary does not mean it is being used!

The optional allocator-mimalloc feature controls support for using mimalloc as Python's memory allocator. The feature behaves similarly to jemalloc, which is documented above.

The optional allocator-snmalloc feature controls support for using snmalloc as Python's memory allocator. The feature behaves similarly to jemalloc, which is documented above.

The optional serialization feature controls whether configuration types (such as [OxidizedPythonInterpreterConfig]) implement Serialize and Deserialize.

Dependencies

~12–22MB
~361K SLoC