Usage

For each supported BitTorrent client there is a subclass of RPCBase. These behave almost identically, except for the call() method, which takes different arguments depending on the client.

It is recommended to use an asynchronous context manager. call() automatically calls connect() if required and disconnect() is called at the end of the context manager block.

async with aiobtclientrpc.QbittorrentRPC(
    url="http://localhost:8080",
    username="foo",
    password="bar",
) as client:
    print(await client.call("app/version"))

You can also connect() and disconnect() manually. Keep in mind that disconnect() must always be called.

client = aiobtclientrpc.QbittorrentRPC("http://localhost:8080")
try:
    await client.connect()
    print(await client.call("app/version"))
finally:
    await client.disconnect()

client() is a convenience function that takes a client name and instantiates the corresponding class.

async with aiobtclientrpc.client(
    name="qbittorrent",
    url="http://localhost:8080",
) as client:
    print(await client.call("app/version"))

RPCBase instances can be re-used as asynchronous context managers. But this may be very inefficient because of the additional calls to connect() and disconnect().

client = aiobtclientrpc.client("qbittorrent", "http://localhost:8081")
async with client:
    print(client.call("app/version"))
async with client:
    print(client.call("app/buildInfo"))
async with client:
    hashes = [
        "232f5ac38b049470589905bc3a34a9f57f8d3d1d",
        "9dfe40bd5e3dba3ca464e0d94c4c3d4e1869b70e",
    ]
    print(client.call("torrents/info", hashes="|".join(hashes)))

To better understand what’s going on, set the logging level to DEBUG or higher.

import logging
logging.getLogger('aiobtclientrpc').setLevel(logging.DEBUG)