diff --git a/datasketch/aio/storage.py b/datasketch/aio/storage.py index 16b5dc56..3b42da72 100644 --- a/datasketch/aio/storage.py +++ b/datasketch/aio/storage.py @@ -10,7 +10,14 @@ from abc import ABCMeta from itertools import chain -from datasketch.storage import OrderedStorage, RedisStorage, Storage, UnorderedStorage, _random_name +from datasketch.storage import OrderedStorage, Storage, UnorderedStorage, _random_name + +# RedisStorage is only available when redis package is installed (optional dependency) +# Import it conditionally to avoid ImportError when redis is not installed +try: + from datasketch.storage import RedisStorage +except ImportError: + RedisStorage = None ABC = ABCMeta("ABC", (object,), {}) @@ -301,7 +308,9 @@ async def remove_val(self, key, val, **kwargs): await self._collection.find_one_and_delete({"key": key, "vals": val}) -if redis is not None: +# Redis-based async storage classes are only defined when both redis package +# and RedisStorage are available (optional dependencies) +if redis is not None and RedisStorage is not None: class AsyncRedisBuffer(redis.client.Pipeline): def __init__(self, connection_pool, response_callbacks, transaction, buffer_size, shard_hint=None): diff --git a/docs/documentation.rst b/docs/documentation.rst index 202b4f01..869c11e6 100644 --- a/docs/documentation.rst +++ b/docs/documentation.rst @@ -38,7 +38,7 @@ MinHash LSH Asynchronous MinHash LSH ------------------------ -.. autoclass:: datasketch.experimental.aio.lsh.AsyncMinHashLSH +.. autoclass:: datasketch.aio.AsyncMinHashLSH :members: :special-members: diff --git a/docs/lsh.rst b/docs/lsh.rst index 7685213a..4fc827a5 100644 --- a/docs/lsh.rst +++ b/docs/lsh.rst @@ -237,8 +237,7 @@ Asynchronous MinHash LSH at scale --------------------------------- .. note:: - The module supports Python version >=3.6, and is currently experimental. - So the interface may change slightly in the future. + The module supports Python version >=3.6. This module may be useful if you want to process millions of text documents in streaming/batch mode using asynchronous RESTful API (for example, aiohttp) @@ -256,7 +255,7 @@ The Asynchronous MongoDB storage option can be configured using: .. code:: python - from datasketch.experimental.aio.lsh import AsyncMinHashLSH + from datasketch.aio import AsyncMinHashLSH from datasketch import MinHash _storage = {'type': 'aiomongo', 'mongo': {'host': 'localhost', 'port': 27017, 'db': 'lsh_test'}} @@ -277,7 +276,7 @@ The Asynchronous MongoDB storage option can be configured using: .. code:: python - from datasketch.experimental.aio.lsh import AsyncMinHashLSH + from datasketch.aio import AsyncMinHashLSH from datasketch import MinHash _storage = {'type': 'aiomongo', 'mongo': {'host': 'localhost', 'port': 27017, 'db': 'lsh_test'}} @@ -329,7 +328,7 @@ To create index for a large number of MinHashes using asynchronous MinHash LSH. .. code:: python - from datasketch.experimental.aio.lsh import AsyncMinHashLSH + from datasketch.aio import AsyncMinHashLSH from datasketch import MinHash def chunk(it, size): @@ -355,7 +354,7 @@ To bulk remove keys from LSH index using asynchronous MinHash LSH. .. code:: python - from datasketch.experimental.aio.lsh import AsyncMinHashLSH + from datasketch.aio import AsyncMinHashLSH from datasketch import MinHash def chunk(it, size):