aiobtclientapi.clients

Clients

Classes

class aiobtclientapi.clients.APIBase(*args, **kwargs)[source]

Bases: ABC

Base class for all BitTorrent client APIs

Subclasses are expected to also inherit from a aiobtclientrpc.RPCBase subclass.

call(), connect() and disconnect() catch most low-level exceptions and translate them into ConnectionError.

Subclasses must catch aiobtclientrpc.RPCError when making RPC calls (see aiobtclientrpc.RPCError.translate()) or populate common_rpc_error_map.

create_background_task(coro, name=None, done_callback=None, detach=False)[source]

Run coroutine in background

Parameters:
  • coro – Coroutine or any other argument for asyncio.create_task()

  • name – Identifier to help with debugging

  • done_callback – Synchronous callable that is called with the return value of coro

  • detach

    Whether to always wait for coro to return

    If this is set to a truthy value, coro is cancelled by wait_for_background_tasks() and CancelledError is ignored.

    If this is set to a falsy value, wait_for_background_tasks() blocks until coro returns.

Returns:

asyncio.Task instance

async wait_for_background_tasks()[source]

Wait for all tasks created by create_background_task()

Detached tasks are cancelled first.

Exceptions from tasks are raised here, except for asyncio.CancelledError from a detached task.

monitor_interval = 0.1

Seconds between requests when waiting for an RPC call to take effect

common_rpc_error_map = {}

Mapping of regular expressions to exceptions for all call() calls

See aiobtclientrpc.RPCError.translate().

async call(*args, **kwargs)[source]

Wrapper around aiobtclientrpc.RPCBase.call() that handles exceptions

This is a thin wrapper that translates the following exceptions into ConnectionError:

async connect(*args, **kwargs)[source]

Wrapper around aiobtclientrpc.RPCBase.connect() that handles exceptions

See call().

async disconnect(*args, **kwargs)[source]

Wrapper around aiobtclientrpc.RPCBase.disconnect() that handles exceptions

See call().

async get_infohashes()[source]

Return sequence of all known infohashes

Raises:

ConnectionError – if the connection can’t be established

async add(*torrents, location=None, stopped=False, verify=True)[source]

Add torrents to client

Parameters:
  • torrents – Paths or URLs to torrent files, magnet: URIs or infohashes

  • location (str) –

    Download directory or None to use the default

    This should be an absolute path. If it isn’t, it is made absolute based on the current working directory, which may be surprising or even non-sensical if the client is running in a different environment.

  • stopped (bool) – Whether the torrent is active right away

  • verify (bool) – Whether any existing files from the torrent are hashed by the client to make sure they are not corrupt

Returns:

Response instance with these custom attributes:

added

Infohashes of successfully added torrents

already_added

Infohashes of torrents that were already added

async start(*infohashes)[source]

Start torrent

Parameters:

infohashes – Infohashes of the torrents to start

Returns:

Response instance with these custom attributes:

started

Infohashes of successfully started torrents

already_started

Infohashes of torrents that were already started

async stop(*infohashes)[source]

Stop torrent

Parameters:

infohashes – Infohash of the torrents to stop

Returns:

Response instance with these custom attributes:

stopped

Infohashes of successfully stopped torrents

already_stopped

Infohashes of torrents that were already stopped

async verify(*infohashes)[source]

Initiate hash check of torrent files

Parameters:

infohashes – Infohashes of the torrents to verify

Returns:

Response instance with these custom attributes:

verifying

Infohashes of torrents that are now being verified

already_verifying

Infohashes of torrents that are already being verified

async verify_wait(*infohashes, interval=(0.3, 3))[source]

Asynchronous generator that yields (infohash, progress) tuples

progress is either a number from 0.0 to 100.0 or Error or Warning.

Every infohash is yielded at least once.

Parameters:
  • infohashes – Infohashes of the torrents

  • interval

    Delay between progress updates

    seconds

    Always use the same delay.

    (seconds_min, seconds_max)

    Dynamically change the delay based on how much time is left.

class aiobtclientapi.clients.DelugeAPI(*args, **kwargs)[source]

Bases: APIBase, DelugeRPC

Deluge API

common_rpc_error_map = {"^'?(([0-9a-fA-F]{40}))'?$": (<class 'aiobtclientapi.errors.NoSuchTorrentError'>, '\\1')}

Mapping of regular expressions to exceptions for all call() calls

See aiobtclientrpc.RPCError.translate().

class aiobtclientapi.clients.QbittorrentAPI(*args, **kwargs)[source]

Bases: APIBase, QbittorrentRPC

qBittorrent API

class aiobtclientapi.clients.RtorrentAPI(*args, **kwargs)[source]

Bases: APIBase, RtorrentRPC

rTorrent API

class aiobtclientapi.clients.TransmissionAPI(*args, **kwargs)[source]

Bases: APIBase, TransmissionRPC

Transmission daemon API