@ctrl/qbittorrent

中文文档
10.1.1发布于 2026/10/23MITTypeScriptES Module构建来源已验证近 30 天下载 8690

TypeScript api wrapper for qbittorrent using ofetch

原始使用文档
文档目录8 节
  1. Install
  2. Use
  3. Authentication
  4. API
  5. Normalized API
  6. See Also
  7. Start a test docker container
  8. Start a test docker container for qBittorrent alpha

qBittorrent npm

TypeScript api wrapper for qBittorrent using ofetch

Install

npm install @ctrl/qbittorrent

Requires Node.js 24 or newer.

Use

import { QBittorrent } from '@ctrl/qbittorrent';

const client = new QBittorrent({
  baseUrl: 'http://localhost:8080/',
  username: 'admin',
  password: 'adminadmin',
});

async function main() {
  const res = await client.getAllData();
  console.log(res);
}

Authentication

The default authentication mode uses qBittorrent's username/password login flow and stores the returned WebUI session cookie.

qBittorrent v5.2.0 and WebAPI v2.14.1 added API key authentication. Pass an API key to use stateless bearer authentication instead of cookie login:

const client = new QBittorrent({
  baseUrl: 'http://localhost:8080/',
  apiKey: 'qbt_0000000000000000000000000000',
});

API keys can be created from the qBittorrent WebUI. They can also be rotated or deleted through the WebAPI:

const passwordClient = new QBittorrent({
  baseUrl: 'http://localhost:8080/',
  username: 'admin',
  password: 'adminadmin',
});

const apiKey = await passwordClient.rotateApiKey();
await passwordClient.deleteApiKey();

API

Docs: https://qbittorrent.ep.workers.dev
qBittorrent API Docs: https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-5.0)
qBittorrent API Key Docs: https://github.com/qbittorrent/qBittorrent/wiki/API-Key-Authentication-%28%E2%89%A5v5.2.0%29

Things that work differently from the other clients:

  • label is the qBittorrent category
  • qBittorrent ignores unknown hashes, pause, resume, queue and remove don't throw for them
  • queueUp/queueDown need torrent queueing enabled, qBittorrent responds with a 409 otherwise. queuePosition is 0 when queueing is disabled or the torrent is seeding
  • pauseTorrent/resumeTorrent use /torrents/stop and /torrents/start on qBittorrent 5 and /torrents/pause and /torrents/resume on 4.x

Normalized API

These functions are normalized through @ctrl/shared-torrent, which makes it easier to support multiple torrent clients. See below for alternative supported torrent clients.

getAllData

Returns all torrent data and an array of label objects. Data has been normalized and does not match the output of native listTorrents().

const data = await client.getAllData();
console.log(data.torrents);
getTorrent

Returns one torrent data from torrent hash

const data = await client.getTorrent('torrent-hash');
console.log(data);
pauseTorrent and resumeTorrent

Pause or resume one or more torrents

await client.pauseTorrent('torrent-hash');
await client.resumeTorrent(['torrent-hash', 'other-torrent-hash']);
removeTorrent

Remove one or more torrents. Does not remove data on disk by default.

// does not remove data on disk
await client.removeTorrent('torrent-hash', false);

// remove data on disk
await client.removeTorrent(['torrent-hash', 'other-torrent-hash'], true);
queueUp and queueDown

Move a torrent up or down the queue

await client.queueUp('torrent-hash');
await client.queueDown('torrent-hash');
addTorrent

Add a torrent from a magnet link or torrent file, has client specific options. Also see normalizedAddTorrent

import { readFileSync } from 'node:fs';

const result = await client.addTorrent(new Uint8Array(readFileSync('./linux.torrent')));
console.log(result);
normalizedAddTorrent

Add a torrent and return normalized torrent data, can start a torrent paused and add label

const result = await client.normalizedAddTorrent('magnet:?xt=urn:btih:...', {
  startPaused: false,
  label: 'linux',
});
console.log(result);
Errors

Failed requests throw a TorrentClientError from @ctrl/shared-torrent with a code of torrent_not_found, unauthorized, request_failed or client_error, the http status when there is one and the original error as the cause.

import { TorrentClientError } from '@ctrl/qbittorrent';

try {
  await client.getTorrent('torrent-hash');
} catch (error) {
  if (error instanceof TorrentClientError && error.code === 'torrent_not_found') {
    // not in the client
  }
}
export and create from state

If you're shutting down the server often (serverless?) you can export the state

const state = client.exportState();
const restored = QBittorrent.createFromState(config, state);

See Also

All of the following npm modules provide the same normalized functions along with supporting the unique apis for each client.

Usenet clients with the same normalized approach:

Start a test docker container

docker run -d \
  --name=qbittorrent \
  -e PUID=1000 \
  -e PGID=1000 \
  -e TZ=Etc/UTC \
  -e WEBUI_PORT=8080 \
  -p 8080:8080 \
  -p 6881:6881 \
  -p 6881:6881/udp \
  --restart unless-stopped \
  lscr.io/linuxserver/qbittorrent:latest

Start a test docker container for qBittorrent alpha

Use the official alpha image when testing against the newest WebAPI changes. The linuxserver latest image can lag behind the latest qBittorrent release.

mkdir -p /tmp/qbittorrent-alpha/config /tmp/qbittorrent-alpha/downloads

docker run -d \
  --name=qbittorrent-alpha \
  -e QBT_LEGAL_NOTICE=confirm \
  -e QBT_WEBUI_PORT=8080 \
  -e QBT_TORRENTING_PORT=6881 \
  -e PUID=1000 \
  -e PGID=1000 \
  -p 8080:8080 \
  -p 6881:6881 \
  -p 6881:6881/udp \
  -v /tmp/qbittorrent-alpha/config:/config \
  -v /tmp/qbittorrent-alpha/downloads:/downloads \
  qbittorrentofficial/qbittorrent-nox:alpha

The alpha image prints a temporary WebUI password in docker logs qbittorrent-alpha. Set the WebUI password to adminadmin before running the integration tests.

版本与发布记录

@ctrl/qbittorrent 共发布 77 个版本,首次发布于 2019/04/15;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
10.1.1latest2026/10/2319 天前
10.1.02026/10/2121 天前
10.0.12026/10/051 个月前
10.0.02026/10/051 个月前
9.16.12026/10/051 个月前
9.16.02026/09/072 个月前

关于 @ctrl/qbittorrent 的常见问题

@ctrl/qbittorrent 是什么?

TypeScript api wrapper for qbittorrent using ofetch

如何安装 @ctrl/qbittorrent?

在项目目录运行 npm install @ctrl/qbittorrent,或使用 pnpm add / yarn add / bun add。

@ctrl/qbittorrent 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ctrl/qbittorrent 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ctrl/qbittorrent 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ctrl/qbittorrent 可以商用吗?

@ctrl/qbittorrent 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ctrl/qbittorrent 的下载量有多少?

根据 npm 官方下载统计,@ctrl/qbittorrent 在 2026/10/11 – 2026/11/09 这 30 天内被下载 8,690 次,日均约 290 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ctrl/qbittorrent 还在维护吗?

最新版本 10.1.1 发布于 2026/10/23(19 天前);至今共发布 77 个版本,其中过去 12 个月发布了 14 个;首次发布于 2019/04/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。