Rust bindings for the Python interpreter

Overview

PyO3

Actions Status codecov crates.io minimum rustc 1.41 Join the dev chat

Rust bindings for Python. This includes running and interacting with Python code from a Rust binary, as well as writing native Python modules.

A comparison with rust-cpython can be found in the guide.

Usage

PyO3 supports Python 3.6 and up. The minimum required Rust version is 1.41.

Building with PyPy is also possible (via cpyext) for Python 3.6, targeted PyPy version is 7.3+. Please refer to the pypy section in the guide.

You can either write a native Python module in Rust, or use Python from a Rust binary.

However, on some OSs, you need some additional packages. E.g. if you are on Ubuntu 18.04, please run

sudo apt install python3-dev python-dev

Using Rust from Python

PyO3 can be used to generate a native Python module.

Cargo.toml

[package]
name = "string-sum"
version = "0.1.0"
edition = "2018"

[lib]
name = "string_sum"
# "cdylib" is necessary to produce a shared library for Python to import from.
#
# Downstream Rust code (including code in `bin/`, `examples/`, and `tests/`) will not be able
# to `use string_sum;` unless the "rlib" or "lib" crate type is also included, e.g.:
# crate-type = ["cdylib", "rlib"]
crate-type = ["cdylib"]

[dependencies.pyo3]
version = "0.13.2"
features = ["extension-module"]

src/lib.rs

use pyo3::prelude::*;
use pyo3::wrap_pyfunction;

/// Formats the sum of two numbers as string.
#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
    Ok((a + b).to_string())
}

/// A Python module implemented in Rust.
#[pymodule]
fn string_sum(py: Python, m: &PyModule) -> PyResult<()> {
    m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;

    Ok(())
}

On Windows and Linux, you can build normally with cargo build --release. On macOS, you need to set additional linker arguments. One option is to compile with cargo rustc --release -- -C link-arg=-undefined -C link-arg=dynamic_lookup, the other is to create a .cargo/config with the following content:

[target.x86_64-apple-darwin]
rustflags = [
  "-C", "link-arg=-undefined",
  "-C", "link-arg=dynamic_lookup",
]

[target.aarch64-apple-darwin]
rustflags = [
  "-C", "link-arg=-undefined",
  "-C", "link-arg=dynamic_lookup",
]

While developing, you can symlink (or copy) and rename the shared library from the target folder: On MacOS, rename libstring_sum.dylib to string_sum.so, on Windows libstring_sum.dll to string_sum.pyd, and on Linux libstring_sum.so to string_sum.so. Then open a Python shell in the same folder and you'll be able to import string_sum.

To build, test and publish your crate as a Python module, you can use maturin or setuptools-rust. You can find an example for setuptools-rust in examples/word-count, while maturin should work on your crate without any configuration.

Using Python from Rust

If you want your Rust application to create a Python interpreter internally and use it to run Python code, add pyo3 to your Cargo.toml like this:

[dependencies.pyo3]
version = "0.13.2"
features = ["auto-initialize"]

Example program displaying the value of sys.version and the current user name:

use pyo3::prelude::*;
use pyo3::types::IntoPyDict;

fn main() -> Result<(), ()> {
    Python::with_gil(|py| {
        main_(py).map_err(|e| {
          // We can't display Python exceptions via std::fmt::Display,
          // so print the error here manually.
          e.print_and_set_sys_last_vars(py);
        })
    })
}

fn main_(py: Python) -> PyResult<()> {
    let sys = py.import("sys")?;
    let version: String = sys.get("version")?.extract()?;
    let locals = [("os", py.import("os")?)].into_py_dict(py);
    let code = "os.getenv('USER') or os.getenv('USERNAME') or 'Unknown'";
    let user: String = py.eval(code, None, Some(&locals))?.extract()?;
    println!("Hello {}, I'm Python {}", user, version);
    Ok(())
}

Our guide has a section with lots of examples about this topic.

Tools and libraries

  • maturin Zero configuration build tool for Rust-made Python extensions.
  • setuptools-rust Setuptools plugin for Rust support.
  • pyo3-built Simple macro to expose metadata obtained with the built crate as a PyDict
  • rust-numpy Rust binding of NumPy C-API
  • dict-derive Derive FromPyObject to automatically transform Python dicts into Rust structs
  • pyo3-log Bridge from Rust to Python logging
  • pythonize Serde serializer for converting Rust objects to JSON-compatible Python objects
  • pyo3-asyncio Utilities for working with Python's Asyncio library and async functions

Examples

  • hyperjson A hyper-fast Python module for reading/writing JSON data using Rust's serde-json
  • html-py-ever Using html5ever through kuchiki to speed up html parsing and css-selecting.
  • point-process High level API for pointprocesses as a Python library
  • autopy A simple, cross-platform GUI automation library for Python and Rust.
    • Contains an example of building wheels on TravisCI and appveyor using cibuildwheel
  • orjson Fast Python JSON library
  • inline-python Inline Python code directly in your Rust code
  • Rogue-Gym Customizable rogue-like game for AI experiments
    • Contains an example of building wheels on Azure Pipelines
  • fastuuid Python bindings to Rust's UUID library
  • wasmer-python Python library to run WebAssembly binaries
  • mocpy Astronomical Python library offering data structures for describing any arbitrary coverage regions on the unit sphere
  • tokenizers Python bindings to the Hugging Face tokenizers (NLP) written in Rust
  • pyre Fast Python HTTP server written in Rust
  • jsonschema-rs Fast JSON Schema validation library
  • css-inline CSS inlining for Python implemented in Rust
  • cryptography Python cryptography library with some functionality in Rust

License

PyO3 is licensed under the Apache-2.0 license. Python is licensed under the Python License.

Comments
  • Added Rust initialisation of Python-allocated bytes

    Added Rust initialisation of Python-allocated bytes

    Adds new_with<F: Fn(&mut [u8])>(py: Python<'_>, len: usize, init: F) -> &PyBytes as suggested by @davidhewitt in #617. This allows initialising new PyBytes in Rust like such:

    let py_bytes = PyBytes::new_with(py, 10, |b: &mut [u8]| {
        b.copy_from_slice(b"Hello Rust");
    });
    

    Currently, it follows the semantics of PyBytes::new in that it panics if a memory error occurs in Python. Maybe my implementation of that could be improved.

    opened by MomoLangenstein 53
  • FromPyObject derivation for structs and enums

    FromPyObject derivation for structs and enums

    This is a draft addressing a bit of both topics in #301 and #1055.

    I have not written proc-macro code before, so this might be quite ugly. This is mostly proof-of-concept, but I think it'd be a great quality-of-life improvement if something like this was available.

    This produces the following behaviour:

    >>> union.foo(["Test"])
    ["Test"]
    >>> union.foo("Test")
    Test
    >>> union.foo(1)
    1
    >>> union.foo(None)
    TypeError: Can't convert NoneType to Union[Str, Int, StringList]
    

    This implementation covers both the cheap downcast variant and extraction of proper Rust types. Although I'm not sure whether relying on the variant holding a reference is the proper heuristic to apply here.


    Todos are marked in the code, a proper implementation should in my opinion:

    • make the reported names of the variants in the error configurable through an attribute on the variant, i.e.:
      #[union]
      pub enum MyUnion {
          #[rename(str)]
          SomeVariant(String)
      } 
      
    • support named fields & variants with multiple fields
    opened by sebpuetz 53
  • Add catch_unwind! macro to prevent panics crossing ffi boundaries

    Add catch_unwind! macro to prevent panics crossing ffi boundaries

    Fixes #492

    This is a first attempt at updating all the wrapping code to use catch_unwind to prevent unsoundness of panics inside Rust callback functions.

    I implemented this using a pyo3::catch_unwind macro, which takes a Python token and a body of code which should evaluate to a PyResult.

    I ran into complications around lifetimes and the callback converters so I ended up simplifying a lot of the callback conversion code. I think a lot of those macros are now in slightly better shape but there's probably more refactoring that could be done.

    Please give this a thorough review, I'm prepared to rework this as many times as needed to get it right.

    TODO:

    • [X] Custom Exception type from BaseException
      • [ ] Mechanism for users to import this Exception (will do later after #805)
      • [x] Resume unwind when pyO3 gets this Exception in a PyErr
    • [ ] Panic section for the book
    help-wanted 
    opened by davidhewitt 53
  • Get rid of specialization

    Get rid of specialization

    ~The last step for #5 is getting rid of specialization. I've remove most uses in 7c0379b1 and subsequent commits, except for the following ~17~ ~10~ ~9~ ~7~ 4:~ https://github.com/rust-lang/rust/pull/64564 changed the rules so there are again many default fn.

    src/class/descr.rs
    76:    default fn tp_descr_get() -> Option<ffi::descrgetfunc> {
    97:    default fn tp_descr_set() -> Option<ffi::descrsetfunc> {
    130:    default fn tp_as_descr(_type_object: &mut ffi::PyTypeObject) {}
    
    src/class/buffer.rs
    46:    default fn tp_as_buffer() -> Option<ffi::PyBufferProcs> {
    74:    default fn cb_bf_getbuffer() -> Option<ffi::getbufferproc> {
    110:    default fn cb_bf_releasebuffer() -> Option<ffi::releasebufferproc> {
    
    src/class/gc.rs
    27:    default fn update_type_object(_type_object: &mut ffi::PyTypeObject) {}
    72:    default fn tp_traverse() -> Option<ffi::traverseproc> {
    124:    default fn tp_clear() -> Option<ffi::inquiry> {
    
    src/class/iter.rs
    49:    default fn tp_as_iter(_typeob: &mut ffi::PyTypeObject) {}
    71:    default fn tp_iter() -> Option<ffi::getiterfunc> {
    94:    default fn tp_iternext() -> Option<ffi::iternextfunc> {
    
    src/class/basic.rs
    152:    default fn tp_as_object(_type_object: &mut ffi::PyTypeObject) {}
    153:    default fn nb_bool_fn() -> Option<ffi::inquiry> {
    183:    default fn tp_getattro() -> Option<ffi::binaryfunc> {
    252:        default fn set_attr() -> Option<ffi::setattrofunc> {
    274:        default fn del_attr() -> Option<ffi::setattrofunc> {
    296:        default fn set_del_attr() -> Option<ffi::setattrofunc> {
    324:    default fn tp_str() -> Option<ffi::unaryfunc> {
    344:    default fn tp_repr() -> Option<ffi::unaryfunc> {
    364:    default fn tp_hash() -> Option<ffi::hashfunc> {
    389:    default fn nb_bool() -> Option<ffi::inquiry> {
    409:    default fn tp_richcompare() -> Option<ffi::richcmpfunc> {
    
    src/class/mapping.rs
    83:    default fn tp_as_mapping() -> Option<ffi::PyMappingMethods> {
    116:    default fn mp_length() -> Option<ffi::lenfunc> {
    139:    default fn mp_subscript() -> Option<ffi::binaryfunc> {
    162:    default fn mp_ass_subscript() -> Option<ffi::objobjargproc> {
    187:    default fn mp_del_subscript() -> Option<ffi::objobjargproc> {
    201:    default fn det_set_dispatch() -> Option<ffi::objobjargproc> {
    
    src/class/pyasync.rs
    94:    default fn tp_as_async() -> Option<ffi::PyAsyncMethods> {
    121:    default fn am_await() -> Option<ffi::unaryfunc> {
    144:    default fn am_aiter() -> Option<ffi::unaryfunc> {
    167:    default fn am_anext() -> Option<ffi::unaryfunc> {
    
    src/conversion.rs
    107:    default fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R
    
    src/class/sequence.rs
    135:    default fn tp_as_sequence() -> Option<ffi::PySequenceMethods> {
    168:    default fn sq_length() -> Option<ffi::lenfunc> {
    190:    default fn sq_item() -> Option<ffi::ssizeargfunc> {
    239:        default fn set_item() -> Option<ffi::ssizeobjargproc> {
    285:        default fn del_item() -> Option<ffi::ssizeobjargproc> {
    328:        default fn del_set_item() -> Option<ffi::ssizeobjargproc> {
    372:    default fn sq_contains() -> Option<ffi::objobjproc> {
    394:    default fn sq_concat() -> Option<ffi::binaryfunc> {
    416:    default fn sq_repeat() -> Option<ffi::ssizeargfunc> {
    438:    default fn sq_inplace_concat() -> Option<ffi::binaryfunc> {
    465:    default fn sq_inplace_repeat() -> Option<ffi::ssizeargfunc> {
    
    src/class/number.rs
    625:    default fn tp_as_number() -> Option<ffi::PyNumberMethods> {
    692:    default fn nb_add() -> Option<ffi::binaryfunc> {
    714:    default fn nb_subtract() -> Option<ffi::binaryfunc> {
    736:    default fn nb_multiply() -> Option<ffi::binaryfunc> {
    758:    default fn nb_matrix_multiply() -> Option<ffi::binaryfunc> {
    780:    default fn nb_true_divide() -> Option<ffi::binaryfunc> {
    802:    default fn nb_floor_divide() -> Option<ffi::binaryfunc> {
    824:    default fn nb_remainder() -> Option<ffi::binaryfunc> {
    846:    default fn nb_divmod() -> Option<ffi::binaryfunc> {
    868:    default fn nb_power() -> Option<ffi::ternaryfunc> {
    890:    default fn nb_lshift() -> Option<ffi::binaryfunc> {
    912:    default fn nb_rshift() -> Option<ffi::binaryfunc> {
    934:    default fn nb_and() -> Option<ffi::binaryfunc> {
    956:    default fn nb_xor() -> Option<ffi::binaryfunc> {
    978:    default fn nb_or() -> Option<ffi::binaryfunc> {
    1000:    default fn nb_inplace_add() -> Option<ffi::binaryfunc> {
    1022:    default fn nb_inplace_subtract() -> Option<ffi::binaryfunc> {
    1044:    default fn nb_inplace_multiply() -> Option<ffi::binaryfunc> {
    1066:    default fn nb_inplace_matrix_multiply() -> Option<ffi::binaryfunc> {
    1088:    default fn nb_inplace_true_divide() -> Option<ffi::binaryfunc> {
    1110:    default fn nb_inplace_floor_divide() -> Option<ffi::binaryfunc> {
    1132:    default fn nb_inplace_remainder() -> Option<ffi::binaryfunc> {
    1154:    default fn nb_inplace_power() -> Option<ffi::ternaryfunc> {
    1176:    default fn nb_inplace_lshift() -> Option<ffi::binaryfunc> {
    1198:    default fn nb_inplace_rshift() -> Option<ffi::binaryfunc> {
    1220:    default fn nb_inplace_and() -> Option<ffi::binaryfunc> {
    1242:    default fn nb_inplace_xor() -> Option<ffi::binaryfunc> {
    1264:    default fn nb_inplace_or() -> Option<ffi::binaryfunc> {
    1287:    default fn nb_add_fallback() -> Option<ffi::binaryfunc> {
    1309:    default fn nb_sub_fallback() -> Option<ffi::binaryfunc> {
    1331:    default fn nb_mul_fallback() -> Option<ffi::binaryfunc> {
    1353:    default fn nb_matmul_fallback() -> Option<ffi::binaryfunc> {
    1375:    default fn nb_truediv_fallback() -> Option<ffi::binaryfunc> {
    1397:    default fn nb_floordiv_fallback() -> Option<ffi::binaryfunc> {
    1419:    default fn nb_mod_fallback() -> Option<ffi::binaryfunc> {
    1441:    default fn nb_divmod_fallback() -> Option<ffi::binaryfunc> {
    1463:    default fn nb_pow_fallback() -> Option<ffi::ternaryfunc> {
    1485:    default fn nb_lshift_fallback() -> Option<ffi::binaryfunc> {
    1507:    default fn nb_rshift_fallback() -> Option<ffi::binaryfunc> {
    1529:    default fn nb_and_fallback() -> Option<ffi::binaryfunc> {
    1551:    default fn nb_xor_fallback() -> Option<ffi::binaryfunc> {
    1573:    default fn nb_or_fallback() -> Option<ffi::binaryfunc> {
    1595:    default fn nb_negative() -> Option<ffi::unaryfunc> {
    1618:    default fn nb_positive() -> Option<ffi::unaryfunc> {
    1640:    default fn nb_absolute() -> Option<ffi::unaryfunc> {
    1662:    default fn nb_invert() -> Option<ffi::unaryfunc> {
    1684:    default fn nb_int() -> Option<ffi::unaryfunc> {
    1706:    default fn nb_float() -> Option<ffi::unaryfunc> {
    1728:    default fn nb_index() -> Option<ffi::unaryfunc> {
    
    src/instance.rs
    387:    default fn to_managed_py_ref<'p>(&self, py: Python<'p>) -> ManagedPyRef<'p, Self> {
    396:    default fn drop_impl(borrowed: &mut ManagedPyRef<Self>) {
    
    src/types/sequence.rs
    268:                default fn extract(obj: &'a PyAny) -> PyResult<Self> {
    307:    default fn extract(obj: &'a PyAny) -> PyResult<Self> {
    

    ~Once those are removed, we pyo3 can be stable on rust 1.30! I'm happy to take pull requests tackling one or more of those default fn uses~

    enhancement 
    opened by konstin 42
  • Questions about multithreading and asyncio

    Questions about multithreading and asyncio

    Hey, I've got a rather complicated program that involves mixing Rust async/await with Python asyncio. I know this problem isn't sorted out yet in pyo3 (although I think it's being worked on), but I figured I could get around those limitations by running two event loops, one for Rust and one for Python on its own dedicated thread.

    So here's what I'm doing:

    • Spin up an async Rust application with async-std runtime
    • Spawn a thread to act as the main thread for the asyncio event loop and call asyncio.set_event_loop(loop) and loop.run_forever() on that thread
    • Host a websocket server with async-tungstenite that occasionally interacts with the Python event loop via pyo3.
    • Interact with the Python event loop via call_soon_threadsafe and asyncio.run_coroutine_threadsafe to run my application
    • When the application exits, I call loop.call_soon_threadsafe(loop.stop) and join my thread

    My tests run exactly as expected with pyo3. The only problem is that when the test exits, I get one of three errors:

    If I'm lucky, my test exits successfully this warning:

    Exception ignored in: <module 'threading' from '/usr/lib/python3.8/threading.py'>
    Traceback (most recent call last):
      File "/usr/lib/python3.8/threading.py", line 1373, in _shutdown
        assert tlock.locked()
    AssertionError: 
    

    If I'm unlucky I either get this error:

    Fatal Python error: This thread state must be current when releasing
    
    Thread 0x00007f7dd1dd8b40 (most recent call first):
    
    Current thread 0x00007f7dcece9700 (most recent call first):
      File "/usr/lib/python3.6/asyncio/selector_events.py", line 148 in _write_to_self
      File "/usr/lib/python3.6/asyncio/base_events.py", line 643 in call_soon_threadsafe
    
    Thread 0x00007f7dcc4a0700 (most recent call first):
      File "/usr/lib/python3.6/selectors.py", line 445 in select
      File "/usr/lib/python3.6/asyncio/base_events.py", line 1415 in _run_once
      File "/usr/lib/python3.6/asyncio/base_events.py", line 438 in run_forever
    
    Thread 0x00007f7dce8e7700 (most recent call first):
    error: test failed
    

    or this one:

    FATAL: exception not rethrown
    error: test failed
    

    Things I've tried:

    • Spawning native rust threads with std::thread to run the event loop
    • Spawning python threads with the threading module to run my event loop
    • Calling pyo3::prepare_freethreaded_python() before the first call to Python::with_gil

    Sorry the problem description is so vague. I've tried simplifying my program to narrow the problem down, but it's frustratingly hard to replicate in a smaller codebase. Before I spend too much time on that, I just wanted to check with someone more experienced with embedding Python to see if I'm setting things up properly.

    Questions:

    • Am I setting up my threads correctly?
    • Do I need to call pyo3::prepare_freethreaded_python() before the first call to Python::with_gil in this situation?
    • Do I need to use a thread from the Python threading module or is it ok to use Rust's std::thread
    • Do I need to use some of the FFI calls to ensure that my Python thread state is correct?
    • Are there any other multi-threading limitations that I should know about with pyo3?

    🌍 Environment

    • OS: Ubuntu 20.04
    • Python version: 3.8.5 (installed with distro)
    • Rust version (rustc --version): rustc 1.47.0-nightly (6c8927b0c 2020-07-26)
    • PyO3 version: "0.12.3"
    • I have not tried pyo3 master yet (I think the problem is with my code)
    question 
    opened by awestlake87 41
  • Complete abi3 support

    Complete abi3 support

    For #1125. Continuation of #1132. What I did so far are

    • Prepared the proper feature flag. I named it all-apis but feel free to propose alternative.
      • EDITED: I renamed it unstable-api adviced by konstin.
    • Restructured method tables with cfg.

    TODO:

    • [x] Add CI setting for abi3
    • [x] Refactor tp_dict initialization codes (=classattr). It should be changed a lot.
    • [x] __text__signature__.
    • [x] Raise compile errors if some features (e.g., Buffer Protocol) is used without unstable-api feature.
    • [ ] Support additional feature flags with the minimum required Python version. See #1195 about the discussion.
    • [x] Documentation
      • Document about abi3 in the README and the guide.

    ... and so on.

    Sorry @alex for the conflict. I'm going to work on tp_dict problem for now and contributions for other areas are welcome.

    opened by kngwyu 41
  • Support rust extensions for PyPy via cpyext

    Support rust extensions for PyPy via cpyext

    Hi, Following the discussion on https://github.com/PyO3/pyo3/pull/370, I've taken some time to dust off my work on support for PyPy via cpyext.

    It runs nicely on my machine (osx) for the several test cases I've been using (raising errors, moving objects back and forth and so on).

    I've managed to run the word_count example successfully, altough for this usecase pypy beats rust in terms of performance (overhead is greater than benefit).

    ~~Unfortunely, it seems the rustapi_module example is still crashing, because of 2 outstanding issues:~~ EDIT: Both solved!

    ~~1. The datetime API wrapper.~~ ~~2. The way initialize_type behaves (causes SIGSEGV on attempt to register a new class) My guess is that there is still some outstanding difference in the implementation of the PyTypeObject struct that causes it to crash~~

    I'd like to outline some changes I've done, and why I think there is definitely some more work needed on this before it's ready for prime time.

    1. cpyext does not offer complete support for the entirety of the cpython API. So I've had (mostly by dumping symbols out of the pypy interpreter) manually add the parts of it that it implements with annotations like this: #[cfg_attr(PyPy, link_name = "PyPyErr_SetInterrupt")]

    I couldn't find any automatic way to set this up, since it's not for all the symbols, so it's quite verbose (I've done this with a regexes), but it makes it very easy to spot changes when the cpyext api layer changes and add them.

    1. I've never succeeded in getting this to work with python2, and since I've read in the PR that it's likely to be discontinued, I didn't invest more time with it.

    2. I've had to manually shim some functions that pypy expects to find when compiling against their version of Python.h, like PyUnicodeDecodeError_Create, these are mostly utility functions which they never bothered implementing, so it looks something like this: image

    3. I've modified the build.rs script originally in my implementation, since I needed it to detect and correctly emit configuration variables that are suitable for PyPy, it's a slight drift from the current model (single build.rs file), into a more structured internal crate that I've used. I didn't want to spend time porting all the changes back into the big build.rs file without hearing your thoughts on it first.

    4. As the title suggests, this only supports python -> rust, and not embedding pypy (due to pypy not behaving nicely with embedding), though I don't think embedding pypy is a significant use case, as it's mostly used to squeeze performance out of existing python codebases.

    EDIT: Functionallity that is still missing from cpyext that is used by PyO3 internally: These functions will need to be implemented in rust.

    • complex numbers _Py_c_* functions
    • PyDict_MergeFromSeq2
    • _PyLong_FromByteArray, _PyLong_AsByteArray
    • PySequence_Count
    • Py_CompileStringExFlags (EDIT: PyPy exports Py_CompileStringFlags, so this is actually OK)

    I'm still certain there are some semantics that I've missed, but i'd love to get another pair of eyes looking over some of this stuff.

    Would love to hear your thoughts :) Cheers 🐍

    P.S I'm away for next week, but I will be able to address suggestions the week after.

    opened by omerbenamram 39
  • #1064: Comparisons with __eq__ should not raise TypeError

    #1064: Comparisons with __eq__ should not raise TypeError

    RichComparisonToSelf expects to compare itself with objects of the same type, but then we shouldn't raise TypeError but return NotImplemented.

    Fixes #1064

    opened by mvaled 38
  • enum WIP

    enum WIP

    Thank you for contributing to pyo3!

    Here are some things you should check for submitting your pull request:

    • Run cargo fmt (This is checked by travis ci)
    • Run cargo clippy and check there are no hard errors (There are a bunch of existing warnings; This is also checked by travis)
    • If applicable, add an entry in the changelog.
    • If applicable, add documentation to all new items and extend the guide.
    • If applicable, add tests for all new or fixed functions
    • If you changed any python code, run black .. You can install black with pip install black)

    You might want to run tox (pip install tox) locally to check compatibility with all supported python versions. If you're using linux or mac you might find the Makefile helpful for testing.

    needs-implementer 
    opened by stillinbeta 38
  • Compile with stable rust

    Compile with stable rust

    PyO3 requires following unstable

    • [x] const_fn rust-lang/rust#24111
    • [x] specialization rust-lang/rust#31844
    • [x] use_extern_macros rust-lang/rust#35896
    • [x] proc_macro (proc_macro_attribute) rust-lang/rust#35896
    • [x] associated_consts
    • [x] ~~Optional, for wrap_function!: concat_idents (rust-lang/rust#29599)~~ Solved with mashup
    opened by fafhrd91 38
  • Undefined symbols for architecture arm64

    Undefined symbols for architecture arm64

    🐛 Bug Reports

    When reporting a bug, please provide the following information. If this is not a bug report you can just discard this template.

    🌍 Environment

    • Your operating system and version: MacOS 11.5 Big Sur, on M1 / arm64
    • Your python version: 3.9.5
    • How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: Pyenv, with virtualenv. Also tested with system python with virtualenv.
    • Your Rust version (rustc --version): rustc 1.54.0 (a178d0322 2021-07-26)
    • Your PyO3 version: 0.14.2
    • Have you tried using latest PyO3 main (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")?: Yes

    💥 Reproducing

    $ cat Cargo.toml
    [package]
    name = "foo"
    version = "0.1.0"
    edition = "2018"
    
    [lib]
    name = "foo"
    crate-type = ["cdylib"]
    
    [dependencies.pyo3]
    version = "0.14.2"
    features = ["extension-module"]
    $ cat src/lib.rs
    use pyo3::prelude::*;
    
    #[pyfunction]
    fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
        Ok((a + b).to_string())
    }
    
    #[pymodule]
    fn foo(_py: Python, m: &PyModule) -> PyResult<()> {
        m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
        Ok(())
    }
    
    #[cfg(test)]
    mod tests {
        use super::*;
        #[test]
        fn test() {
            assert_ne!(sum_as_string(10, 20).unwrap(), "29");
            assert_eq!(sum_as_string(10, 20).unwrap(), "30");
        }
    }
    $ ./.venv/bin/python -m pip install --upgrade maturin
    Collecting maturin
      Using cached maturin-0.11.2-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (10.5 MB)
    Collecting toml~=0.10.2
      Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
    Installing collected packages: toml, maturin
    Successfully installed maturin-0.11.2 toml-0.10.2
    $ maturin develop
    🔗 Found pyo3 bindings
    🐍 Found CPython 3.9 at python
       Compiling proc-macro2 v1.0.28
       Compiling unicode-xid v0.2.2
       Compiling proc-macro-hack v0.5.19
       Compiling syn v1.0.74
       Compiling pyo3-build-config v0.14.2 (https://github.com/PyO3/pyo3#336e87ec)
       Compiling once_cell v1.8.0
       Compiling libc v0.2.99
       Compiling unindent v0.1.7
       Compiling quote v1.0.9
       Compiling parking_lot_core v0.8.3
       Compiling parking_lot v0.11.1
       Compiling paste-impl v0.1.18
       Compiling pyo3 v0.14.2 (https://github.com/PyO3/pyo3#336e87ec)
       Compiling paste v0.1.18
       Compiling pyo3-macros-backend v0.14.2 (https://github.com/PyO3/pyo3#336e87ec)
       Compiling indoc-impl v0.3.6
       Compiling indoc v0.3.6
       Compiling pyo3-macros v0.14.2 (https://github.com/PyO3/pyo3#336e87ec)
       Compiling foo v0.1.0 (/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo)
        Finished dev [unoptimized + debuginfo] target(s) in 6.09s
    $ cargo test
       Compiling foo v0.1.0 (/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo)
    error: linking with `cc` failed: exit status: 1
      |
      = note: "cc" "-arch" "arm64" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.110fvvgslxwl7xjc.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.12kh3itm9hwj9eya.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.16g57alsqnv4g7f.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.1a0ghimskmekwiuk.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.1av1bln3bhfp9nj.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.1f7ufrshnyieunmq.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.1grj2h43vo039nxn.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.1w6b9uzfz2s5unib.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.23ga6qr0715pwz5y.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.24e8nkkcbbxnt787.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2a30e9rsdwwu0myc.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2bfqaxllo29w3ifh.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2crziipwfs2kz1rl.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2ehls50ircwkdmom.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2f1e1rxz18gsu2mj.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2fdsczpl1dm1fip.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2g4fb0qea2p4q6xm.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2guxm18uiabqkc4g.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2jufnvyjxohkzt7x.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2knf917igqi0yh23.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2p5zghtzgwcs84b3.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2ryebkgzo7xg8qnt.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2w9t2gyroz08k6r5.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2zqka4hc0y9fowwt.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2zxc1obih7i5hr7t.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.2zygjmkbd28bfn6s.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.31ff4xyicc3wnhmg.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.32mlaq0jdx1jm6es.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.386vuxnbh48s9wou.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.3cd74yt2oylhtzgz.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.3exvfe10ewcn52er.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.3g5mqpn1qg0wh1a9.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.3h0owt6q12tqs9k1.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.3lmvouff0a9ask7g.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.3m044sb2289k1a45.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.3nlmoppukou4iz9o.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.3sp1r43kboysk609.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.3z1hnn9k793ut1vv.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.404rd2jigivih456.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.41g3d6jr8g5e13dg.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.44bcgq52s2fm83bo.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.46y4g6gr7pgrmj5p.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.4a8upifjlrchwi95.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.4ibyiowjhkywlxz5.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.4kb8d8qea0l2v9xb.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.4u279idye23i71pz.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.4vdhqlwluf10xra6.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.4vw02eizd1tr7ojw.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.4wsoqwueg83w4bj4.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.4xwdfbwtcu6drnpn.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.4zb71mjndf679w95.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.4zebmmyhpove6ig9.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.50i6cvni8o6e604x.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.50m5yqhkl1tj8tt7.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.51bwrx5e8skq6vdz.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.53gw0dkzu34phl59.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.54uz16ierizblqjb.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.58htorl2ddld3vy6.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.5efmic2dvfz0pyna.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.7vrbjuouu484zpk.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.d8kk98i9kjuql8j.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.gc7opmckjdvlw86.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.io5k9a5m56skmi7.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.m0svsb223gbvcdi.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.ov0hczhn18vqy4g.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.pp1aw1mhc4kqgka.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.q1smzop47y4w3d2.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.snh43turx8z4g5z.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.vfssu1qsbtfwmz3.rcgu.o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879.44z81xxn3zvsfpbf.rcgu.o" "-L" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps" "-L" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libtest-06ff11d645105e2b.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libterm-f05ecaeca66814e6.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgetopts-6ad0d034fc8e15c7.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunicode_width-c4beacdc35405cb8.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_std-fc0f4647def297a8.rlib" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/libpyo3-194c7c6b45ae4486.rlib" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/libparking_lot-3d6f176468cb3e55.rlib" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/libparking_lot_core-1a66328f5320fcf8.rlib" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/libsmallvec-b1d3333bf059e064.rlib" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/liblock_api-09ae7dbe1cd82c80.rlib" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/libscopeguard-62e7a6d9289eec1f.rlib" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/libinstant-4e05ab198a32da16.rlib" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/libcfg_if-254a4227ea494762.rlib" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/liblibc-2d65d84e2d4e9c71.rlib" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/libunindent-dda6001dcdbb754c.rlib" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/libpaste-61320a4b949429d0.rlib" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/libindoc-758ee8d2665c486a.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd-000cdec9267bfd7b.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-2669f3cbce8358f4.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libobject-86461a1c60728ccb.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-f17574752cb5ddba.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgimli-3bb606c936cc0d28.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-8139a4b0cda20184.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-ea0823eca3e9abf9.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-4f19e1259f6028e7.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-435daca85b8e10b5.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunwind-d73085abefd284c6.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-e6a09ca0044b34e5.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liblibc-e07333f48f53c71e.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liballoc-2a49b0d9fbc7a459.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-b66dda66aafe36c9.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-34d0b58da984bf31.rlib" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-01275baa20724171.rlib" "-liconv" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv" "-L" "/Users/n8henrie/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879" "-Wl,-dead_strip" "-nodefaultlibs"
      = note: Undefined symbols for architecture arm64:
                "_PyExc_TypeError", referenced from:
                    _$LT$pyo3..exceptions..PyTypeError$u20$as$u20$pyo3..type_object..PyTypeInfo$GT$::type_object_raw::h3351d28f1f012e04 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.1.rcgu.o)
                "_PyExc_BaseException", referenced from:
                    _$LT$pyo3..exceptions..PyBaseException$u20$as$u20$pyo3..type_object..PyTypeInfo$GT$::type_object_raw::h3e7fd002a901032a in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.1.rcgu.o)
                "_PyBytes_AsString", referenced from:
                    pyo3::types::bytes::PyBytes::as_bytes::hcb83c311a32d8877 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.15.rcgu.o)
                "_PyErr_Print", referenced from:
                    pyo3::err::panic_after_error::h86153d46e74bf037 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.15.rcgu.o)
                "_PyBytes_Size", referenced from:
                    pyo3::types::bytes::PyBytes::as_bytes::hcb83c311a32d8877 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.15.rcgu.o)
                "_PyErr_NormalizeException", referenced from:
                    pyo3::err::PyErr::normalized::h9588758d1ccab3f5 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.15.rcgu.o)
                "_PyErr_PrintEx", referenced from:
                    pyo3::err::PyErr::print::h797d38ccce2cbbaf in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.15.rcgu.o)
                "_PyErr_NewException", referenced from:
                    pyo3::err::PyErr::new_type::hfb51b941f04ed644 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.15.rcgu.o)
                "_PyErr_Restore", referenced from:
                    pyo3::err::PyErr::restore::h1dbbf8b88416361d in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.15.rcgu.o)
                "_PyGILState_Release", referenced from:
                    _$LT$pyo3..gil..GILGuard$u20$as$u20$core..ops..drop..Drop$GT$::drop::hf2f8a6f21e2d4dfe in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.10.rcgu.o)
                "_PyErr_Fetch", referenced from:
                    pyo3::err::PyErr::fetch::h48d0241c5aeeaf12 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.15.rcgu.o)
                "_PyUnicode_AsUTF8AndSize", referenced from:
                    pyo3::types::string::PyString::to_str::h7219ef1704e18050 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.2.rcgu.o)
                "_PyGILState_Ensure", referenced from:
                    pyo3::gil::GILGuard::acquire_unchecked::hb63c5f585f222b6d in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.10.rcgu.o)
                "_PyEval_ThreadsInitialized", referenced from:
                    pyo3::gil::GILGuard::acquire::_$u7b$$u7b$closure$u7d$$u7d$::hb0a84271271719f2 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.10.rcgu.o)
                "_PyUnicode_AsEncodedString", referenced from:
                    pyo3::types::string::PyString::to_string_lossy::hdc219ee0b91d0d09 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.2.rcgu.o)
                "_Py_IsInitialized", referenced from:
                    pyo3::gil::GILGuard::acquire::_$u7b$$u7b$closure$u7d$$u7d$::hb0a84271271719f2 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.10.rcgu.o)
                "_PyExc_SystemError", referenced from:
                    _$LT$pyo3..exceptions..PySystemError$u20$as$u20$pyo3..type_object..PyTypeInfo$GT$::type_object_raw::h788c3eab76189041 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.1.rcgu.o)
                "_PyObject_Repr", referenced from:
                    pyo3::types::any::PyAny::repr::hb17f942fc5a28d64 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.11.rcgu.o)
                "__Py_Dealloc", referenced from:
                    pyo3::ffi::object::Py_DECREF::h99cb8d1a6d9fe0a4 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.5.rcgu.o)
                "_PyUnicode_FromStringAndSize", referenced from:
                    pyo3::types::string::PyString::new::h875d8b9d6e9e8e21 in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.2.rcgu.o)
                "_PyObject_GetAttr", referenced from:
                    pyo3::types::any::PyAny::getattr::_$u7b$$u7b$closure$u7d$$u7d$::h26dc56d4a757defc in libpyo3-194c7c6b45ae4486.rlib(pyo3-194c7c6b45ae4486.pyo3.960x274q-cgu.11.rcgu.o)
              ld: symbol(s) not found for architecture arm64
              clang: error: linker command failed with exit code 1 (use -v to see invocation)
    
    
    error: aborting due to previous error
    
    error: could not compile `foo`
    
    To learn more, run the command again with --verbose.
    

    Things I've tried with / without in various combinations:

    [target.aarch64-apple-darwin]
    rustflags = [
      "-C", "link-arg=-undefined",
      "-C", "link-arg=dynamic_lookup",
    ]
    

    This results in a different error:

    dyld: Symbol not found: _PyExc_BaseException
      Referenced from: /private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879
      Expected in: flat namespace
     in /private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879
    error: test failed, to rerun pass '--lib'
    
    Caused by:
      process didn't exit successfully: `/private/var/folders/kb/tw_lp_xd2_bbv0hqk4m0bvt80000gn/T/tmp.uLGa46f6aT/foo/target/debug/deps/foo-bf9e8350fad87879` (signal: 6, SIGABRT: process abort signal)
    
    • PYO3_PYTHON=/usr/bin/python3 cargo test no change
    • PYO3_PYTHON=/opt/homebrew/bin/python3 cargo test no change
    • PYO3_PYTHON=/usr/bin/python3 cargo test
    • PYO3_PYTHON=~/.pyenv/versions/3.9.6/bin/python cargo test no change
    • In or out of virtualenv no change

    Also no change with:

    [features]
    extension-module = ["pyo3/extension-module"]
    default = ["extension-module"]
    

    I've tried to cargo clean before cargo test with all of these, and tried with cargo test --no-default-features as well.

    Thanks for a cool library, I'm excited to start delving into it. FWIW this was building and testing fine on Windows yesterday :) It looks like there is some active work going on to make this easier on MacOS, so I hope this is more constructive than just adding to noise or confusion.

    Further reading:

    • https://github.com/PyO3/pyo3/issues/1719
    • https://github.com/PyO3/pyo3/issues/1741
    • https://github.com/PyO3/pyo3/issues/1330
    • https://pyo3.rs/latest/faq.html#i-cant-run-cargo-test-im-having-linker-issues-like-symbol-not-found-or-undefined-reference-to-_pyexc_systemerror
    documentation needs-implementer 
    opened by n8henrie 36
  • docs: fixed typo in error_handling.md

    docs: fixed typo in error_handling.md

    the sample code currently produces this error:

    15 |     fn from(error: MyOtherError) -> Self {
       |        ---- this function doesn't have a `self` parameter
    16 |         PyValueError::new_err(self.0.message())
       |                               ^^^^ `self` value is a keyword only available in methods with a `self` parameter
    
    CI-skip-changelog 
    opened by mrob95 1
  • Further relax extract_sequence for the upcoming release 0.18

    Further relax extract_sequence for the upcoming release 0.18

    These are the two less controversial parts, i.e. turning anything that can be iterated into a Vec whether it calls itself a sequence or not and also accepting str where the changelog entry gives a concrete hint on how to handle the str-as-Vec<String> edge case ergonomically as is common in Python API.

    opened by adamreichold 5
  • Reproducable crash with pyo3 and tensorflow

    Reproducable crash with pyo3 and tensorflow

    Bug Description

    We encountered a very similar sounding issue to #2032 #1623 - but "luckily" for us the crash happens quite reliably!

    It doesn't seem specific to tensorflow as it seems to crash similarly with some pytorch code

    Steps to Reproduce

    Create simple project, and virtual env with tensorflow (pandas also included as it was in the original Python snippet, but I don't think it is relevant)

    $ cargo new --bin pyo3_tf_crash
    $ cd pyo3_tf_crash/
    $ python -m venv _venv
    $ source _venv/bin/activate
    $ pip install tensorflow pandas
    
    $ cat Cargo.toml
    [package]
    name = "pyo3_tf_crash"
    version = "0.1.0"
    edition = "2021"
    
    [dependencies]
    pyo3 = {version = "0.17.1", features = ["auto-initialize"]}
    

    And finally, src/main.rs

    use pyo3::prelude::*;
    
    static CODE: &'static str = r#"import pandas
    d = [
        {'status': 'a', 'title': 'title 1'},
        {'status': 'b', 'title': 'title 2'},
    ]
    
    data = pandas.DataFrame(d)
    sentiment_label = data.status.factorize()
    
    maxlen = 30
    
    from tensorflow.keras.preprocessing.text import Tokenizer
    from tensorflow.keras.preprocessing.sequence import pad_sequences
    from tensorflow.keras.models import Sequential
    from tensorflow.keras.layers import LSTM,Dense, Dropout, SpatialDropout1D
    from tensorflow.keras.layers import Embedding
    
    
    
    tokenizer = Tokenizer(num_words=5000)
    tokenizer.fit_on_texts(data.title.values)
    
    encoded_docs = tokenizer.texts_to_sequences(data.title.values)
    padded_sequence = pad_sequences(encoded_docs, maxlen=maxlen)
    
    vocab_size = len(tokenizer.word_index) + 1
    
    
    
    embedding_vector_length = 32
    model = Sequential()
    model.add(Embedding(vocab_size, embedding_vector_length, input_length=maxlen))
    model.add(SpatialDropout1D(0.25))
    model.add(LSTM(50, dropout=0.5, recurrent_dropout=0.5))
    model.add(Dropout(0.2))
    model.add(Dense(1, activation='sigmoid'))
    
    model.compile(loss='binary_crossentropy',optimizer='adam', metrics=['accuracy'])
    
    history = model.fit(padded_sequence, sentiment_label[0], validation_split=0.2, epochs=2, batch_size=32)
    "#;
    
    fn start_py_thread() {
        std::thread::spawn(move || loop {
            use pyo3::prelude::*;
            Python::with_gil(|py| {
                py.run(CODE, None, None).unwrap();
            });
        });
    }
    
    fn main() {
        // Acquire then drop GIL
        let gil = Python::acquire_gil();
        std::mem::drop(gil);
    
        // Start thread doing Python things
        start_py_thread();
    
        loop {
            println!("Waiting");
            std::thread::sleep(std::time::Duration::from_secs(1));
        }
    }
    

    Run the script, and when the model fitting runs for the second time, it will crash (usually a segfault, but I think may occasionally either abort or deadlock)

    $ cargo run
       Compiling pyo3_tf_crash v0.1.0 (/home/dbr/Desktop/pyo3_tf_crash)
    warning: use of deprecated associated function `pyo3::Python::<'py>::acquire_gil`: prefer Python::with_gil
      --> src/main.rs:56:23
       |
    56 |     let gil = Python::acquire_gil();
       |                       ^^^^^^^^^^^
       |
       = note: `#[warn(deprecated)]` on by default
    
    warning: `pyo3_tf_crash` (bin "pyo3_tf_crash") generated 1 warning
        Finished dev [unoptimized + debuginfo] target(s) in 0.77s
         Running `target/debug/pyo3_tf_crash`
    Waiting
    Waiting
    Waiting
    Waiting
    Waiting
    [...]
    Waiting
    Epoch 1/2
    Waiting
    Waiting
    Waiting
    Waiting
    Waiting
    Waiting
    1/1 [==============================] - ETA: 0s - loss: 0.6860 - accuracy: 1.0000Waiting
    1/1 [==============================] - 8s 8s/step - loss: 0.6860 - accuracy: 1.0000 - val_loss: 0.7145 - val_accuracy: 0.0000e+00
    Epoch 2/2
    1/1 [==============================] - 0s 101ms/step - loss: 0.6703 - accuracy: 1.0000 - val_loss: 0.7226 - val_accuracy: 0.0000e+00
    Waiting
    Epoch 1/2
    Segmentation fault
    

    Backtrace

    #0  __GI___pthread_mutex_lock (mutex=0x1b0) at ../nptl/pthread_mutex_lock.c:67
    #1  0x00007ffff7bc3fac in ?? () from /lib/x86_64-linux-gnu/libpython3.9.so.1.0
    #2  0x00007ffff7bc443e in PyEval_AcquireThread () from /lib/x86_64-linux-gnu/libpython3.9.so.1.0
    #3  0x00007fffa3328195 in pybind11::gil_scoped_acquire::gil_scoped_acquire() () from /home/dbr/Desktop/pyo3_tf_crash/_venv/lib/python3.9/site-packages/tensorflow/python/client/_pywrap_tf_session.so
    #4  0x00007fffa3345b5c in pybind11::cpp_function::initialize<pybind11_init__pywrap_tf_session(pybind11::module_&)::{lambda(TF_Operation*, char const*)#25}, pybind11::object, TF_Operation*, char const*, pybind11::name, pybind11::scope, pybind11::sibling>(pybind11_init__pywrap_tf_session(pybind11::module_&)::{lambda(TF_Operation*, char const*)#25}&&, pybind11::object (*)(TF_Operation*, char const*), pybind11::name const&, pybind11::scope const&, pybind11::sibling const&)::{lambda(pybind11::detail::function_call&)#3}::_FUN(pybind11::detail::function_call&) () from /home/dbr/Desktop/pyo3_tf_crash/_venv/lib/python3.9/site-packages/tensorflow/python/client/_pywrap_tf_session.so
    #5  0x00007fffa33468fc in pybind11::cpp_function::dispatcher(_object*, _object*, _object*) () from /home/dbr/Desktop/pyo3_tf_crash/_venv/lib/python3.9/site-packages/tensorflow/python/client/_pywrap_tf_session.so
    #6  0x00007ffff7b2dc93 in ?? () from /lib/x86_64-linux-gnu/libpython3.9.so.1.0
    #7  0x00007ffff7ae7a50 in _PyObject_MakeTpCall () from /lib/x86_64-linux-gnu/libpython3.9.so.1.0
    #8  0x00007ffff7a992f2 in _PyEval_EvalFrameDefault () from /lib/x86_64-linux-gnu/libpython3.9.so.1.0
    [...]
    

    Your operating system and version

    Linux/Debian 11 Bullseye

    Your Python version (python --version)

    Python 3.9.2

    Your Rust version (rustc --version)

    rustc 1.62.0

    Your PyO3 version

    0.16.4 and 0.17

    How did you install python? Did you use a virtualenv?

    Using system Python via apt, virtualenv used as per repo-steps

    Additional Info

    Haven't tested the trimmed down reproduction example on Windows, but the code in it's original application crashed on both Linux and Windows

    bug 
    opened by dbr 2
  • docs: `#[pyclass(sequence)]` does not make Python add the sequence length to negative indexes

    docs: `#[pyclass(sequence)]` does not make Python add the sequence length to negative indexes

    Bug Description

    https://pyo3.rs/v0.17.1/class/protocols.html#mapping--sequence-types

    Use the #[pyclass(sequence)] annotation to instruct PyO3 to fill the sq_length slot instead of the mp_length slot for len. This will help libraries such as numpy recognise the class as a sequence, however will also cause CPython to automatically add the sequence length to any negative indices before passing them to getitem. (getitem, setitem and delitem mapping slots are still used for sequences, for slice operations.)

    What actually happens is that negative indices are passed as is to __getitem__.

    I guess this happens because PyO3 only fills the mapping slot for __getitem__, and the negative index correction thing only happens when calling the sequence slot for __getitem__.

    Steps to Reproduce

    Minimal reproduction:

    use pyo3::prelude::*;                                  
                                                           
    #[pyclass(sequence)]                                   
    struct MyList;                                         
                                                           
    #[pymethods]                                           
    impl MyList {                                          
        #[new]                                             
        fn new() -> MyList {                               
            MyList {}                                      
        }                                                  
                                                           
        fn __len__(&self) -> usize {                       
            42                                             
        }                                                  
                                                           
        fn __getitem__(&self, idx: isize) -> bool {        
            assert!(idx >= 0);                             
            true                                           
        }                                                  
    }                                                      
                                                           
    #[pymodule]                                            
    fn testmod(_py: Python, m: &PyModule) -> PyResult<()> {
        m.add_class::<MyList>()?;                          
        Ok(())                                             
    }                                                      
    

    Backtrace

    >>> from testmod import MyList
    >>> a = MyList()
    >>> a[-1]
    thread '<unnamed>' panicked at 'assertion failed: idx >= 0', src/lib.rs:18:9
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    pyo3_runtime.PanicException: assertion failed: idx >= 0
    >>> a[0]
    True
    
    
    
    ### Your operating system and version
    
    Arch Linux
    
    ### Your Python version (`python --version`)
    
    Python 3.10.6
    
    ### Your Rust version (`rustc --version`)
    
    rustc 1.63.0
    
    ### Your PyO3 version
    
    0.17.1
    
    ### How did you install python? Did you use a virtualenv?
    
    pacman
    
    Yes
    
    ### Additional Info
    
    _No response_
    bug 
    opened by ravenexp 2
  • Fail to run cargo test.

    Fail to run cargo test.

    Bug Description

    When I ran cargo test command, it failed with the following errors:

    cargo test
       Compiling target-lexicon v0.12.4
       Compiling autocfg v1.1.0
       Compiling once_cell v1.13.1
       Compiling proc-macro2 v1.0.43
       Compiling libc v0.2.132
       Compiling quote v1.0.21
       Compiling unicode-ident v1.0.3
       Compiling syn v1.0.99
       Compiling parking_lot_core v0.9.3
       Compiling scopeguard v1.1.0
       Compiling cfg-if v1.0.0
       Compiling smallvec v1.9.0
       Compiling unindent v0.1.10
       Compiling indoc v1.0.7
       Compiling lock_api v0.4.7
       Compiling num-traits v0.2.15
       Compiling pyo3-build-config v0.16.6
       Compiling parking_lot v0.12.1
       Compiling ordered-float v3.0.0
       Compiling pyo3-ffi v0.16.6
       Compiling pyo3 v0.16.6
       Compiling pyo3-macros-backend v0.16.6
       Compiling pyo3-macros v0.16.6
       Compiling itemcf v1.0.0 (/Users/Myname/Desktop/Myname/Work/Github/itemcf/itemcf)
        Finished test [unoptimized + debuginfo] target(s) in 34.05s
         Running unittests src/lib.rs (target/debug/deps/itemcf-dc85442e1cd8d29b)
    dyld: Library not loaded: @rpath/libpython3.8.dylib
      Referenced from: /Users/Myname/Desktop/Myname/Work/Github/itemcf/itemcf/target/debug/deps/itemcf-dc85442e1cd8d29b
      Reason: image not found
    error: test failed, to rerun pass '--lib'
    
    Caused by:
      process didn't exit successfully: `/Users/Myname/Desktop/Myname/Work/Github/itemcf/itemcf/target/debug/deps/itemcf-dc85442e1cd8d29b` (signal: 6, SIGABRT: process abort signal)
    
    
    ### Steps to Reproduce
    
    1. git clone [email protected]:tushushu/itemcf.git
    2. check out wip-heap branch
    3. cd yourdir/itemcf
    4. cargo test
    
    ### Backtrace
    
    _No response_
    
    ### Your operating system and version
    
    MacOS big sur 11.6.8
    
    ### Your Python version (`python --version`)
    
    Python 3.8
    
    ### Your Rust version (`rustc --version`)
    
    1.61.0
    
    ### Your PyO3 version
    
    0.16.4
    
    ### How did you install python? Did you use a virtualenv?
    
    conda create -n py38 python=3.8
    
    ### Additional Info
    
    _No response_
    enhancement documentation needs-design 
    opened by tushushu 3
Releases(v0.17.1)
  • v0.17.1(Aug 28, 2022)

    This release contains some minor bug fixes for PyO3 0.17.0. In particular the new PyDictItems, PyDictKeys and PyDictValues types are actually accessible!

    Thanks to @davidhewitt, @messense and @PrettyWood for the fixes.

    Source code(tar.gz)
    Source code(zip)
  • v0.17.0(Aug 23, 2022)

    This release contains a focus on quality improvements over the PyO3 0.16 releases.

    There have been new API types added such as PyDictKeys, PyDictValues, PyDictItems, PyCode, PyFrame, and PySuper. The PyMapping and PySequence types have changed so they are more directly compatible with the corresponding Python Mapping and Sequence base classes in the collections.abc module (this is a breaking change).

    A new #[pyclass(frozen)] option has been added to opt-out of runtime borrow checking by removing the ability to access &mut self for objects owned by Python.

    There have been a number of soundness fixes, both to the PyCapsule type (see the CHANGELOG for more details) and to a number of FFI bindings which had fallen out of sync with newer Python and PyPy releases.

    There have been numerous other smaller improvements, changes and fixes. For full details see the CHANGELOG.

    Please consult the migration guide for help upgrading.

    Thank you to everyone who contributed code, documentation, design ideas, bug reports, and feedback. The following users' commits are included in this release:

    @acshi @aganders3 @alex @birkenfeld @cjermain @Cryptex-github @cuishuang @davidhewitt @drewkett @dswij @herquan @hoodmane @ikrivosheev @indygreg @jeertmans @jinlow @jonaspleyer @kngwyu @mejrs @messense @n8henrie @PigeonF @PWhiddy @ravenexp @savente93 @yankun1992 @yodaldevoid

    Source code(tar.gz)
    Source code(zip)
  • v0.16.6(Aug 23, 2022)

    This release is a tactical set of soundness fixes identified for the PyCapsule bindings released in PyO3 0.16. To avoid breaking API changes capsules created with PyCapsule::new and PyCapsule::new_with_destructor will now leak their contents (and not call the destructor) if released on a thread other than the one they were created.

    PyO3 0.17 will be released shortly with breaking API changes which resolve the PyCapsule issues with better design (e.g. the destructor has a Send bound added). Users are encouraged to upgrade at their earliest convenience.

    Thanks to @saethlin for reporting the issue, and to @adamreichold and @davidhewitt for implementing the resolution.

    Source code(tar.gz)
    Source code(zip)
  • v0.16.5(May 15, 2022)

    This release contains an FFI definition correction to resolve crashes for PyOxidizer on Python 3.10, and a new generate-import-lib feature to allow easier cross-compiling to Windows.

    Thank you to the following users for the improvements:

    @cjermain @davidhewitt @indygreg @messense

    Source code(tar.gz)
    Source code(zip)
  • v0.16.4(Apr 14, 2022)

    This release fixes a regression introduced in 0.16.3 leading to build failures on Windows, enables crates depending on PyO3 to collect code coverage using LLVM instrumentation on stable Rust version 1.60 or later, and enables safe access to time zone information attached to Python's time and datetime objects. There are also some adjustments to PyO3's build-time interpreter detection to make it easier to cross-compile abi3 Python extensions.

    Thank you to the following users for the improvements:

    @adamreichold @davidhewitt @mejrs @messense @pickfire @ravenexp @RicoHageman

    Source code(tar.gz)
    Source code(zip)
  • v0.15.2(Apr 14, 2022)

    This release is a backport of PyO3 0.16's support for PyPy 3.9.

    Thanks to @mejrs and @messense for the implementation work, and to @alex for testing it to build the cryptography package.

    Source code(tar.gz)
    Source code(zip)
  • v0.16.3(Apr 5, 2022)

    This release contains a number of non-breaking additions and fixes since PyO3 0.16.2.

    They are mostly centered on improving support for various build configurations. There are also usability tweaks to the #[pyclass] macro and a new intern! macro to create statically-backed PyString objects as an optimization technique.

    Thank you to the following users for the improvements:

    @adamreichold @aganders3 @alex @kmp1 @mejrs @messense @mityax
    @momirza @ravenexp @zh-jq

    Source code(tar.gz)
    Source code(zip)
  • v0.16.2(Mar 15, 2022)

    This release contains support for the latest PyPy 7.3.8 release, a fix for a regression from PyO3 0.16.0 which would cause flaky build failures, and corrections to documentation.

    Thank you for the following users for the improvements:

    @adamreichold @alex @birkenfeld @davidhewitt @messense

    Source code(tar.gz)
    Source code(zip)
  • v0.16.1(Mar 5, 2022)

    This release contains a couple of fixes for regressions in PyO3 0.16.0, as well as documentation fixes. The hashbrown optional dependency range has been extended to include its new 0.12 version.

    Thank you for the following users for the improvements:

    @adamreichold @alex @birkenfeld @davidhewitt @JerzySpendel @mejrs @messense @PanQL

    Source code(tar.gz)
    Source code(zip)
  • v0.16.0(Feb 27, 2022)

    This release contains substantial changes and improvements over PyO3 0.15.1. To support these improvements, support has been dropped for the end-of-life Python 3.6 and Rust versions older than 1.48.

    The pyo3::ffi submodule has been split out into a separate pyo3-ffi crate, so that users who want to use PyO3's Python bindings without any of the safe APIs or macros are able to do so.

    #[pyclass] can now be used on simple "C-like" enums to create Python enums.

    The #[pyproto] macro has been deprecated, and can be disabled by disabling the optional #[pyproto] feature. The "magic methods" such as __repr__ which previously were implemented by #[pyproto] gained support in #[pymethods] in 0.15, and now in PyO3 0.16 #[pymethods] is intended to be the only attribute macro needed to write class method implementations.

    There are numerous other reworks, improvements, and bugfixes.

    For full details of all changes, see the CHANGELOG.

    Thank you to everyone who contributed code, documentation, design ideas, bug reports, and feedback. The following users' commits are included in this release:

    @adamreichold @aganders3 @Amanieu @aviramha @birkenfeld @b05902132 @CarlKCarlK @cmpute @danielhenrymantilla @davidhewitt @DSPOM2 @ghuls @Gobot1234 @kevinheavey @konstin @mejrs @messense @milesgranger @mrl5 @parsons20 @RicoHageman @saidvandeklundert @Tom1380 @vxgmichel

    Source code(tar.gz)
    Source code(zip)
  • v0.15.1(Nov 19, 2021)

    This release is a set of bug fixes for some minor issues reported since PyO3 0.15's release. There are also some small additions for those storing PyIterator, PySequence, and PyMapping in Py smart pointers, and a PyTraceback type to ease interacting with Python tracebacks from Rust.

    For full details of all changes, see the CHANGELOG.

    Thank you to everyone who contributed code, documentation, design ideas, bug reports, and feedback. The following users' commits are included in this release:

    @dansvo @davidhewitt @KRunchPL @mejrs @messense @moriyoshi @saidvandeklundert @taiki-e

    Source code(tar.gz)
    Source code(zip)
  • v0.15.0(Nov 3, 2021)

    This release of PyO3 brings support for Python 3.10 and PyPy 3.8. In addition, new optional dependencies on anyhow and eyre have been added for easy integration of the popular error-handling libraries with Python code.

    A number of consistency improvements have been made to PyList, PyTuple and PySequence APIs. They now all exclusively use usize- based indexing, and now also support Rust's indexing operator.

    In this release #[pymethods] are now able to implement many magic methods such as __str__ and __repr__, removing the need for #[pyproto] macro implementations. For the 0.15 release series both #[pymethods] and #[pyproto] will be supported; #[pyproto] is expected to be deprecated in the future.

    For full details of all changes, see the CHANGELOG. For help with upgrading, see the migration guide.

    Thank you to everyone who contributed code, documentation, design ideas, bug reports, and feedback.

    Source code(tar.gz)
    Source code(zip)
  • v0.14.5(Sep 5, 2021)

    This release fixes a compile regression of PyO3 0.14.4 where not all APIs related to PyStringData were conditionally disabled correctly on big-endian platforms.

    In addition, a few public APIs have been added to the pyo3_build_config crate to support needs of the PyOxidizer project.

    Thanks to @decathorpe and @indygreg for further reports, discussions, and resolution.

    Source code(tar.gz)
    Source code(zip)
  • v0.14.4(Aug 29, 2021)

    This release resolves issues with the PyString::data API added in 0.14.3. After release it was found to be unsound on certain platforms, so has been disabled on those platforms and marked unsafe with the safety expectation that users will ensure it works appropriately on their platform as part of usage.

    Thanks to @decathorpe and @indygreg for the report, discussion, and resolution.

    Source code(tar.gz)
    Source code(zip)
  • v0.14.3(Aug 22, 2021)

    This release is a small set of bugfixes added on top of the PyO3 0.14.2 release.

    For full details of all changes, see the CHANGELOG.

    Thank you to everyone who contributed code, documentation, design ideas, bug reports, and feedback. The following users' commits are included in this release:

    @awestlake87 @davidhewitt @indygreg @mejrs @messense @mtreinish @pschafhalter @Ptrskay3 @sansyrox @tiran

    Source code(tar.gz)
    Source code(zip)
  • v0.14.2(Aug 9, 2021)

    This release is a small quality-of-life update for the PyO3 0.14 release series. Optional support for the indexmap crate has been added. In addition, there have been a number of documentation improvements, and bugfixes for regressions and incorrect FFI definitions.

    Users who removed macOS cargo configuration from their setup after updating to PyO3 0.14 will unfortunately have to once again add configuration to their compilation after updating to this release. This is because PyO3 was using functionality which Cargo had erroneously allowed.

    The recommended way to restore configuration for macOS is to add a build script which invokes pyo3_build_config::add_extension_module_link_args(). The cargo configuration previously recommended is also still an option.

    For full details of all changes, see the CHANGELOG.

    Thank you to everyone who contributed code, documentation, design ideas, bug reports, and feedback. The following users' commits are included in this release:

    @alex @awestlake87 @batconjurer @birkenfeld @davidhewitt @deantvv @Eric-Arellano @indygreg
    @IvanIsCoding @mejrs @messense @nihaals @tommilligan

    Source code(tar.gz)
    Source code(zip)
  • v0.14.1(Jul 4, 2021)

    This release addresses some incorrect FFI definitions in PyO3 0.14.0 which caused crashes when targeting PyPy. In addition, IntoPy<PyObject> has been implemented for &PathBuf and &OsString for additional convenience when working with the new conversions.

    Thank you to @alex and @jameshilliard for the quick reports, and @birkenfeld and @messense for the quick fixes!

    Source code(tar.gz)
    Source code(zip)
  • v0.14.0(Jul 3, 2021)

    This release contains a significant number of improvements and optimizations since the 0.13 releases. Conversion support for more Rust standard library types has been added: [T; N], Path, PathBuf, OsStr, and OsString. In addition, the #[pyo3(...)] attribute options already used in #[pyclass] and #[derive(FromPyObject)] have been expanded to all macros to cover more options such as #[pyo3(name = "...")].

    This release also includes some notable performance optimizations to PyO3's Python function generation, and users should observe reductions in overhead when calling PyO3-wrapped functions from Python. The documentation has also benefited from extensive work from several contributors.

    Finally, there are a number of breaking changes to this release:

    • To reduce the default dependency set, a new feature multiple-pymethods has been added. If this feature is not enabled, each #[pyclass] may only have a single #[pymethods] block. If this feature is enabled then the previous behavior (and dependency on inventory) is restored.
    • The pyo3::ffi module has received many updates to keep in sync with CPython's definitions.
    • A number of APIs and particular usages of PyO3 macros have been marked deprecated where better alternatives now exist.
    • A number of previously-deprecated APIs have been removed.

    For full details of all changes, see the CHANGELOG. For help with upgrading, see the migration guide.

    Thank you to everyone who contributed code, documentation, design ideas, bug reports, and feedback. The following users' commits are included in this release:

    @alex @alonblade @aviramha @birkenfeld @c410-f3r @Daggy1234 @daniil-konovalenko @davidhewitt @erikjohnston @GabrielMajeri @gilescope @indygreg @isosphere @jameshilliard @kangalioo @kngwyu @konstin @m-ou-se @mejrs @messense @nw0 @ohadravid @ravenexp @scalexm @simonrainerson @TheGhostHuCodes @winxton @1tgr

    Source code(tar.gz)
    Source code(zip)
  • v0.13.2(Feb 12, 2021)

    This release contains small improvements over PyO3 0.13.1. The minimum supported Rust version has been lowered to Rust 1.41. A serde feature has been added which provides implementations of Serialize and Deserialize for types inside the Py<T> smart pointer.

    Of note is that this release disables automatic finalization of the Python interpreter at program exit for Rust binaries embedding the Python interpreter. This was found to cause a number of issues with C extensions such as Tensorflow and Scipy which were sensitive to the deinitialization order. For the vast majority of users this should cause no impact or fix a number of problem cases. For the minority who did depend on finalization, the unsafe method with_embedded_python_interpreter has been added to manually control the interpreter lifecycle.

    For full details of all changes, see the CHANGELOG.

    Thank you to everyone who contributed code, documentation fixes, design ideas, bug reports, and feedback. The following users' commits are included in this release:

    @alex @awestlake87 @birkenfeld @cfbolz @daniil-konovalenko @davidhewitt @decathorpe @ijl @kangalioo @kngwyu @lazka @nw0 @tdamsma

    Source code(tar.gz)
    Source code(zip)
  • v0.13.1(Jan 10, 2021)

    This release is a set of quality-of-life improvements and bugfixes for PyO3 0.13.0. All new functionality adds flexibility to pyo3 in rarer cases, such as fixing #[pyclass(dict)] support for the abi3 feature (on compatible Python versions). In addition, a long-overdue initiative to reconcile PyO3's ffi definitions with the current state of the upstream Python API has started. This resulted in a number of new deprecations where mismatches were found.

    For full details of all changes, see the CHANGELOG.

    Thank you to everyone who contributed code, documentation fixes, design ideas, bug reports, and feedback. The following users' commits are included in this release:

    @cecini @dalcde @daniil-konovalenko @davidhewitt @kngwyu @konstin @nw0 @OrangeTux

    Source code(tar.gz)
    Source code(zip)
  • v0.13.0(Dec 22, 2020)

    The major feature for this PyO3 release is support for the CPython limited API. This is an opt-in feature when building extension modules which makes it possible for the built wheel to be installable on multiple Python versions.

    As well as this, a number of other refinements, fixes, and performance improvements have been merged into this release. In particular, note that the internal "macros" crates have been renamed to pyo3-macros and pyo3-macros-backend for clarity and consistency (previously pyo3cls and pyo3-derive-backend).

    For full details of all changes, see the CHANGELOG.

    Thank you to everyone who contributed code, documentation fixes, design ideas, bug reports, and feedback. The following users' commits are included in this release:

    @AleksaC @alex @Askaholic @aviramha @birkenfeld @Daggy1234 @davidhewitt @dvermd @kngwyu @konstin @Palladinium @roblabla @scalexm @Stranger6667

    Source code(tar.gz)
    Source code(zip)
  • v0.12.4(Nov 28, 2020)

    This release fixes a reference count issue discovered in PyO3 0.12.3, present in the implementation of From<Py<T>> for PyObject. Usage of this implementation would lead to an incorrect Python reference count decrease, likely leading to use-after-free.

    This regression was only present in the PyO3 0.12 series. The offending implementation was used only in one location inside the PyO3 codebase itself, though of course is likely used in downstream code. As a result, previous PyO3 versions in the 0.12 series will be yanked.

    Sincerest apologies for the inconvenience.

    Fixed

    • Fix reference count bug in implementation of From<Py<T>> for PyObject, a regression introduced in PyO3 0.12. #1297
    Source code(tar.gz)
    Source code(zip)
  • v0.12.3(Oct 12, 2020)

    This release fixes support for Rust versions 1.39 through Rust 1.44, which was erroneously broken in PyO3 0.12.2. Thanks to @mtreinish for the quick bug report!

    Source code(tar.gz)
    Source code(zip)
  • v0.12.2(Oct 12, 2020)

    This release adds the ability to specify keyword-only arguments in #[pyfunction] definitions, a new function Python::check_signals, and a couple of smaller refinements improving upon PyO3 0.12.1.

    Thank you to everyone who contributed code, documentation fixes, design ideas, bug reports, and feedback. The following users' commits are included in this release:

    @birkenfeld @davidhewitt @dvermd
    @kngwyu @sebpuetz

    Source code(tar.gz)
    Source code(zip)
  • v0.12.1(Sep 16, 2020)

    This release contains a couple of bugfixes to resolve complation issues with 0.12.0 on specific targets. Thank you to @alex and @mtreinish for the bug reports and subsequent patches.

    Fixed

    • Fix building for a 32-bit Python on 64-bit Windows with a 64-bit Rust toolchain. #1179
    • Fix building on platforms where c_char is u8. #1182
    Source code(tar.gz)
    Source code(zip)
  • v0.12.0(Sep 12, 2020)

    This release includes a few careful revisions to the PyO3 API with the intention to make it easier to learn and use. The PyErr type is reworked to implement std::error::Error. The FromPy trait is removed. Finally, the PyObject struct is now just a type alias to Py<PyAny>. While we do not take pleasure in making breaking changes for users' code, we have done so with careful thought to make migration as simple as possible while also allowing the PyO3 API to mature. Please see the migration guide for help upgrading if any of these changes affect you.

    Also added is a new #[derive(FromPyObject)] macro, which enables a convenient way to accept arguments of the Python "type" Union. (See the guide entry on this new feature.)

    There have been many other improvements and bugfixes too numerous to go into detail here. For the full list, see the CHANGELOG.

    Thank you to everyone who contributed code, documentation fixes, design ideas, bug reports, and feedback on the way to PyO3 0.12. The full list of users who commited at least one contribution to PyO3 0.12 is below:

    @alex @birkenfeld @cathay4t @davidhewitt @Hakuyume @Hywan @kngwyu @konstin @marioortizmanero @MoritzLangenstein @mtreinish @mvaled @nagisa @noam93k @Progdrasil @programmerjake @rob-thatcher @sebpuetz @vorner @vthriller

    Source code(tar.gz)
    Source code(zip)
  • v0.11.1(Jul 3, 2020)

  • v0.11.0(Jun 28, 2020)

    This is our first version that supports the stable Rust toolchain. The minimum required version is 1.39.0. Thank you @davidhewitt @scalexm @tamuhey @konstin @Nateckert @Alexander-N @m-ou-se and all issue reporters :slightly_smiling_face:

    Maybe the most influential change is now #[pyclass] requires Send. Please see the migration guide for more.

    Added

    • Support stable versions of Rust (>=1.39). #969
    • Add FFI definition PyObject_AsFileDescriptor. #938
    • Add PyByteArray::data, PyByteArray::as_bytes, and PyByteArray::as_bytes_mut. #967
    • Add GILOnceCell to use in situations where lazy_static or once_cell can deadlock. #975
    • Add Py::borrow, Py::borrow_mut, Py::try_borrow, and Py::try_borrow_mut for accessing #[pyclass] values. #976
    • Add IterNextOutput and IterANextOutput for returning from __next__ / __anext__. #997

    Changed

    • Simplify internals of #[pyo3(get)] attribute. (Remove the hidden API GetPropertyValue.) #934
    • Call Py_Finalize at exit to flush buffers, etc. #943
    • Add type parameter to PyBuffer. #951
    • Require Send bound for #[pyclass]. #966
    • Add Python argument to most methods on PyObject and Py<T> to ensure GIL safety. #970
    • Change signature of PyTypeObject::type_object() - now takes Python argument and returns &PyType. #970
    • Change return type of PyTuple::slice() and PyTuple::split_from() from Py<PyTuple> to &PyTuple. #970
    • Change return type of PyTuple::as_slice to &[&PyAny]. #971
    • Rename PyTypeInfo::type_object to type_object_raw, and add Python argument. #975
    • Update num-complex optional dependendency from 0.2 to 0.3. #977
    • Update num-bigint optional dependendency from 0.2 to 0.3. #978
    • #[pyproto] is re-implemented without specialization. #961
    • PyClassAlloc::alloc is renamed to PyClassAlloc::new. #990
    • #[pyproto] methods can now have return value T or PyResult<T> (previously only PyResult<T> was supported). #996
    • #[pyproto] methods can now skip annotating the return type if it is (). #998

    Removed

    • Remove ManagedPyRef (unused, and needs specialization) #930

    Fixed

    • Fix passing explicit None to Option<T> argument #[pyfunction] with a default value. #936
    • Fix PyClass.__new__'s not respecting subclasses when inherited by a Python class. #990
    • Fix returning Option<T> from #[pyproto] methods. #996
    • Fix accepting PyRef<Self> and PyRefMut<Self> to #[getter] and #[setter] methods. #999
    Source code(tar.gz)
    Source code(zip)
  • v0.10.1(May 14, 2020)

    0.10.0 has a deadlock bug and was yanked. Thank you @davidhewitt for fixing it!

    Fixed

    • Fix deadlock in Python::acquire_gil() after dropping a PyObject or Py<T>. #924
    Source code(tar.gz)
    Source code(zip)
  • v0.10.0(May 13, 2020)

    Many changes but not so many API changes. See CHANGELOG and migraton guide for more.

    Thank you @davidhewitt @m-ou-se @scalexm @Alexander-N @abingham @althonos @konstin @ijl @ArniDagur @oconnor663 and all issue reporters!

    Added

    • Add FFI definition _PyDict_NewPresized. #849
    • Implement IntoPy<PyObject> for HashSet and BTreeSet. #864
    • Add PyAny::dir method. #886
    • Gate macros behind a macros feature (enabled by default). #897
    • Add ability to define class attributes using #[classattr] on functions in #[pymethods]. #905
    • Implement Clone for PyObject and Py<T>. #908
    • Implement Deref<Target = PyAny> for all builtin types. (PyList, PyTuple, PyDict etc.) #911
    • Implement Deref<Target = PyAny> for PyCell<T>. #911
    • Add #[classattr] support for associated constants in #[pymethods]. #914

    Changed

    • Panics will now be raised as a Python PanicException. #797
    • Change PyObject and Py<T> reference counts to decrement immediately upon drop when the GIL is held. #851
    • Allow PyIterProtocol methods to use either PyRef or PyRefMut as the receiver type. #856
    • Change the implementation of FromPyObject for Py<T> to apply to a wider range of T, including all T: PyClass. #880
    • Move all methods from the ObjectProtocol trait to the PyAny struct. #911
    • Remove need for #![feature(specialization)] in crates depending on PyO3. #917

    Removed

    • Remove PyMethodsProtocol trait. #889
    • Remove num-traits dependency. #895
    • Remove ObjectProtocol trait. #911
    • Remove PyAny::None. Users should use Python::None instead. #911
    • Remove all *ProtocolImpl traits. #917

    Fixed

    • Fix support for __radd__ and other __r*__ methods as implementations for Python mathematical operators. #839
    • Fix panics during garbage collection when traversing objects that were already mutably borrowed. #855
    • Prevent &'static references to Python objects as arguments to #[pyfunction] and #[pymethods]. #869
    • Fix lifetime safety bug with AsPyRef::as_ref. #876
    • Fix #[pyo3(get)] attribute on Py<T> fields. #880
    • Fix segmentation faults caused by functions such as PyList::get_item returning borrowed objects when it was not safe to do so. #890
    • Fix segmentation faults caused by nested Python::acquire_gil calls creating dangling references. #893
    • Fix segmentatation faults when a panic occurs during a call to Python::allow_threads. #912
    Source code(tar.gz)
    Source code(zip)
Owner
PyO3
Pythonium Trioxide
PyO3
RustPython - A Python Interpreter written in Rust

RustPython A Python-3 (CPython >= 3.9.0) Interpreter written in Rust ?? ?? ?? . Usage Check out our online demo running on WebAssembly. RustPython req

null 12.1k Sep 20, 2022
Create a Python project automatically with rust (like create-react-app but for python)

create-python-project Create a Python project automatically with rust (like create-react-app but for python) Installation cargo install create-python-

Dhravya Shah 2 Mar 12, 2022
Create, open, manage your Python projects with ease, a project aimed to make python development experience a little better

Create, open, manage your Python projects with ease, a project aimed to make python development experience a little better

Dhravya Shah 7 Jul 10, 2022
Rust <-> Python bindings

rust-cpython Rust bindings for the python interpreter. Documentation Cargo package: cpython Copyright (c) 2015-2020 Daniel Grunwald. Rust-cpython is l

Daniel Grunwald 1.6k Sep 22, 2022
Implementation of Monte Carlo PI approximation algorithm in Rust Python bindings

rusty_pi Implementation of Monte Carlo PI approximation algorithm in Rust Python bindings. Time of 100M iterations approximation on Core i7 10th gen:

Aleksey Popov 1 Jul 6, 2022
Very experimental Python bindings for the Rust biscuit-auth library

Overview This is a very experimental take on Python bindings for the biscuit_auth Rust library. It is very much a work in progress (limited testing, m

Josh Wright 5 Sep 14, 2022
Python bindings for heck, the Rust case conversion library

pyheck PyHeck is a case conversion library (for converting strings to snake_case, camelCase etc). It is a thin wrapper around the Rust library heck. R

Kevin Heavey 33 Sep 22, 2022
lavalink-rs bindings for Python

lavasnek_rs Dev Docs: Main Site | Fallback: GitHub Pages GitHub repo GitLab repo Using the library The library is available on PyPi, and you can insta

Victoria Casasampere Fernandez 38 Aug 5, 2022
The polyglot bindings generator for your library (C#, C, Python, …) 🐙

Interoptopus ?? The polyglot bindings generator for your library. Interoptopus allows you to deliver high-quality system libraries to your users, and

Ralf Biedert 104 Sep 22, 2022
Python bindings for akinator-rs using pyo3

Akinator-py python bindings for akinator-rs using pyo3 Installation Prebuilt wheels are uploaded onto pypi, if you platform is supported, you can inst

Tom-the-Bomb 2 Aug 21, 2022
A simple Pascal interpreter written in rust.

rascal A simple Pascal interpreter written in rust. Usage Download the latest rascal executable from the release page. Run the executable. rascal.exe

null 44 Sep 1, 2022
A simple interpreter language written in Rust.

Glang Backstory Hello and welcome to the Glang git repository. Game Slang or in short Glang is a super simple interpreted language written in Rust wit

null 5 Jul 3, 2022
A memory safe Lua interpreter

Hematita Da Lua Hematita Da Lua is an interpreter for the scripting language Lua, written entirely in 100% safe Rust. Hematita is the portugese word f

Daniel 133 Sep 14, 2022
An interpreter for the esoteric programming language, Brainf*ck.

Brainf*ck Interpreter This is just a normal Brainf*ck interpreter written in Rust. If you don't know what Brainf*ck is, you can check out the wikipedi

Callum Irving 0 Dec 23, 2021
WebAssembly (Wasm) interpreter.

Continuous Integration Test Coverage Documentation Crates.io wasmi- WebAssembly (Wasm) Interpreter wasmi was conceived as a component of parity-ethere

Parity Technologies 959 Sep 23, 2022
Lisp interpreter that might be fast someday maybe?

ehlisp Pronunciation I'm not really sure. Maybe like an incorrect pronunciation of "ellipse", like "ellisp"? Also maybe like "a lisp". I named it this

Eddie Hatfield 3 May 9, 2022
A script language like Python or Lua written in Rust, with exactly the same syntax as Go's.

A script language like Python or Lua written in Rust, with exactly the same syntax as Go's.

null 1.4k Sep 23, 2022
Rust Python modules for interacting with Metaplex's NFT standard.

Simple Metaplex Metadata Decoder Install the correct Python wheel for your Python version with pip: pip install metaplex_decoder-0.1.0-cp39-cp39-manyl

Samuel Vanderwaal 11 Mar 31, 2022
A simple library to allow for easy use of python from rust.

Rustpy A simple library to allow for easy use of python from rust. Status Currently this library has not received much love (pull requests welcome for

Luke 74 Jun 20, 2022