Back to Pyo3

PyO3 Examples

examples/README.md

0.28.31.4 KB
Original Source

PyO3 Examples

These example crates are a collection of toy extension modules built with PyO3. They are all tested using nox in PyO3's CI.

Below is a brief description of each of these:

ExampleDescription
decoratorA project showcasing the example from the Emulating callable objects chapter of the guide.
maturin-starterA template project which is configured to use maturin for development.
setuptools-rust-starterA template project which is configured to use setuptools_rust for development.
pluginIllustrates how to use Python as a scripting language within a Rust application

Note that there are also other examples in the pyo3-ffi/examples directory that illustrate how to create rust extensions using raw FFI calls into the CPython C API instead of using PyO3's abstractions.

Creating new projects from these examples

To copy an example, use cargo-generate. Follow the commands below, replacing <example> with the example to start from:

bash
$ cargo install cargo-generate
$ cargo generate --git https://github.com/PyO3/pyo3 examples/<example>

(cargo generate will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.)