Skip to main content

Python torrent download manager wrapping aria2c via JSON-RPC

Project description

boltdown

A Python library for managing torrent downloads, powered by aria2c.

PyPI Python License

boltdown wraps aria2c via JSON-RPC to provide a clean, dependency-free Python API for torrent and magnet link downloads. No Django. No heavy HTTP frameworks. Just Python and aria2c.


Features

  • Zero external HTTP dependencies — uses stdlib urllib only
  • Magnet links — full validation, hash extraction, DHT support
  • .torrent files — optional bencodepy extra
  • SQLite state — stdlib sqlite3, no ORM required
  • Background monitoring — auto-syncs progress from aria2c
  • Typed and documented — full type hints, Python 3.9+
  • PyPI-readypip install boltdown

Quick Start

1. Install

pip install boltdown
# For .torrent file support:
pip install boltdown[torrent]

2. Download a Magnet Link

from boltdown import BoltdownClient

with BoltdownClient(download_dir="./downloads") as client:
    task = client.add_magnet("magnet:?xt=urn:btih:...")
    print(task)
    # <DownloadTask id=1 name='My File' status='downloading' progress=0.0%>

3. Download a .torrent File

from boltdown import BoltdownClient

with BoltdownClient(download_dir="./downloads") as client:
    task = client.add_torrent_file("/path/to/file.torrent")

4. Manage Downloads

client = BoltdownClient(download_dir="./downloads")

# List all tasks
tasks = client.list_tasks()
for t in tasks:
    print(t.to_dict())

# Pause and resume
client.pause(task.id)
client.resume(task.id)

# Remove (and optionally delete files from disk)
client.remove(task.id, delete_files=True)

# Always shut down cleanly
client.shutdown()

Configuration

client = BoltdownClient(
    download_dir     = "./downloads",   # Directory where files are saved
    db_path          = "./boltdown.db", # SQLite database (default: inside download_dir)
    aria2c_path      = None,            # Auto-detect, or pass "/usr/bin/aria2c"
    aria2_secret     = "mysecret",      # aria2 RPC token (optional but recommended)
    rpc_port         = 6800,            # aria2 RPC listen port
    monitor_interval = 2.0,             # Seconds between status sync polls
)

Prerequisites


API Reference

BoltdownClient

Method Returns Description
add_magnet(magnet_link) DownloadTask Add a magnet URI and start downloading
add_torrent_file(path) DownloadTask Add a .torrent file and start downloading
pause(task_id) bool Pause a download
resume(task_id) bool Resume a paused download
remove(task_id, delete_files=False) None Remove a download, optionally deleting files
get_task(task_id) DownloadTask Retrieve a single task by ID
list_tasks() list[DownloadTask] List all tasks, ordered by ID
shutdown() None Stop monitoring and terminate aria2c

DownloadTask

Field Type Description
id int Auto-assigned integer ID
info_hash str 40-character hex SHA-1 info hash
name str Display name
status str One of: queued, downloading, paused, completed, error
progress float Completion percentage (0.0 to 100.0)
download_speed int Current download speed in bytes per second
upload_speed int Current upload speed in bytes per second
total_size int Total file size in bytes
eta int Estimated seconds remaining
save_path str Directory where files are saved
added_at datetime UTC datetime when the task was created
completed_at datetime or None UTC datetime when the download finished
error_message str or None Description of the last error, if any

Exceptions

Exception When raised
BoltdownError Base class for all library errors
Aria2NotFoundError The aria2c binary could not be located
Aria2RpcError aria2 returned an error or refused the RPC call
InvalidMagnetError The supplied string is not a valid magnet link
TaskNotFoundError No task exists with the given ID
StorageError A database or persistence error occurred

Architecture

boltdown/
    client.py      BoltdownClient — main entry point
    aria2.py       aria2c process management and JSON-RPC client (stdlib urllib)
    storage.py     SQLite state persistence (stdlib sqlite3)
    models.py      DownloadTask dataclass
    magnet.py      Magnet URI parsing utilities
    exceptions.py  Custom exception hierarchy
    _version.py    Version string

Running Tests

cd boltdown-lib
pip install -e ".[dev]"
pytest

Publishing to PyPI

pip install build twine
python -m build
twine upload dist/*

To test on TestPyPI first:

twine upload --repository testpypi dist/*
pip install --index-url https://test.pypi.org/simple/ boltdown

License

MIT — see LICENSE.


By Mohammad Ameen Barech

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

boltdown-0.1.0.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

boltdown-0.1.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file boltdown-0.1.0.tar.gz.

File metadata

  • Download URL: boltdown-0.1.0.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for boltdown-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1a13c9fae5b479d4342f76c45a92552eb93bf177eba1469bad7cf3d94fe4845d
MD5 50c236f58bd84249b0de94a46f78c15a
BLAKE2b-256 b5240876439d6e14c7fba8618d60d8cd155e1f320f96b8314a626188b417910e

See more details on using hashes here.

File details

Details for the file boltdown-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: boltdown-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for boltdown-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a1cb906f62ed41a05dfa0b90512885221b25b2ed0d4f2596daf5e48cae52578
MD5 2b0382dd39cec8d3538ae7105e401e8f
BLAKE2b-256 2cb538f91d72fde4bac2f583937aaf418c936849b270d093efce1137cb2586ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page