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