Skip to main content

pyo3/
lib.rs

1#![warn(
2    clippy::alloc_instead_of_core,
3    clippy::std_instead_of_alloc,
4    clippy::std_instead_of_core
5)]
6#![warn(missing_docs)]
7#![cfg_attr(
8    feature = "nightly",
9    feature(auto_traits, negative_impls, iter_advance_by)
10)]
11#![cfg_attr(all(feature = "nightly", Py_GIL_DISABLED), feature(try_trait_v2))]
12#![cfg_attr(docsrs, feature(doc_cfg))]
13#![warn(unsafe_op_in_unsafe_fn)]
14// Deny some lints in doctests.
15// Use `#[allow(...)]` locally to override.
16#![doc(test(attr(
17    deny(
18        rust_2018_idioms,
19        unused_lifetimes,
20        rust_2021_prelude_collisions,
21        warnings
22    ),
23    allow(
24        unused_imports,  // to make imports already in the prelude explicit
25        unused_variables,
26        unused_assignments,
27        unused_extern_crates,
28        // FIXME https://github.com/rust-lang/rust/issues/121621#issuecomment-1965156376
29        unknown_lints,
30        non_local_definitions,
31    )
32)))]
33
34//! Rust bindings to the Python interpreter.
35//!
36//! PyO3 can be used to write native Python modules or run Python code and modules from Rust.
37//!
38//! See [the guide] for a detailed introduction.
39//!
40//! # PyO3's object types
41//!
42//! PyO3 has several core types that you should familiarize yourself with:
43//!
44//! ## The `Python<'py>` object, and the `'py` lifetime
45//!
46//! Holding the [global interpreter lock] (GIL) is modeled with the [`Python<'py>`](Python) token. Many
47//! Python APIs require that the GIL is held, and PyO3 uses this token as proof that these APIs
48//! can be called safely. It can be explicitly acquired and is also implicitly acquired by PyO3
49//! as it wraps Rust functions and structs into Python functions and objects.
50//!
51//! The [`Python<'py>`](Python) token's lifetime `'py` is common to many PyO3 APIs:
52//! - Types that also have the `'py` lifetime, such as the [`Bound<'py, T>`](Bound) smart pointer, are
53//!   bound to the Python GIL and rely on this to offer their functionality. These types often
54//!   have a [`.py()`](Bound::py) method to get the associated [`Python<'py>`](Python) token.
55//! - Functions which depend on the `'py` lifetime, such as [`PyList::new`](types::PyList::new),
56//!   require a [`Python<'py>`](Python) token as an input. Sometimes the token is passed implicitly by
57//!   taking a [`Bound<'py, T>`](Bound) or other type which is bound to the `'py` lifetime.
58//! - Traits which depend on the `'py` lifetime, such as [`FromPyObject<'py>`](FromPyObject), usually have
59//!   inputs or outputs which depend on the lifetime. Adding the lifetime to the trait allows
60//!   these inputs and outputs to express their binding to the GIL in the Rust type system.
61//!
62//! ## Python object smart pointers
63//!
64//! PyO3 has two core smart pointers to refer to Python objects, [`Py<T>`](Py) and its GIL-bound
65//! form [`Bound<'py, T>`](Bound) which carries the `'py` lifetime. (There is also
66//! [`Borrowed<'a, 'py, T>`](instance::Borrowed), but it is used much more rarely).
67//!
68//! The type parameter `T` in these smart pointers can be filled by:
69//!   - [`PyAny`], e.g. `Py<PyAny>` or `Bound<'py, PyAny>`, where the Python object type is not
70//!     known.
71//!   - Concrete Python types like [`PyList`](types::PyList) or [`PyTuple`](types::PyTuple).
72//!   - Rust types which are exposed to Python using the [`#[pyclass]`](macro@pyclass) macro.
73//!
74//! See the [guide][types] for an explanation of the different Python object types.
75//!
76//! ## PyErr
77//!
78//! The vast majority of operations in this library will return [`PyResult<...>`](PyResult).
79//! This is an alias for the type `Result<..., PyErr>`.
80//!
81//! A `PyErr` represents a Python exception. A `PyErr` returned to Python code will be raised as a
82//! Python exception. Errors from `PyO3` itself are also exposed as Python exceptions.
83//!
84//! # Feature flags
85//!
86//! PyO3 uses [feature flags] to enable you to opt-in to additional functionality. For a detailed
87//! description, see the [Features chapter of the guide].
88//!
89//! ## Default feature flags
90//!
91//! The following features are turned on by default:
92//! - `macros`: Enables various macros, including all the attribute macros.
93//!
94//! ## Optional feature flags
95//!
96//! The following features customize PyO3's behavior:
97//!
98//! - `abi3`: Restricts PyO3's API to a subset of the full Python API which is guaranteed by
99//! [PEP 384] to be forward-compatible with future Python versions.
100//! - `auto-initialize`: Changes [`Python::attach`] to automatically initialize the Python
101//! interpreter if needed.
102//! - `multiple-pymethods`: Enables the use of multiple [`#[pymethods]`](macro@crate::pymethods)
103//! blocks per [`#[pyclass]`](macro@crate::pyclass). This adds a dependency on the [inventory]
104//! crate, which is not supported on all platforms.
105//!
106//! The following features enable interactions with other crates in the Rust ecosystem:
107//! - [`anyhow`]: Enables a conversion from [anyhow]’s [`Error`][anyhow_error] type to [`PyErr`].
108//! - [`chrono`]: Enables a conversion from [chrono]'s structures to the equivalent Python ones.
109//! - [`chrono-tz`]: Enables a conversion from [chrono-tz]'s `Tz` enum. Requires Python 3.9+.
110//! - [`either`]: Enables conversions between Python objects and [either]'s [`Either`] type.
111//! - [`eyre`]: Enables a conversion from [eyre]’s [`Report`] type to [`PyErr`].
112//! - [`hashbrown`]: Enables conversions between Python objects and [hashbrown]'s [`HashMap`] and
113//! [`HashSet`] types.
114//! - [`indexmap`][indexmap_feature]: Enables conversions between Python dictionary and [indexmap]'s [`IndexMap`].
115//! - [`num-bigint`]: Enables conversions between Python objects and [num-bigint]'s [`BigInt`] and
116//! [`BigUint`] types.
117//! - [`num-complex`]: Enables conversions between Python objects and [num-complex]'s [`Complex`]
118//!  type.
119//! - [`num-rational`]: Enables conversions between Python's fractions.Fraction and [num-rational]'s types
120//! - [`ordered-float`]: Enables conversions between Python's float and [ordered-float]'s types
121//! - [`rust_decimal`]: Enables conversions between Python's decimal.Decimal and [rust_decimal]'s
122//! [`Decimal`] type.
123//! - [`serde`]: Allows implementing [serde]'s [`Serialize`] and [`Deserialize`] traits for
124//! [`Py`]`<T>` for all `T` that implement [`Serialize`] and [`Deserialize`].
125//! - [`smallvec`][smallvec]: Enables conversions between Python list and [smallvec]'s [`SmallVec`].
126//!
127//! ## Unstable features
128//!
129//! - `nightly`: Uses  `#![feature(auto_traits, negative_impls)]` to define [`Ungil`] as an auto trait.
130//
131//! ## `rustc` environment flags
132//! - `Py_3_8`, `Py_3_9`, `Py_3_10`, `Py_3_11`, `Py_3_12`, `Py_3_13`, `Py_3_14`: Marks code that is
133//!    only enabled when compiling for a given minimum Python version.
134//! - `Py_LIMITED_API`: Marks code enabled when the `abi3` feature flag is enabled.
135//! - `Py_GIL_DISABLED`: Marks code that runs only in the free-threaded build of CPython.
136//! - `PyPy` - Marks code enabled when compiling for PyPy.
137//! - `GraalPy` - Marks code enabled when compiling for GraalPy.
138//!
139//! Additionally, you can query for the values `Py_DEBUG`, `Py_REF_DEBUG`,
140//! `Py_TRACE_REFS`, and `COUNT_ALLOCS` from `py_sys_config` to query for the
141//! corresponding C build-time defines. For example, to conditionally define
142//! debug code using `Py_DEBUG`, you could do:
143//!
144//! ```rust,ignore
145//! #[cfg(py_sys_config = "Py_DEBUG")]
146//! println!("only runs if python was compiled with Py_DEBUG")
147//! ```
148//! To use these attributes, add [`pyo3-build-config`] as a build dependency in
149//! your `Cargo.toml` and call `pyo3_build_config::use_pyo3_cfgs()` in a
150//! `build.rs` file.
151//!
152//! # Minimum supported Rust and Python versions
153//!
154//! Requires Rust 1.63 or greater.
155//!
156//! PyO3 supports the following Python distributions:
157//!   - CPython 3.8 or greater
158//!   - PyPy 7.3 (Python 3.11+)
159//!   - GraalPy 24.0 or greater (Python 3.10+)
160//!
161//! # Example: Building a native Python module
162//!
163//! PyO3 can be used to generate a native Python module. The easiest way to try this out for the
164//! first time is to use [`maturin`]. `maturin` is a tool for building and publishing Rust-based
165//! Python packages with minimal configuration. The following steps set up some files for an example
166//! Python module, install `maturin`, and then show how to build and import the Python module.
167//!
168//! First, create a new folder (let's call it `string_sum`) containing the following two files:
169//!
170//! **`Cargo.toml`**
171//!
172//! ```toml
173//! [package]
174//! name = "string-sum"
175//! version = "0.1.0"
176//! edition = "2021"
177//!
178//! [lib]
179//! name = "string_sum"
180//! # "cdylib" is necessary to produce a shared library for Python to import from.
181//! #
182//! # Downstream Rust code (including code in `bin/`, `examples/`, and `tests/`) will not be able
183//! # to `use string_sum;` unless the "rlib" or "lib" crate type is also included, e.g.:
184//! # crate-type = ["cdylib", "rlib"]
185//! crate-type = ["cdylib"]
186//!
187//! [dependencies]
188#![doc = concat!("pyo3 = \"", env!("CARGO_PKG_VERSION"),  "\"")]
189//! ```
190//!
191//! **`src/lib.rs`**
192//! ```rust,no_run
193//! use pyo3::prelude::*;
194//!
195//! /// Formats the sum of two numbers as string.
196//! #[pyfunction]
197//! fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
198//!     Ok((a + b).to_string())
199//! }
200//!
201//! /// A Python module implemented in Rust.
202//! #[pymodule]
203//! fn string_sum(m: &Bound<'_, PyModule>) -> PyResult<()> {
204//!     m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
205//!
206//!     Ok(())
207//! }
208//! ```
209//!
210//! With those two files in place, now `maturin` needs to be installed. This can be done using
211//! Python's package manager `pip`. First, load up a new Python `virtualenv`, and install `maturin`
212//! into it:
213//! ```bash
214//! $ cd string_sum
215//! $ python -m venv .env
216//! $ source .env/bin/activate
217//! $ pip install maturin
218//! ```
219//!
220//! Now build and execute the module:
221//! ```bash
222//! $ maturin develop
223//! # lots of progress output as maturin runs the compilation...
224//! $ python
225//! >>> import string_sum
226//! >>> string_sum.sum_as_string(5, 20)
227//! '25'
228//! ```
229//!
230//! As well as with `maturin`, it is possible to build using [setuptools-rust] or
231//! [manually][manual_builds]. Both offer more flexibility than `maturin` but require further
232//! configuration.
233//!
234//! # Example: Using Python from Rust
235//!
236//! To embed Python into a Rust binary, you need to ensure that your Python installation contains a
237//! shared library. The following steps demonstrate how to ensure this (for Ubuntu), and then give
238//! some example code which runs an embedded Python interpreter.
239//!
240//! To install the Python shared library on Ubuntu:
241//! ```bash
242//! sudo apt install python3-dev
243//! ```
244//!
245//! Start a new project with `cargo new` and add  `pyo3` to the `Cargo.toml` like this:
246//! ```toml
247//! [dependencies.pyo3]
248#![doc = concat!("version = \"", env!("CARGO_PKG_VERSION"),  "\"")]
249//! # this is necessary to automatically initialize the Python interpreter
250//! features = ["auto-initialize"]
251//! ```
252//!
253//! Example program displaying the value of `sys.version` and the current user name:
254//! ```rust
255//! use pyo3::prelude::*;
256//! use pyo3::types::IntoPyDict;
257//!
258//! fn main() -> PyResult<()> {
259//!     Python::attach(|py| {
260//!         let sys = py.import("sys")?;
261//!         let version: String = sys.getattr("version")?.extract()?;
262//!
263//!         let locals = [("os", py.import("os")?)].into_py_dict(py)?;
264//!         let code = c"os.getenv('USER') or os.getenv('USERNAME') or 'Unknown'";
265//!         let user: String = py.eval(code, None, Some(&locals))?.extract()?;
266//!
267//!         println!("Hello {}, I'm Python {}", user, version);
268//!         Ok(())
269//!     })
270//! }
271//! ```
272//!
273//! The guide has [a section][calling_rust] with lots of examples about this topic.
274//!
275//! # Other Examples
276//!
277//! The PyO3 [README](https://github.com/PyO3/pyo3#readme) contains quick-start examples for both
278//! using [Rust from Python] and [Python from Rust].
279//!
280//! The PyO3 repository's [examples subdirectory]
281//! contains some basic packages to demonstrate usage of PyO3.
282//!
283//! There are many projects using PyO3 - see a list of some at
284//! <https://github.com/PyO3/pyo3#examples>.
285//!
286//! [anyhow]: https://docs.rs/anyhow/ "A trait object based error system for easy idiomatic error handling in Rust applications."
287//! [anyhow_error]: https://docs.rs/anyhow/latest/anyhow/struct.Error.html "Anyhows `Error` type, a wrapper around a dynamic error type"
288//! [`anyhow`]: ./anyhow/index.html "Documentation about the `anyhow` feature."
289//! [inventory]: https://docs.rs/inventory
290//! [`HashMap`]: https://docs.rs/hashbrown/latest/hashbrown/struct.HashMap.html
291//! [`HashSet`]: https://docs.rs/hashbrown/latest/hashbrown/struct.HashSet.html
292//! [`SmallVec`]: https://docs.rs/smallvec/latest/smallvec/struct.SmallVec.html
293//! [`Uuid`]: https://docs.rs/uuid/latest/uuid/struct.Uuid.html
294//! [`IndexMap`]: https://docs.rs/indexmap/latest/indexmap/map/struct.IndexMap.html
295//! [`BigInt`]: https://docs.rs/num-bigint/latest/num_bigint/struct.BigInt.html
296//! [`BigUint`]: https://docs.rs/num-bigint/latest/num_bigint/struct.BigUint.html
297//! [`Complex`]: https://docs.rs/num-complex/latest/num_complex/struct.Complex.html
298//! [`Deserialize`]: https://docs.rs/serde/latest/serde/trait.Deserialize.html
299//! [`Serialize`]: https://docs.rs/serde/latest/serde/trait.Serialize.html
300//! [chrono]: https://docs.rs/chrono/ "Date and Time for Rust."
301//! [chrono-tz]: https://docs.rs/chrono-tz/ "TimeZone implementations for chrono from the IANA database."
302//! [`chrono`]: ./chrono/index.html "Documentation about the `chrono` feature."
303//! [`chrono-tz`]: ./chrono-tz/index.html "Documentation about the `chrono-tz` feature."
304//! [either]: https://docs.rs/either/ "A type that represents one of two alternatives."
305//! [`either`]: ./either/index.html "Documentation about the `either` feature."
306//! [`Either`]: https://docs.rs/either/latest/either/enum.Either.html
307//! [eyre]: https://docs.rs/eyre/ "A library for easy idiomatic error handling and reporting in Rust applications."
308//! [`Report`]: https://docs.rs/eyre/latest/eyre/struct.Report.html
309//! [`eyre`]: ./eyre/index.html "Documentation about the `eyre` feature."
310//! [`hashbrown`]: ./hashbrown/index.html "Documentation about the `hashbrown` feature."
311//! [indexmap_feature]: ./indexmap/index.html "Documentation about the `indexmap` feature."
312//! [`maturin`]: https://github.com/PyO3/maturin "Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages"
313//! [`num-bigint`]: ./num_bigint/index.html "Documentation about the `num-bigint` feature."
314//! [`num-complex`]: ./num_complex/index.html "Documentation about the `num-complex` feature."
315//! [`num-rational`]: ./num_rational/index.html "Documentation about the `num-rational` feature."
316//! [`ordered-float`]: ./ordered_float/index.html "Documentation about the `ordered-float` feature."
317//! [`pyo3-build-config`]: https://docs.rs/pyo3-build-config
318//! [rust_decimal]: https://docs.rs/rust_decimal
319//! [`rust_decimal`]: ./rust_decimal/index.html "Documentation about the `rust_decimal` feature."
320//! [`Decimal`]: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html
321//! [`serde`]: <./serde/index.html> "Documentation about the `serde` feature."
322#![doc = concat!("[calling_rust]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/python-from-rust.html \"Calling Python from Rust - PyO3 user guide\"")]
323//! [examples subdirectory]: https://github.com/PyO3/pyo3/tree/main/examples
324//! [feature flags]: https://doc.rust-lang.org/cargo/reference/features.html "Features - The Cargo Book"
325//! [global interpreter lock]: https://docs.python.org/3/glossary.html#term-global-interpreter-lock
326//! [hashbrown]: https://docs.rs/hashbrown
327//! [smallvec]: https://docs.rs/smallvec
328//! [uuid]: https://docs.rs/uuid
329//! [indexmap]: https://docs.rs/indexmap
330#![doc = concat!("[manual_builds]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/building-and-distribution.html#manual-builds \"Manual builds - Building and Distribution - PyO3 user guide\"")]
331//! [num-bigint]: https://docs.rs/num-bigint
332//! [num-complex]: https://docs.rs/num-complex
333//! [num-rational]: https://docs.rs/num-rational
334//! [ordered-float]: https://docs.rs/ordered-float
335//! [serde]: https://docs.rs/serde
336//! [setuptools-rust]: https://github.com/PyO3/setuptools-rust "Setuptools plugin for Rust extensions"
337//! [the guide]: https://pyo3.rs "PyO3 user guide"
338#![doc = concat!("[types]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/types.html \"GIL lifetimes, mutability and Python object types\"")]
339//! [PEP 384]: https://www.python.org/dev/peps/pep-0384 "PEP 384 -- Defining a Stable ABI"
340//! [Python from Rust]: https://github.com/PyO3/pyo3#using-python-from-rust
341//! [Rust from Python]: https://github.com/PyO3/pyo3#using-rust-from-python
342#![doc = concat!("[Features chapter of the guide]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/features.html#features-reference \"Features Reference - PyO3 user guide\"")]
343//! [`Ungil`]: crate::marker::Ungil
344
345extern crate alloc;
346
347pub use crate::class::*;
348pub use crate::conversion::{FromPyObject, IntoPyObject, IntoPyObjectExt};
349pub use crate::err::{CastError, CastIntoError, PyErr, PyErrArguments, PyResult, ToPyErr};
350#[allow(deprecated)]
351pub use crate::err::{DowncastError, DowncastIntoError};
352pub use crate::instance::{Borrowed, Bound, BoundObject, Py};
353#[cfg(not(any(PyPy, GraalPy)))]
354pub use crate::interpreter_lifecycle::with_embedded_python_interpreter;
355pub use crate::marker::Python;
356pub use crate::pycell::{PyRef, PyRefMut};
357pub use crate::pyclass::{PyClass, PyClassGuard, PyClassGuardMut};
358pub use crate::pyclass_init::PyClassInitializer;
359pub use crate::type_object::{PyTypeCheck, PyTypeInfo};
360pub use crate::types::PyAny;
361pub use crate::version::PythonVersionInfo;
362
363pub(crate) mod ffi_ptr_ext;
364pub(crate) mod py_result_ext;
365pub(crate) mod sealed;
366
367/// Old module which contained some implementation details of the `#[pyproto]` module.
368///
369/// Prefer using the same content from `pyo3::pyclass`, e.g. `use pyo3::pyclass::CompareOp` instead
370/// of `use pyo3::class::basic::CompareOp`.
371///
372/// For compatibility reasons this has not yet been removed, however will be done so
373/// once <https://github.com/rust-lang/rust/issues/30827> is resolved.
374pub mod class {
375    pub use self::gc::{PyTraverseError, PyVisit};
376
377    /// Old module which contained some implementation details of the `#[pyproto]` module.
378    ///
379    /// Prefer using the same content from `pyo3::pyclass`, e.g. `use pyo3::pyclass::CompareOp` instead
380    /// of `use pyo3::class::basic::CompareOp`.
381    ///
382    /// For compatibility reasons this has not yet been removed, however will be done so
383    /// once <https://github.com/rust-lang/rust/issues/30827> is resolved.
384    pub mod basic {
385        pub use crate::pyclass::CompareOp;
386    }
387
388    /// Old module which contained some implementation details of the `#[pyproto]` module.
389    ///
390    /// Prefer using the same content from `pyo3::pyclass`, e.g. `use pyo3::pyclass::PyTraverseError` instead
391    /// of `use pyo3::class::gc::PyTraverseError`.
392    ///
393    /// For compatibility reasons this has not yet been removed, however will be done so
394    /// once <https://github.com/rust-lang/rust/issues/30827> is resolved.
395    pub mod gc {
396        pub use crate::pyclass::{PyTraverseError, PyVisit};
397    }
398}
399
400#[cfg(all(feature = "macros", feature = "multiple-pymethods"))]
401#[doc(hidden)]
402pub use inventory; // Re-exported for `#[pyclass]` and `#[pymethods]` with `multiple-pymethods`.
403
404/// Tests and helpers which reside inside PyO3's main library. Declared first so that macros
405/// are available in unit tests.
406#[cfg(test)]
407mod test_utils;
408#[cfg(test)]
409mod tests;
410
411// Macro dependencies, also contains macros exported for use across the codebase and
412// in expanded macros.
413#[doc(hidden)]
414pub mod impl_;
415
416#[macro_use]
417mod internal_tricks;
418mod internal;
419
420pub mod buffer;
421pub mod call;
422pub mod conversion;
423mod conversions;
424#[cfg(feature = "experimental-async")]
425pub mod coroutine;
426mod err;
427pub mod exceptions;
428pub mod ffi;
429pub(crate) mod fmt;
430mod instance;
431mod interpreter_lifecycle;
432pub mod marker;
433pub mod marshal;
434#[macro_use]
435pub mod sync;
436pub(crate) mod byteswriter;
437pub mod panic;
438pub mod pybacked;
439pub mod pycell;
440pub mod pyclass;
441pub mod pyclass_init;
442
443pub mod type_object;
444pub mod types;
445mod version;
446
447#[allow(
448    unused_imports,
449    reason = "with no features enabled this module has no public exports"
450)]
451pub use crate::conversions::*;
452
453#[cfg(feature = "macros")]
454pub use pyo3_macros::{
455    pyfunction, pymethods, pymodule, FromPyObject, IntoPyObject, IntoPyObjectRef,
456};
457
458/// A proc macro used to expose Rust structs and fieldless enums as Python objects.
459///
460#[doc = include_str!("../guide/pyclass-parameters.md")]
461///
462/// For more on creating Python classes,
463/// see the [class section of the guide][1].
464///
465#[doc = concat!("[1]: https://pyo3.rs/v", env!("CARGO_PKG_VERSION"), "/class.html")]
466#[cfg(feature = "macros")]
467pub use pyo3_macros::pyclass;
468
469#[cfg(feature = "macros")]
470#[macro_use]
471mod macros;
472
473#[cfg(feature = "experimental-inspect")]
474pub mod inspect;
475
476// Putting the declaration of prelude at the end seems to help encourage rustc and rustdoc to prefer using
477// other paths to the same items. (e.g. `pyo3::types::PyAnyMethods` instead of `pyo3::prelude::PyAnyMethods`).
478pub mod prelude;
479
480/// Test readme and user guide
481#[cfg(doctest)]
482pub mod doc_test {
483    macro_rules! doctests {
484        ($($path:expr => $mod:ident),* $(,)?) => {
485            $(
486                #[doc = include_str!(concat!("../", $path))]
487                mod $mod{}
488            )*
489        };
490    }
491
492    doctests! {
493        "README.md" => readme_md,
494        "guide/src/advanced.md" => guide_advanced_md,
495        "guide/src/async-await.md" => guide_async_await_md,
496        "guide/src/building-and-distribution.md" => guide_building_and_distribution_md,
497        "guide/src/building-and-distribution/multiple-python-versions.md" => guide_bnd_multiple_python_versions_md,
498        "guide/src/class.md" => guide_class_md,
499        "guide/src/class/call.md" => guide_class_call,
500        "guide/src/class/object.md" => guide_class_object,
501        "guide/src/class/numeric.md" => guide_class_numeric,
502        "guide/src/class/protocols.md" => guide_class_protocols_md,
503        "guide/src/class/thread-safety.md" => guide_class_thread_safety_md,
504        "guide/src/conversions.md" => guide_conversions_md,
505        "guide/src/conversions/tables.md" => guide_conversions_tables_md,
506        "guide/src/conversions/traits.md" => guide_conversions_traits_md,
507        "guide/src/debugging.md" => guide_debugging_md,
508
509        // deliberate choice not to test guide/ecosystem because those pages depend on external
510        // crates such as pyo3_asyncio.
511
512        "guide/src/exception.md" => guide_exception_md,
513        "guide/src/faq.md" => guide_faq_md,
514        "guide/src/features.md" => guide_features_md,
515        "guide/src/free-threading.md" => guide_free_threading_md,
516        "guide/src/function.md" => guide_function_md,
517        "guide/src/function/error-handling.md" => guide_function_error_handling_md,
518        "guide/src/function/signature.md" => guide_function_signature_md,
519        "guide/src/migration.md" => guide_migration_md,
520        "guide/src/module.md" => guide_module_md,
521        "guide/src/parallelism.md" => guide_parallelism_md,
522        "guide/src/performance.md" => guide_performance_md,
523        "guide/src/python-from-rust.md" => guide_python_from_rust_md,
524        "guide/src/python-from-rust/calling-existing-code.md" => guide_pfr_calling_existing_code_md,
525        "guide/src/python-from-rust/function-calls.md" => guide_pfr_function_calls_md,
526        "guide/src/python-typing-hints.md" => guide_python_typing_hints_md,
527        "guide/src/rust-from-python.md" => guide_rust_from_python_md,
528        "guide/src/trait-bounds.md" => guide_trait_bounds_md,
529        "guide/src/types.md" => guide_types_md,
530    }
531}