Skip to main content

Crate pylink

Crate pylink 

Source
Expand description

Download, link, and initialize an application-local CPython interpreter.

Call initialize once during application startup, before using PyO3 or another Python API. Python runs in isolated mode: it ignores PYTHONHOME, PYTHONPATH, the user site directory, and application command-line arguments. Initialization leaves the GIL released so PyO3 can attach Rust threads.

fn main() -> Result<(), pylink::Error> {
    pylink::initialize()?;
    // Now use pyo3::Python::attach(...), or another Python C API wrapper.
    Ok(())
}

Python remains initialized for the lifetime of the process. Do not call Py_FinalizeEx or independently initialize Python while using this crate. Prefer initializing on the main thread, which CPython treats as its main interpreter thread.

Enums§

Error
An interpreter discovery or initialization error.

Constants§

BUILD_PYTHON_HOME
The downloaded interpreter’s home on the build machine.
PYO3_CONFIG_FILE
The generated PyO3 configuration file on the build machine.
PYTHON_RELEASE
The pinned Astral python-build-standalone release tag selected at build time.
PYTHON_VERSION
The exact CPython version selected at build time.

Functions§

initialize
Initialize CPython using runtime_home.
initialize_from
Initialize CPython with an explicit interpreter home.
runtime_home
Locate the Python home, or return the home already used for initialization.