From 0326819a5fa65543a73c4987fa98762321d66f2f Mon Sep 17 00:00:00 2001 From: Voronin Sergei Date: Sun, 31 May 2026 16:48:16 +1200 Subject: [PATCH] Add async optional dependency extra --- README.md | 9 +++++---- docs/english/concepts/async.md | 4 ++-- docs/japanese/concepts/async.md | 4 ++-- pyproject.toml | 3 ++- requirements/async.txt | 2 ++ slack_bolt/async_app.py | 9 +++++---- 6 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 requirements/async.txt diff --git a/README.md b/README.md index 39747df40..23475aaee 100644 --- a/README.md +++ b/README.md @@ -150,18 +150,19 @@ Most of the app's functionality will be inside listener functions (the `fn` para ## Creating an async app -If you'd prefer to build your app with [asyncio](https://docs.python.org/3/library/asyncio.html), you can import the [AIOHTTP](https://docs.aiohttp.org/en/stable/) library and call the `AsyncApp` constructor. Within async apps, you can use the async/await pattern. +If you'd prefer to build your app with [asyncio](https://docs.python.org/3/library/asyncio.html), you can install the async extra to include [AIOHTTP](https://docs.aiohttp.org/en/stable/) and call the `AsyncApp` constructor. Within async apps, you can use the async/await pattern. ```bash -# Python 3.7+ required +# Python 3.9+ required for the async extra python -m venv .venv source .venv/bin/activate pip install -U pip -# aiohttp is required -pip install slack_bolt aiohttp +pip install "slack_bolt[async]" ``` +If you're using Python 3.7 or 3.8, install an `aiohttp` version compatible with your Python runtime separately. + In async apps, all middleware/listeners must be async functions. When calling utility methods (like `ack` and `say`) within these functions, it's required to use the `await` keyword. ```python diff --git a/docs/english/concepts/async.md b/docs/english/concepts/async.md index e6ae28fc6..991365244 100644 --- a/docs/english/concepts/async.md +++ b/docs/english/concepts/async.md @@ -1,11 +1,11 @@ # Using async (asyncio) -To use the async version of Bolt, you can import and initialize an `AsyncApp` instance (rather than `App`). `AsyncApp` relies on [AIOHTTP](https://docs.aiohttp.org) to make API requests, which means you'll need to install `aiohttp` (by adding to `requirements.txt` or running `pip install aiohttp`). +To use the async version of Bolt, you can import and initialize an `AsyncApp` instance (rather than `App`). `AsyncApp` relies on [AIOHTTP](https://docs.aiohttp.org) to make API requests. On Python 3.9 and newer, install the async extra by running `pip install "slack_bolt[async]"`. If you're using Python 3.7 or 3.8, install an `aiohttp` version compatible with your Python runtime separately. Sample async projects can be found within the repository's [examples](https://github.com/slackapi/bolt-python/tree/main/examples) folder. ```python -# Requirement: install aiohttp +# Requirement: pip install "slack_bolt[async]" from slack_bolt.async_app import AsyncApp app = AsyncApp() diff --git a/docs/japanese/concepts/async.md b/docs/japanese/concepts/async.md index 6687dcff5..10b5223ca 100644 --- a/docs/japanese/concepts/async.md +++ b/docs/japanese/concepts/async.md @@ -1,11 +1,11 @@ # Async(asyncio)の使用 -非同期バージョンの Bolt を使用する場合は、`App` の代わりに `AsyncApp` インスタンスをインポートして初期化します。`AsyncApp` では [AIOHTTP](https://docs.aiohttp.org/) を使って API リクエストを行うため、`aiohttp` をインストールする必要があります(`requirements.txt` に追記するか、`pip install aiohttp` を実行します)。 +非同期バージョンの Bolt を使用する場合は、`App` の代わりに `AsyncApp` インスタンスをインポートして初期化します。`AsyncApp` では [AIOHTTP](https://docs.aiohttp.org/) を使って API リクエストを行います。Python 3.9 以降では、`pip install "slack_bolt[async]"` を実行して async extra をインストールしてください。Python 3.7 または 3.8 を使用している場合は、その Python ランタイムと互換性のある `aiohttp` のバージョンを別途インストールしてください。 非同期バージョンのプロジェクトのサンプルは、リポジトリの [`examples` フォルダ](https://github.com/slackapi/bolt-python/tree/main/examples)にあります。 ```python -# aiohttp のインストールが必要です +# 必要条件: pip install "slack_bolt[async]" from slack_bolt.async_app import AsyncApp app = AsyncApp() diff --git a/pyproject.toml b/pyproject.toml index ac197c4f6..018fa561b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "slack_bolt" -dynamic = ["version", "readme", "authors"] +dynamic = ["version", "readme", "authors", "optional-dependencies"] description = "The Bolt Framework for Python" license = { text = "MIT" } classifiers = [ @@ -34,6 +34,7 @@ include = ["slack_bolt*"] [tool.setuptools.dynamic] version = { attr = "slack_bolt.version.__version__" } readme = { file = ["README.md"], content-type = "text/markdown" } +optional-dependencies.async = { file = ["requirements/async.txt"] } [tool.distutils.bdist_wheel] universal = true diff --git a/requirements/async.txt b/requirements/async.txt new file mode 100644 index 000000000..dcb5597c0 --- /dev/null +++ b/requirements/async.txt @@ -0,0 +1,2 @@ +# pip install -r requirements/async.txt +aiohttp>=3,<4; python_version >= "3.9" diff --git a/slack_bolt/async_app.py b/slack_bolt/async_app.py index f95d952aa..7dd625a7a 100644 --- a/slack_bolt/async_app.py +++ b/slack_bolt/async_app.py @@ -2,18 +2,19 @@ ### Creating an async app -If you'd prefer to build your app with [asyncio](https://docs.python.org/3/library/asyncio.html), you can import the [AIOHTTP](https://docs.aiohttp.org/en/stable/) library and call the `AsyncApp` constructor. Within async apps, you can use the async/await pattern. +If you'd prefer to build your app with [asyncio](https://docs.python.org/3/library/asyncio.html), you can install the async extra to include [AIOHTTP](https://docs.aiohttp.org/en/stable/) and call the `AsyncApp` constructor. Within async apps, you can use the async/await pattern. ```bash -# Python 3.7+ required +# Python 3.9+ required for the async extra python -m venv .venv source .venv/bin/activate pip install -U pip -# aiohttp is required -pip install slack_bolt aiohttp +pip install "slack_bolt[async]" ``` +If you're using Python 3.7 or 3.8, install an `aiohttp` version compatible with your Python runtime separately. + In async apps, all middleware/listeners must be async functions. When calling utility methods (like `ack` and `say`) within these functions, it's required to use the `await` keyword. ```python