Add support for Trio via AnyIO (#3372)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
Thomas Grainger
2021-10-06 16:32:11 +01:00
committed by GitHub
parent 4d26fa5c54
commit 11d0a08acd
15 changed files with 49 additions and 167 deletions

View File

@@ -7,15 +7,6 @@ To do this, use `yield` instead of `return`, and write the extra steps after.
!!! tip
Make sure to use `yield` one single time.
!!! info
For this to work, you need to use **Python 3.7** or above, or in **Python 3.6**, install the "backports":
```
pip install async-exit-stack async-generator
```
This installs <a href="https://github.com/sorcio/async_exit_stack" class="external-link" target="_blank">async-exit-stack</a> and <a href="https://github.com/python-trio/async_generator" class="external-link" target="_blank">async-generator</a>.
!!! note "Technical Details"
Any function that is valid to use with:

View File

@@ -441,17 +441,6 @@ You can find an example of Alembic in a FastAPI project in the templates from [P
### Create a dependency
!!! info
For this to work, you need to use **Python 3.7** or above, or in **Python 3.6**, install the "backports":
```console
$ pip install async-exit-stack async-generator
```
This installs <a href="https://github.com/sorcio/async_exit_stack" class="external-link" target="_blank">async-exit-stack</a> and <a href="https://github.com/python-trio/async_generator" class="external-link" target="_blank">async-generator</a>.
You can also use the alternative method with a "middleware" explained at the end.
Now use the `SessionLocal` class we created in the `sql_app/databases.py` file to create a dependency.
We need to have an independent database session/connection (`SessionLocal`) per request, use the same session through all the request and then close it after the request is finished.

View File

@@ -2,20 +2,6 @@
You can serve static files automatically from a directory using `StaticFiles`.
## Install `aiofiles`
First you need to install `aiofiles`:
<div class="termy">
```console
$ pip install aiofiles
---> 100%
```
</div>
## Use `StaticFiles`
* Import `StaticFiles`.