Skip to content

Commit ea21b82

Browse files
authored
Readme updates (#23)
1 parent 4ab275c commit ea21b82

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

Diff for: README.md

+14-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![crates.io](https://img.shields.io/crates/v/pyo3-async-runtimes)](https://crates.io/crates/pyo3-async-runtimes)
66
[![minimum rustc 1.63](https://img.shields.io/badge/rustc-1.63+-blue.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
77

8-
***This is a fork of [`pyo3-asyncio`](https://github.com/awestlake87/pyo3-asyncio/) to deliver compatibility for PyO3 0.21. This may be the base for a permanent fork in the future, depending on the status of the original `pyo3-asyncio` maintainer.***
8+
***This is a fork of [`pyo3-asyncio`](https://github.com/awestlake87/pyo3-asyncio/) to deliver compatibility for PyO3 0.21+. This may be the base for a permanent fork in the future, depending on the status of the original `pyo3-asyncio` maintainer.***
99

1010
[Rust](http://www.rust-lang.org/) bindings for [Python](https://www.python.org/)'s [Asyncio Library](https://docs.python.org/3/library/asyncio.html). This crate facilitates interactions between Rust Futures and Python Coroutines and manages the lifecycle of their corresponding event loops.
1111

@@ -19,26 +19,24 @@
1919

2020
> PyO3 Asyncio is a _brand new_ part of the broader PyO3 ecosystem. Feel free to open any issues for feature requests or bugfixes for this crate.
2121
22-
**If you're a new-comer, the best way to get started is to read through the primer below! For `v0.13` and `v0.14` users I highly recommend reading through the [migration section](#migration-guide) to get a general idea of what's changed in `v0.14` and `v0.15`.**
23-
2422
## Usage
2523

2624
Like PyO3, PyO3 Asyncio supports the following software versions:
2725

2826
- Python 3.7 and up (CPython and PyPy)
29-
- Rust 1.48 and up
27+
- Rust 1.63 and up
3028

31-
## PyO3 Asyncio Primer
29+
## PyO3-async-runtimes Primer
3230

3331
If you are working with a Python library that makes use of async functions or wish to provide
3432
Python bindings for an async Rust library, [`pyo3-async-runtimes`](https://github.com/PyO3/pyo3-async-runtimes)
3533
likely has the tools you need. It provides conversions between async functions in both Python and
3634
Rust and was designed with first-class support for popular Rust runtimes such as
3735
[`tokio`](https://tokio.rs/) and [`async-std`](https://async.rs/). In addition, all async Python
38-
code runs on the default `asyncio` event loop, so `pyo3-asyncio` should work just fine with existing
36+
code runs on the default `asyncio` event loop, so `pyo3-async-runtimes` should work just fine with existing
3937
Python libraries.
4038

41-
In the following sections, we'll give a general overview of `pyo3-asyncio` explaining how to call
39+
In the following sections, we'll give a general overview of `pyo3-async-runtimes` explaining how to call
4240
async Python functions with PyO3, how to call async Rust functions from Python, and how to configure
4341
your codebase to manage the runtimes of both.
4442

@@ -124,7 +122,7 @@ crate-type = ["cdylib"]
124122
```
125123

126124
Make your project depend on `pyo3` with the `extension-module` feature enabled and select your
127-
`pyo3-asyncio` runtime:
125+
`pyo3-async-runtimes` runtime:
128126

129127
For `async-std`:
130128

@@ -282,7 +280,7 @@ let future = rust_sleep();
282280

283281
We can convert this `Future` object into Python to make it `awaitable`. This tells Python that you
284282
can use the `await` keyword with it. In order to do this, we'll call
285-
[`pyo3_async_runtimes::async_std::future_into_py`](https://docs.rs/pyo3-asyncio/latest/pyo3_async_runtimes/async_std/fn.future_into_py.html):
283+
[`pyo3_async_runtimes::async_std::future_into_py`](https://docs.rs/pyo3-async-runtimes/latest/pyo3_async_runtimes/async_std/fn.future_into_py.html):
286284

287285
```rust
288286
use pyo3::prelude::*;
@@ -316,15 +314,15 @@ Python's `asyncio` features, like proper signal handling, require control over t
316314
doesn't always play well with Rust.
317315

318316
Luckily, Rust's event loops are pretty flexible and don't _need_ control over the main thread, so in
319-
`pyo3-asyncio`, we decided the best way to handle Rust/Python interop was to just surrender the main
317+
`pyo3-async-runtimes`, we decided the best way to handle Rust/Python interop was to just surrender the main
320318
thread to Python and run Rust's event loops in the background. Unfortunately, since most event loop
321319
implementations _prefer_ control over the main thread, this can still make some things awkward.
322320

323321
### PyO3 Asyncio Initialization
324322

325323
Because Python needs to control the main thread, we can't use the convenient proc macros from Rust
326324
runtimes to handle the `main` function or `#[test]` functions. Instead, the initialization for PyO3 has to be done from the `main` function and the main
327-
thread must block on [`pyo3_async_runtimes::run_forever`](https://docs.rs/pyo3-asyncio/latest/pyo3_async_runtimes/fn.run_forever.html) or [`pyo3_async_runtimes::async_std::run_until_complete`](https://docs.rs/pyo3-asyncio/latest/pyo3_async_runtimes/async_std/fn.run_until_complete.html).
325+
thread must block on [`pyo3_async_runtimes::async_std::run_until_complete`](https://docs.rs/pyo3-async-runtimes/latest/pyo3_async_runtimes/async_std/fn.run_until_complete.html).
328326

329327
Because we have to block on one of those functions, we can't use [`#[async_std::main]`](https://docs.rs/async-std/latest/async_std/attr.main.html) or [`#[tokio::main]`](https://docs.rs/tokio/1.1.0/tokio/attr.main.html)
330328
since it's not a good idea to make long blocking calls during an async function.
@@ -345,7 +343,7 @@ since it's not a good idea to make long blocking calls during an async function.
345343
> that can avoid this problem, but again that's not something we can use here since we need it to
346344
> block on the _main_ thread.
347345
348-
For this reason, `pyo3-asyncio` provides its own set of proc macros to provide you with this
346+
For this reason, `pyo3-async-runtimes` provides its own set of proc macros to provide you with this
349347
initialization. These macros are intended to mirror the initialization of `async-std` and `tokio`
350348
while also satisfying the Python runtime's needs.
351349
@@ -535,8 +533,8 @@ fn main() -> PyResult<()> {
535533

536534
### Additional Information
537535

538-
- Managing event loop references can be tricky with pyo3-async-runtimes. See [Event Loop References and ContextVars](https://awestlake87.github.io/pyo3-asyncio/master/doc/pyo3_async_runtimes/#event-loop-references-and-contextvars) in the API docs to get a better intuition for how event loop references are managed in this library.
539-
- Testing pyo3-asyncio libraries and applications requires a custom test harness since Python requires control over the main thread. You can find a testing guide in the [API docs for the `testing` module](https://awestlake87.github.io/pyo3-asyncio/master/doc/pyo3_async_runtimes/testing)
536+
- Managing event loop references can be tricky with pyo3-async-runtimes. See [Event Loop References and ContextVars](https://docs.rs/pyo3-async-runtimes/latest/pyo3_async_runtimes/#event-loop-references-and-contextvars) in the API docs to get a better intuition for how event loop references are managed in this library.
537+
- Testing pyo3-async-runtimes libraries and applications requires a custom test harness since Python requires control over the main thread. You can find a testing guide in the [API docs for the `testing` module](https://docs.rs/pyo3-async-runtimes/latest/pyo3_async_runtimes/testing/index.html)
540538

541539
## Migration Guide
542540

@@ -548,7 +546,7 @@ Well, a lot actually. There were some pretty major flaws in the initialization b
548546

549547
To make things a bit easier, I decided to keep most of the old API alongside the new one (with some deprecation warnings to encourage users to move away from it). It should be possible to use the `v0.13` API alongside the newer `v0.14` API, which should allow you to upgrade your application piecemeal rather than all at once.
550548

551-
**Before you get started, I personally recommend taking a look at [Event Loop References and ContextVars](https://awestlake87.github.io/pyo3-asyncio/master/doc/pyo3_async_runtimes/#event-loop-references-and-contextvars) in order to get a better grasp on the motivation behind these changes and the nuance involved in using the new conversions.**
549+
**Before you get started, I personally recommend taking a look at [Event Loop References and ContextVars](https://docs.rs/pyo3-async-runtimes/latest/pyo3_async_runtimes/#event-loop-references-and-contextvars) in order to get a better grasp on the motivation behind these changes and the nuance involved in using the new conversions.**
552550

553551
### 0.14 Highlights
554552

@@ -636,7 +634,7 @@ To make things a bit easier, I decided to keep most of the old API alongside the
636634
```
637635

638636
4. Replace conversions with their newer counterparts.
639-
> You may encounter some issues regarding the usage of `get_running_loop` vs `get_event_loop`. For more details on these newer conversions and how they should be used see [Event Loop References and ContextVars](https://awestlake87.github.io/pyo3-asyncio/master/doc/pyo3_async_runtimes/#event-loop-references-and-contextvars).
637+
> You may encounter some issues regarding the usage of `get_running_loop` vs `get_event_loop`. For more details on these newer conversions and how they should be used see [Event Loop References and ContextVars](https://docs.rs/pyo3-async-runtimes/latest/pyo3_async_runtimes/#event-loop-references-and-contextvars).
640638
- Replace `pyo3_async_runtimes::into_future` with `pyo3_async_runtimes::<runtime>::into_future`
641639
- Replace `pyo3_async_runtimes::<runtime>::into_coroutine` with `pyo3_async_runtimes::<runtime>::future_into_py`
642640
- Replace `pyo3_async_runtimes::get_event_loop` with `pyo3_async_runtimes::<runtime>::get_current_loop`

0 commit comments

Comments
 (0)