Files
Server-scripts/torrent_api
Lucas Vivo 1992a3dcd0
Torrent API CI / build (push) Successful in 36s
Torrent API CI / test (push) Successful in 12s
Torrent API CI / lint (push) Successful in 7s
Torrent API CI / install (mediahost) (push) Successful in 2s
Torrent API CI / install (vivohost) (push) Successful in 2s
Torrent API CI / install (serverhost) (push) Successful in 3s
Torrent API CI / install (quiethost) (push) Successful in 8s
feat(torrent_api): load env file in current dir and execution dir
2026-11-23 12:28:30 +01:00
..
2026-11-23 11:36:36 +01:00
2026-11-22 16:16:32 +01:00

qBittorrent helpers

Install the package and its dependencies in your virtual environment:

uv sync --project .

Use the Qbittorrent class:

from torrent_api import Qbittorrent

instance = Qbittorrent("localhost:8080", "example", "your-api-key")

# Either limit may be omitted. Seed time is measured in seconds.
removed = instance.remove_torrents(seed_time=7 * 86400, ratio=2.0)
instance.show_and_copy_torrent_contents("exact torrent name or hash")
instance.show_torrents(id=True)  # Include torrent hashes in the listing.

remove_torrents removes torrents exceeding either limit and deletes their downloaded files by default. Pass delete_files=False to retain the files. It returns the matching torrent records after a successful deletion. show_and_copy_torrent_contents prints files whose progress meets the threshold (default: 1.0). Pass copy_to with a destination directory to also copy files that are 100% complete there, preserving their torrent-relative paths. Names must match exactly; use the hash if multiple torrents have the same name.

CLI and debugging

Set QBITTORRENT_PRIVATE_API_KEY and QBITTORRENT_PUBLIC_API_KEY in the environment, then run torrent-api or python -m torrent_api.cli. To load them from the local .env file in a POSIX shell, run:

set -a
. ./.env
set +a
torrent-api

The CLI uses the existing private and public instance addresses and supports --log-level (TRACE, DEBUG, INFO, WARNING, ERROR, or CRITICAL; default INFO), --sort, --asc, --force-start, --show-id, --id (torrent name or hash for contents), --progress-threshold, and --copy-to (a destination directory for completed files). Add --dry-run to log planned copies without writing files. The VS Code launch configuration uses the workspace main.py and loads .env automatically. Keep this file private; it is ignored by Git.

Tests

Run python run_tests.py to discover and run all unittests. In VS Code, use the Torrent API: Run tests launch configuration or unittest discovery when this directory is opened as the workspace and the environment with the installed package is selected.

Lint and build

Install the optional tools and build a single-file executable:

uv sync --project . --extra build --extra lint
uv run --project . ruff check src tests main.py run_tests.py
uv run --project . python -m PyInstaller --noconfirm torrent_api.spec
./dist/torrent_api --help

The VS Code build task runs the same PyInstaller command using .venv. Builds are specific to the OS and architecture on which they run. The Gitea workflow tests and lints on pushes and pull requests; on a successful push to main, it builds the executable and installs it to ~/tools/torrent_api on the same self-hosted runners as ffmpeg_handling.