API Reference

class setuptools_rust.RustExtension(target, path='Cargo.toml', args=None, features=None, rustc_flags=None, rust_version=None, quiet=False, debug=None, binding=Binding.PyO3, strip=Strip.No, script=False, native=False, optional=False, py_limited_api=False)

Used to define a rust extension module and its build configuration.

  • target (Union[str, Dict[str, str]]) – The full name of the extension, including any packages i.e. not a filename or pathname, but Python dotted name. It is possible to specify multiple binaries, if extension uses Binding.Exec binding mode. In that case first argument has to be dictionary. Keys of the dictionary corresponds to compiled rust binaries and values are full name of the executable inside python package.

  • path (str) – Path to the Cargo.toml manifest file

  • args (Optional[List[str]]) – A list of extra argumenents to be passed to cargo.

  • features (Optional[List[str]]) – A list of features to also build.

  • rust_version (Optional[str]) – Minimum Rust compiler version required for this extension.

  • quiet (bool) – Suppress Cargo’s output.

  • debug (Optional[bool]) – Controls whether --debug or --release is passed to cargo. If set to None (the default) then build type is auto-detect. Inplace build is debug build otherwise release.

  • binding (Binding) – Controls which python binding is in use.

  • strip (Strip) – Strip symbols from final file. Does nothing for debug build.

  • script (bool) – Generate console script for executable if Binding.Exec is used.

  • native (bool) – Build extension or executable with --target-cpu=native.

  • optional (bool) – if it is true, a build failure in the extension will not abort the build process, but instead simply not install the failing extension.

  • py_limited_api (bool) – Same as py_limited_api on setuptools.Extension. Note that if you set this to True, your extension must pass the appropriate feature flags to pyo3 (ensuring that abi3 feature is enabled).

class setuptools_rust.Binding(value)

Enumeration of possible Rust binding types supported by setuptools-rust.


This is an extension built using PyO3.


This is an extension built using rust-cpython.


Bring your own bindings for the extension.


Build an executable instead of an extension.

class setuptools_rust.Strip(value)

Enumeration of modes for stripping symbols from the built extension.


Do not strip symbols.


Strip debug symbols.


Strip all symbols.