#pyo3 #async-io #async #events #python #python-bindings

pyo3-asyncio

PyO3 为 Python 的 Asyncio 库提供的实用工具

14 个版本 (7 个重大更改)

0.20.0 2023 年 11 月 11 日
0.19.0 2023 年 7 月 23 日
0.18.0 2023 年 2 月 2 日
0.17.0 2022 年 10 月 7 日
0.13.2 2021 年 2 月 20 日

#16 in FFI

Download history 15879/week @ 2024-04-20 61807/week @ 2024-04-27 59799/week @ 2024-05-04 21302/week @ 2024-05-11 14557/week @ 2024-05-18 12461/week @ 2024-05-25 14816/week @ 2024-06-01 15257/week @ 2024-06-08 13826/week @ 2024-06-15 12831/week @ 2024-06-22 11238/week @ 2024-06-29 9524/week @ 2024-07-06 10964/week @ 2024-07-13 9522/week @ 2024-07-20 10324/week @ 2024-07-27 9571/week @ 2024-08-03

41,888 每月下载量
用于 30 个 Crates (28 个直接使用)

Apache-2.0

215KB
2K SLoC

PyO3 Asyncio

Actions Status codecov crates.io minimum rustc 1.63

Rust 对 Python 的 Asyncio 库的绑定。这个包促进了 Rust Futures 和 Python 协程之间的交互,并管理它们对应的事件循环的生命周期。

PyO3 Asyncio 是 PyO3 生态系统的一个全新的部分。对于此包的功能请求或错误修复,请随时提出任何问题。

如果您是新手,阅读以下入门指南是开始的最佳方式!对于 v0.13.2 和 v0.14 用户,我强烈建议阅读迁移部分,以了解 v0.14 和 v0.15 的主要更改。

用法

与 PyO3 类似,PyO3 Asyncio 支持以下软件版本

  • Python 3.7 及以上(CPython 和 PyPy)
  • Rust 1.48 及以上

PyO3 Asyncio 入门指南

如果您正在使用一个使用异步函数的Python库或希望为异步Rust库提供Python绑定,pyo3-asyncio很可能拥有您需要的工具。它提供了Python和Rust中异步函数之间的转换,并设计了对流行的Rust运行时(如tokioasync-std)的一级支持。此外,所有异步Python代码都在默认的asyncio事件循环上运行,因此pyo3-asyncio应该可以很好地与现有的Python库一起工作。

在以下部分中,我们将对pyo3-asyncio进行概述,解释如何使用PyO3调用异步Python函数,如何从Python调用异步Rust函数,以及如何配置您的代码库来管理这两个运行时。

快速入门

以下是立即开始的一些示例!这些示例中概念的更详细说明可以在以下部分中找到。

Rust应用程序

在这里,我们初始化运行时,导入Python的asyncio库,并使用Python的默认EventLoopasync-std运行给定的future,直到完成。在future内部,我们将asyncio睡眠转换为Rust future并等待它。

# Cargo.toml dependencies
[dependencies]
pyo3 = { version = "0.20" }
pyo3-asyncio = { version = "0.20", features = ["attributes", "async-std-runtime"] }
async-std = "1.9"
//! main.rs

use pyo3::prelude::*;

#[pyo3_asyncio::async_std::main]
async fn main() -> PyResult<()> {
    let fut = Python::with_gil(|py| {
        let asyncio = py.import("asyncio")?;
        // convert asyncio.sleep into a Rust Future
        pyo3_asyncio::async_std::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
    })?;

    fut.await?;

    Ok(())
}

相同的程序可以写成使用tokio,使用#[pyo3_asyncio::tokio::main]属性。

# Cargo.toml dependencies
[dependencies]
pyo3 = { version = "0.20" }
pyo3-asyncio = { version = "0.20", features = ["attributes", "tokio-runtime"] }
tokio = "1.9"
//! main.rs

use pyo3::prelude::*;

#[pyo3_asyncio::tokio::main]
async fn main() -> PyResult<()> {
    let fut = Python::with_gil(|py| {
        let asyncio = py.import("asyncio")?;
        // convert asyncio.sleep into a Rust Future
        pyo3_asyncio::tokio::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
    })?;

    fut.await?;

    Ok(())
}

有关此库的更多详细信息,请参阅API文档和下面的入门指南。

PyO3原生Rust模块

PyO3 Asyncio还可以用来编写带有异步函数的原生模块。

[lib]部分添加到Cargo.toml中,使您的库成为Python可以导入的cdylib

[lib]
name = "my_async_module"
crate-type = ["cdylib"]

通过启用extension-module功能,使您的项目依赖于pyo3,并选择您的pyo3-asyncio运行时

对于async-std

[dependencies]
pyo3 = { version = "0.20", features = ["extension-module"] }
pyo3-asyncio = { version = "0.20", features = ["async-std-runtime"] }
async-std = "1.9"

对于tokio

[dependencies]
pyo3 = { version = "0.20", features = ["extension-module"] }
pyo3-asyncio = { version = "0.20", features = ["tokio-runtime"] }
tokio = "1.9"

导出一个使用async-std的异步函数

//! lib.rs

use pyo3::{prelude::*, wrap_pyfunction};

#[pyfunction]
fn rust_sleep(py: Python) -> PyResult<&PyAny> {
    pyo3_asyncio::async_std::future_into_py(py, async {
        async_std::task::sleep(std::time::Duration::from_secs(1)).await;
        Ok(())
    })
}

#[pymodule]
fn my_async_module(py: Python, m: &PyModule) -> PyResult<()> {
    m.add_function(wrap_pyfunction!(rust_sleep, m)?)?;

    Ok(())
}

如果您想使用tokio,则模块应该如下所示

//! lib.rs

use pyo3::{prelude::*, wrap_pyfunction};

#[pyfunction]
fn rust_sleep(py: Python) -> PyResult<&PyAny> {
    pyo3_asyncio::tokio::future_into_py(py, async {
        tokio::time::sleep(std::time::Duration::from_secs(1)).await;
        Ok(())
    })
}

#[pymodule]
fn my_async_module(py: Python, m: &PyModule) -> PyResult<()> {
    m.add_function(wrap_pyfunction!(rust_sleep, m)?)?;
    Ok(())
}

您可以使用maturin(请参阅PyO3指南中的在Python中使用Rust部分中的设置说明)构建您的模块。之后,您应该能够运行Python REPL来尝试它。

maturin develop && python3
🔗 Found pyo3 bindings
🐍 Found CPython 3.8 at python3
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>>
>>> from my_async_module import rust_sleep
>>>
>>> async def main():
>>>     await rust_sleep()
>>>
>>> # should sleep for 1s
>>> asyncio.run(main())
>>>

在Rust中等待异步Python函数

让我们看看一个简单的异步Python函数

# Sleep for 1 second
async def py_sleep():
    await asyncio.sleep(1)

Python中的异步函数只是返回一个coroutine对象的函数。对于我们来说,我们真的不需要了解太多关于这些coroutine对象。关键因素在于调用异步函数的方式就像调用常规函数一样,唯一的不同之处在于我们必须对它返回的对象做一些特殊处理。

在Python中,这种特殊处理通常是await关键字,但为了在Rust中等待这个协程,我们首先需要将其转换为Rust的coroutine版本:一个Future。这正是pyo3-asyncio发挥作用的地方。 pyo3_asyncio::into_future为我们执行这个转换

use pyo3::prelude::*;

#[pyo3_asyncio::tokio::main]
async fn main() -> PyResult<()> {
    let future = Python::with_gil(|py| -> PyResult<_> {
        // import the module containing the py_sleep function
        let example = py.import("example")?;

        // calling the py_sleep method like a normal function
        // returns a coroutine
        let coroutine = example.call_method0("py_sleep")?;

        // convert the coroutine into a Rust future using the
        // tokio runtime
        pyo3_asyncio::tokio::into_future(coroutine)
    })?;

    // await the future
    future.await?;

    Ok(())
}

如果您想了解更多关于 协程可等待对象 的信息,请查看Python 3 asyncio 文档以获取更多信息。

在 Python 中等待 Rust 未来

这里有一个与之前相同的异步函数,使用 async-std 运行时在 Rust 中编写

/// Sleep for 1 second
async fn rust_sleep() {
    async_std::task::sleep(std::time::Duration::from_secs(1)).await;
}

与 Python 类似,Rust 的异步函数也返回一个特殊对象,称为 Future

let future = rust_sleep();

我们可以将这个 Future 对象转换为 Python,使其成为 可等待。这告诉 Python 可以使用 await 关键字。为了做到这一点,我们将调用 pyo3_asyncio::async_std::future_into_py

use pyo3::prelude::*;

async fn rust_sleep() {
    async_std::task::sleep(std::time::Duration::from_secs(1)).await;
}

#[pyfunction]
fn call_rust_sleep(py: Python) -> PyResult<&PyAny> {
    pyo3_asyncio::async_std::future_into_py(py, async move {
        rust_sleep().await;
        Ok(())
    })
}

在 Python 中,我们可以像调用任何其他异步函数一样调用这个 pyo3 函数

from example import call_rust_sleep

async def rust_sleep():
    await call_rust_sleep()

管理事件循环

Python 的事件循环需要一些特殊处理,尤其是在主线程方面。Python 的某些 asyncio 功能,如适当的信号处理,需要控制主线程,而这与 Rust 不太兼容。

幸运的是,Rust 的事件循环非常灵活,并且 不需要 控制主线程,因此在 pyo3-asyncio 中,我们决定最好的处理 Rust/Python 互操作的方法是将主线程交给 Python,并在后台运行 Rust 的事件循环。不幸的是,由于大多数事件循环实现 更喜欢 控制主线程,这仍然会使一些事情变得尴尬。

PyO3 Asyncio 初始化

由于 Python 需要控制主线程,我们不能使用 Rust 运行时的方便的 proc 宏来处理 main 函数或 #[test] 函数。相反,PyO3 的初始化必须从 main 函数中进行,并且主线程必须在 pyo3_asyncio::run_foreverpyo3_asyncio::async_std::run_until_complete 上阻塞。

由于我们必须在这些函数上阻塞,因此我们不能使用 #[async_std::main]#[tokio::main],因为在一个异步函数中进行长阻塞调用不是一个好主意。

内部,这些 #[main] proc 宏被展开为类似以下的内容

fn main() {
    // your async main fn
    async fn _main_impl() { /* ... */ }
    Runtime::new().block_on(_main_impl());
}

在由 block_on 驱动的 Future 中进行长阻塞调用,会阻止该线程执行任何其他操作,并可能给某些运行时带来麻烦(实际上,这也会导致单线程运行时死锁!)。许多运行时都提供某种形式的 spawn_blocking 机制,可以避免这个问题,但同样,由于我们需要在 线程上进行阻塞,所以我们不能在这里使用它。

因此,pyo3-asyncio 提供了自己的一组 proc 宏,以提供这种初始化。这些宏旨在反映 async-stdtokio 的初始化,同时满足 Python 运行时的需求。

以下是一个使用 async-std 运行时的 PyO3 初始化的完整示例

use pyo3::prelude::*;

#[pyo3_asyncio::async_std::main]
async fn main() -> PyResult<()> {
    // PyO3 is initialized - Ready to go

    let fut = Python::with_gil(|py| -> PyResult<_> {
        let asyncio = py.import("asyncio")?;

        // convert asyncio.sleep into a Rust Future
        pyo3_asyncio::async_std::into_future(
            asyncio.call_method1("sleep", (1.into_py(py),))?
        )
    })?;

    fut.await?;

    Ok(())
}

关于 asyncio.run 的说明

在 Python 3.7+ 中,使用 asyncio 运行顶级协程的推荐方法是使用 asyncio.run。在 v0.13 中,由于初始化问题,我们不建议使用此函数,但在 v0.14 中,使用此函数是完全可以接受的……但有前提。

由于我们的 Rust <--> Python 转换需要 Python 事件循环的引用,这引发了一个问题。想象一下,我们有一个 PyO3 Asyncio 模块,其中定义了一个类似于之前的示例中的 rust_sleep 函数。你可能会合理地假设可以直接像这样将其传递给 asyncio.run

import asyncio

from my_async_module import rust_sleep

asyncio.run(rust_sleep())

你可能惊讶地发现这会引发错误

Traceback (most recent call last):
  File "example.py", line 5, in <module>
    asyncio.run(rust_sleep())
RuntimeError: no running event loop

这里发生的情况是,我们在使用 asyncio.run 创建的事件循环上的未来实际运行之前,调用了 rust_sleep。这很反直觉,但这是预期行为,不幸的是,似乎没有很好的方法在 PyO3 Asyncio 本身内解决这个问题。

然而,我们可以通过一个简单的解决方案使这个示例工作

import asyncio

from my_async_module import rust_sleep

# Calling main will just construct the coroutine that later calls rust_sleep.
# - This ensures that rust_sleep will be called when the event loop is running,
#   not before.
async def main():
    await rust_sleep()

# Run the main() coroutine at the top-level instead
asyncio.run(main())

非标准 Python 事件循环

Python 允许您使用默认的 asyncio 事件循环之外的选择。一种流行的替代方案是 uvloop。在 v0.13 中,使用非标准事件循环有些麻烦,但在 v0.14 中,这是微不足道的事情。

在 PyO3 Asyncio 原生扩展中使用 uvloop

# Cargo.toml

[lib]
name = "my_async_module"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.20", features = ["extension-module"] }
pyo3-asyncio = { version = "0.20", features = ["tokio-runtime"] }
async-std = "1.9"
tokio = "1.9"
//! lib.rs

use pyo3::{prelude::*, wrap_pyfunction};

#[pyfunction]
fn rust_sleep(py: Python) -> PyResult<&PyAny> {
    pyo3_asyncio::tokio::future_into_py(py, async {
        tokio::time::sleep(std::time::Duration::from_secs(1)).await;
        Ok(())
    })
}

#[pymodule]
fn my_async_module(_py: Python, m: &PyModule) -> PyResult<()> {
    m.add_function(wrap_pyfunction!(rust_sleep, m)?)?;

    Ok(())
}
$ maturin develop && python3
🔗 Found pyo3 bindings
🐍 Found CPython 3.8 at python3
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Python 3.8.8 (default, Apr 13 2021, 19:58:26)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> import uvloop
>>>
>>> import my_async_module
>>>
>>> uvloop.install()
>>>
>>> async def main():
...     await my_async_module.rust_sleep()
...
>>> asyncio.run(main())
>>>

在 Rust 应用程序中使用 uvloop

在 Rust 应用程序中使用 uvloop 要复杂一些,但通过相对较小的修改仍然可以实现。

不幸的是,我们无法在非标准事件循环中使用 #[pyo3_asyncio::<runtime>::main] 属性。这是因为 #[pyo3_asyncio::<runtime>::main] proc 宏必须在我们可以安装 uvloop 策略之前与 Python 事件循环交互。

[dependencies]
async-std = "1.9"
pyo3 = "0.20"
pyo3-asyncio = { version = "0.20", features = ["async-std-runtime"] }
//! main.rs

use pyo3::{prelude::*, types::PyType};

fn main() -> PyResult<()> {
    pyo3::prepare_freethreaded_python();

    Python::with_gil(|py| {
        let uvloop = py.import("uvloop")?;
        uvloop.call_method0("install")?;

        // store a reference for the assertion
        let uvloop = PyObject::from(uvloop);

        pyo3_asyncio::async_std::run(py, async move {
            // verify that we are on a uvloop.Loop
            Python::with_gil(|py| -> PyResult<()> {
                assert!(uvloop
                    .as_ref(py)
                    .getattr("Loop")?
                    .downcast::<PyType>()
                    .unwrap()
                    .is_instance(pyo3_asyncio::async_std::get_current_loop(py)?)?);
                Ok(())
            })?;

            async_std::task::sleep(std::time::Duration::from_secs(1)).await;

            Ok(())
        })
    })
}

更多信息

迁移指南

从0.13迁移到0.14

那么,从v0.13v0.14有哪些变化呢?

实际上变化很多。在v0.13的初始化行为中存在一些相当严重的缺陷。虽然最好在不改变公共API的情况下解决这些问题,但我决定打破一些旧的API,而不是完全改变现有函数的底层行为。我明白这可能会带来一些麻烦,所以希望本节能帮助您顺利过渡。

为了让事情变得简单一些,我决定保留大部分旧的API和新API(同时发出一些弃用警告,鼓励用户迁移)。您应该可以在旧版的v0.13 API和新版的v0.14 API之间切换,这样您就可以分阶段升级应用程序,而不是一次性升级。

在您开始之前,我建议您先看看事件循环引用和ContextVars,以便更好地理解这些变化背后的动机以及使用新转换的细微差别。

0.14 突出显示

  • Tokio初始化现在是懒加载的。
    • 如果您使用的是多线程调度器,则无需进行配置。
    • 调用pyo3_asyncio::tokio::init_multithreadpyo3_asyncio::tokio::init_multithread_once可以直接删除。
    • 调用pyo3_asyncio::tokio::init_current_threadpyo3_asyncio::tokio::init_current_thread_once需要特别注意。
    • 自定义运行时配置是通过将一个tokio::runtime::Builder传递给pyo3_asyncio::tokio::init来完成的,而不是传递一个tokio::runtime::Runtime
  • 添加了一套新的、更正确的函数来替换v0.13的转换。
    • pyo3_asyncio::into_future_with_loop
    • pyo3_asyncio::<runtime>::future_into_py_with_loop
    • pyo3_asyncio::<runtime>::local_future_into_py_with_loop
    • pyo3_asyncio::<runtime>::into_future
    • pyo3_asyncio::<runtime>::future_into_py
    • pyo3_asyncio::<runtime>::local_future_into_py
    • pyo3_asyncio::<runtime>::get_current_loop
  • 如果您只使用pyo3_asyncio::try_init转换,则不再需要pyo3_asyncio::try_init
  • ThreadPoolExecutor现在不再在启动时自动配置。
    • 幸运的是,这似乎对 v0.13 代码影响不大,这意味着现在您可以手动根据需要配置执行器。

将您的代码升级到 0.14

  1. 修复 PyO3 0.14 初始化。

    • PyO3 0.14 将其自动初始化行为置于“自动初始化”后。您可以在项目中启用“自动初始化”行为,或者将 pyo3::prepare_freethreaded_python() 调用添加到程序的起始处。
    • 如果您使用的是 #[pyo3_asyncio::<runtime>::main] proc 宏属性,则可以跳过此步骤。#[pyo3_asyncio::<runtime>::main] 将在程序启动时调用 pyo3::prepare_freethreaded_python(),而不考虑项目中“自动初始化”功能。
  2. 修复 tokio 初始化。

    • 调用pyo3_asyncio::tokio::init_multithreadpyo3_asyncio::tokio::init_multithread_once可以直接删除。

    • 如果您使用当前线程调度程序,您需要在初始化时手动启动运行的线程

      let mut builder = tokio::runtime::Builder::new_current_thread();
      builder.enable_all();
      
      pyo3_asyncio::tokio::init(builder);
      std::thread::spawn(move || {
          pyo3_asyncio::tokio::get_runtime().block_on(
              futures::future::pending::<()>()
          );
      });
      
    • 可以将自定义的 tokio::runtime::Builder 配置传递给 pyo3_asyncio::tokio::init。第一次调用 pyo3_asyncio::tokio::get_runtime() 时,将懒加载 tokio::runtime::Runtime

  3. 如果您在应用程序中使用 pyo3_asyncio::run_forever,则应切换到更手动的方法。

    run_forever 不是在 Python 中运行事件循环的推荐方式,所以可能最好远离它。此函数可能需要更改以适应 0.14,但由于它被认为是一个边缘情况,因此决定如果用户需要,可以手动调用它。

    use pyo3::prelude::*;
    
    fn main() -> PyResult<()> {
        pyo3::prepare_freethreaded_python();
    
        Python::with_gil(|py| {
            let asyncio = py.import("asyncio")?;
    
            let event_loop = asyncio.call_method0("new_event_loop")?;
            asyncio.call_method1("set_event_loop", (event_loop,))?;
    
            let event_loop_hdl = PyObject::from(event_loop);
    
            pyo3_asyncio::tokio::get_runtime().spawn(async move {
                tokio::time::sleep(std::time::Duration::from_secs(1)).await;
    
                // Stop the event loop manually
                Python::with_gil(|py| {
                    event_loop_hdl
                        .as_ref(py)
                        .call_method1(
                            "call_soon_threadsafe",
                            (event_loop_hdl
                                .as_ref(py)
                                .getattr("stop")
                                .unwrap(),),
                        )
                        .unwrap();
                })
            });
    
            event_loop.call_method0("run_forever")?;
            Ok(())
        })
    }
    
  4. 用它们的较新版本替换转换。

    您可能会遇到有关 get_running_loopget_event_loop 使用的某些问题。有关这些较新转换及其使用的更多详细信息,请参阅 事件循环引用和 ContextVars

    • pyo3_asyncio::into_future 替换为 pyo3_asyncio::<runtime>::into_future
    • pyo3_asyncio::<runtime>::into_coroutine 替换为 pyo3_asyncio::<runtime>::future_into_py
    • pyo3_asyncio::get_event_loop 替换为 pyo3_asyncio::<runtime>::get_current_loop
  5. 将所有转换替换为其 v0.14 对应版本后,可以安全地移除 pyo3_asyncio::try_init

在版本 v0.15 中删除了 v0.13 API

从 0.14 迁移到 0.15+

API 发生了一些变化,以支持从 Python 和 contextvars 模块进行适当的取消。

  • 可以将任何 cancellable_future_into_pylocal_cancellable_future_into_py 转换替换为其 future_into_pylocal_future_into_py 对应版本。

    取消支持在 0.15 中成为默认行为。

  • 应将 *_with_loop 转换的实例替换为较新的 *_with_locals 转换。

    use pyo3::prelude::*;
    
    Python::with_gil(|py| -> PyResult<()> {
    
        // *_with_loop conversions in 0.14
        //
        // let event_loop = pyo3_asyncio::get_running_loop(py)?;
        //
        // let fut = pyo3_asyncio::tokio::future_into_py_with_loop(
        //     event_loop,
        //     async move { Ok(Python::with_gil(|py| py.None())) }
        // )?;
        //
        // should be replaced with *_with_locals in 0.15+
        let fut = pyo3_asyncio::tokio::future_into_py_with_locals(
            py,
            pyo3_asyncio::tokio::get_current_locals(py)?,
            async move { Ok(()) }
        )?;
    
        Ok(())
    });
    
  • scopescope_local 变体现在接受 TaskLocals 而不是 event_loop。通常只需将 event_loop 替换为 pyo3_asyncio::TaskLocals::new(event_loop).copy_context(py)?

  • future_into_pyfuture_into_py_with_localslocal_future_into_pylocal_future_into_py_with_locals 的返回类型现在由有界 IntoPy<PyObject> 限制,而不是要求返回类型为 PyObject。这可以使未来的返回类型更灵活,但具体类型不明确时(例如使用 into()),推理可能会失败。有时可以简单地移除 into()

  • runrun_until_complete 现在可以返回任何 Send + 'static 值。

从 0.15 迁移到 0.16

实际上,API 中变化不大。我很高兴地说,PyO3 Asyncio 在 0.16 中达到了相当稳定的状态。在大多数情况下,0.16 是关于清理和从 API 中删除已弃用函数。

PyO3 0.16 自带一些 API 变更,但对其 Asyncio 影响最大的是决定停止支持 Python 3.6。PyO3 Asyncio 之前使用了一些变通方法或技巧来支持 3.7 版本之前的 Python asyncio 库,但这些方法现在不再需要。因此,PyO3 Asyncio 的底层实现也因此变得更加简洁。

PyO3 Asyncio 0.15 对 API 进行了一些重要修复,以添加对正确任务取消的支持,并允许在 Python 协程中保留/使用 contextvars。这导致了某些 0.14 版本中用于边缘情况的功能被废弃,并转而使用更正确的版本,这些废弃的功能在 0.16 版本的 API 中已被移除。

此外,随着 PyO3 Asyncio 0.16 的发布,库现在对从 Python 的异步生成器到 Rust Stream 的转换提供了实验性支持。目前有两个版本 v1v2,它们具有略微不同的性能和类型签名,因此我希望能得到一些反馈,了解哪个版本最适合下游用户。只需启用 unstable-streams 功能即可!

反之,从 Rust Stream 到 Python 异步生成器的转换可能会在后续版本中提供,如果用户有需求的话!

依赖关系

~4–15MB
~203K SLoC