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()) and/or populate common_rpc_error_map.

All asynchronous methods may raise ConnectionError.

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:

It also converts any common errors by passing common_rpc_error_map to aiobtclientrpc.RPCError.translate().

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

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

Add torrent to client

Parameters:
  • torrent – Path or URL to torrent file, magnet: URI or infohash

  • 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:

Infohash of the added torrent

Raises:

errors.AddTorrentError – if adding fails

async start(infohash)[source]

Start torrent

Parameters:

infohashes – Infohash of the torrent to start

Returns:

None when the torrent was started

Raises:

errors.StartTorrentError – if starting the torrent failed

async stop(infohash)[source]

Stop torrent

Parameters:

infohash – Infohash of the torrent to stop

Returns:

None when the torrent was stopped

Raises:

errors.StopTorrentError – if stopping the torrent failed

async verify(infohash)[source]

Initiate hash check of a torrent’s files

See also verify_wait().

Parameters:

infohash – Infohash of the torrent to check

Returns:

None when the verification was initiated

Raises:

errors.VerifyTorrentError – if initiating the verification failed

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. seconds_min is used until progress gets close to 100.0. Then, seconds_min gradually moves to seconds_max.

    This allows to spread out update requests until the end, where you want to check progress more frequently to know when the verification is finished.

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