Python wrapper for qBittorrent Web API

Published on Aug. 22, 2023, 12:13 p.m.

Python wrapper for qBittorrent Web API (for versions above 4.1, for version below and above v3.1.x .

Installation

$ pip install python-qbittorrent

QBittorent webUI must be enabled.

Quick usage guide

from qbittorrent import Client

qb = Client('http://127.0.0.1:8080/')

qb.login('admin', 'your-secret-password')
# not required when 'Bypass from localhost' setting is active.
# defaults to admin:admin.
# to use defaults, just do qb.login()

torrents = qb.torrents()

for torrent in torrents:
    print torrent['name']

If you have enabled SSL you probably want to disable SSL verification.This can be done by passing verify=False.

from qbittorrent import Client

qb = Client('https://127.0.0.1:8080/', verify=False)

Get all active torrents:

qb.torrents()

Filter torrents:

qb.torrents(filter='downloading', category='my category')
# This will return all torrents which are currently
# downloading and are labeled as ``my category``.

qb.torrents(filter='paused', sort='ratio')
# This will return all paused torrents sorted by their Leech:Seed ratio.

Download torrents by link:

magnet_link = "magnet:?xt=urn:btih:e334ab9ddd91c10938a7....."
qb.download_from_link(magnet_link)

# No matter the link is correct or not,
# method will always return empty JSON object.

Download multipe torrents by list of links:

link_list = [link1, link2, link3]
qb.download_from_link(link_list)

Downloading torrents by file:

torrent_file = open('my-torrent-file.torrent', 'rb')
qb.download_from_file(torrent_file)

Downloading multiple torrents by using files:

torrent_file_list = [open('1.torrent', 'rb'), open('2.torrent', 'rb')]
qb.download_from_file(torrent_file_list)

Specifing save path for downloads:

dl_path = '/home/user/Downloads/special-dir/'
qb.download_from_file(myfile, savepath=dl_path)

# same for links.
qb.download_from_link(my_magnet_uri, savepath=dl_path)

Applying labels to downloads:

qb.download_from_file(myfile, label='secret-files ;) ')

# same for links.
qb.download_from_link(my_magnet_uri, category='anime')

Pausing/ Resuming all torrents:

qb.pause_all()
qb.resume_all()

Pausing/ Resuming a speicific torrent:

info_hash = 'e334ab9ddd....infohash....5d7fff526cb4'
qb.pause(info_hash)
qb.resume(info_hash)

Pausing/ Resuming multiple torrents:

info_hash_list = ['e334ab9ddd9......infohash......fff526cb4',
                  'c9dc36f46d9......infohash......90ebebc46',
                  '4c859243615......infohash......8b1f20108']

qb.pause_multiple(info_hash_list)
qb.resume_multipe(info_hash_list)