qbittorrent-api Python Client

2025.11.1 · active · verified Fri Apr 17

qbittorrent-api is a Python client library for interacting with the qBittorrent v4.1+ Web API. It provides a programmatic interface to manage torrents, retrieve application status, and control various aspects of the qBittorrent client. The library releases frequently, often mirroring updates in qBittorrent server versions or adding new API features, with the current version being 2025.11.1.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a qBittorrent instance using the client library, authenticate, and retrieve basic information like the application version and current transfer speeds. It uses environment variables for sensitive connection details.

import os
from qbittorrentapi import Client, APIError

# Configure connection details using environment variables for security
QBT_HOST = os.environ.get('QBT_HOST', 'localhost')
QBT_PORT = int(os.environ.get('QBT_PORT', '8080'))
QBT_USERNAME = os.environ.get('QBT_USERNAME', 'admin')
QBT_PASSWORD = os.environ.get('QBT_PASSWORD', 'adminadmin') # Change 'adminadmin' if using a custom password

try:
    # Initialize the qBittorrent client
    qbt_client = Client(
        host=QBT_HOST,
        port=QBT_PORT,
        username=QBT_USERNAME,
        password=QBT_PASSWORD,
        verify_data_path=False # Set to True if using HTTPS with a valid certificate
    )

    # Test connection and authentication by getting the application version
    app_version = qbt_client.app.version()
    print(f"Successfully connected to qBittorrent Web UI (v{app_version}) at {QBT_HOST}:{QBT_PORT}")

    # Example: Get the transfer info
    transfer_info = qbt_client.transfer.info()
    print(f"Download speed: {transfer_info.dl_info_speed / 1024:.2f} KB/s, Upload speed: {transfer_info.up_info_speed / 1024:.2f} KB/s")

except APIError as e:
    print(f"qBittorrent API Error: {e}")
    if "failed to login" in str(e).lower():
        print("Please check your username and password.")
except ConnectionError as e:
    print(f"Connection Error: {e}. Is qBittorrent running, Web UI enabled, and host/port correct?")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →