Skip to content

Asynchronous Client

Bases: Py1337x

An experimental asynchronous version of the Py1337x class, which calls the original synchronous methods in a worker thread.

This client mirrors the functionality of the synchronous Py1337x client but provides an async/await interface. All methods, parameters, and return models are identical to the synchronous version.

Example
import asyncio

from py1337x import AsyncPy1337x

async def main():
    torrents = AsyncPy1337x()
    vlc_media = await torrents.search('vlc media player')
    print(vlc_media)

asyncio.run(main())
Source code in py1337x/py1337x.py
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
class AsyncPy1337x(Py1337x):
    """
    An experimental asynchronous version of the Py1337x class, which calls the
    original synchronous methods in a worker thread.

    This client mirrors the functionality of the synchronous `Py1337x` client but provides an `async/await` interface.
    All methods, parameters, and return models are identical to the synchronous version.

    Example:
        ```python
        import asyncio

        from py1337x import AsyncPy1337x

        async def main():
            torrents = AsyncPy1337x()
            vlc_media = await torrents.search('vlc media player')
            print(vlc_media)

        asyncio.run(main())
        ```
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def __getattribute__(self, name):
        # Get the attribute from the parent class
        attr = super().__getattribute__(name)

        if callable(attr):
            # If the attribute is callable, return an asyncified version of it
            return asyncify(attr)

        # Otherwise, return the attribute as is
        return attr