Registry / devops / libtorrent

libtorrent

JSON →
library2.0.11pypypi✓ verified 84d ago

Python bindings for libtorrent-rasterbar, a C++ BitTorrent library. Version 2.0.11 is the current release, with a slow cadence tracking the C++ library.

pip install libtorrent
INSTALL
IMPORT
SIG · LIBTORRENT
L
libtorrent
devopspythonv2.0.11
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lt
import libtorrent as lt
import libtorrent
The correct alias is 'lt' to avoid confusion with the standard library? Actually 'import libtorrent as lt' works; the wrong import is to not alias and then use 'libtorrent.*' which is allowed but not idiomatic.
lt.add_torrent_params
import libtorrent as lt; p = lt.add_torrent_params()
from libtorrent import add_torrent_params
Direct import of submodules is not possible; use module prefix. Also note that in libtorrent 2.0, 'add_torrent_params' renamed some fields like 'save_path' -> 'save_path' unchanged.

Basic session creation and magnet download.

import libtorrent as lt import time ses = lt.session() ses.listen_on(6881, 6891) params = lt.add_torrent_params() params.save_path = '/tmp/downloads' params.url = 'magnet:?xt=urn:btih:...' h = ses.add_torrent(params) while not h.is_seed(): s = h.status() print(f'Progress: {s.progress*100:.2f}%') time.sleep(1) print('Download complete')
Debug
Known issues
deprecatedIn libtorrent 2.0, many functions/members previously accessed via 'handle' changed. For example, 'torrent_handle.status()' now returns a status structure with renamed fields (e.g., 'state' instead of 'status').
fix
Check the libtorrent 2.0 migration guide; use 'state' enum for torrent state.
affects: >=2.0.0
breakingPython 3.6 or older is not supported; libtorrent 2.0.11 wheels are only for Python 3.7+.
fix
Upgrade to Python 3.7+.
affects: >=2.0.0
gotchaOn Windows, the pre-built wheel may require the Visual C++ Redistributable. If missing, you'll get an ImportError about DLL not found.
fix
Install Microsoft Visual C++ Redistributable for Visual Studio 2015-2022.
affects: all
Errors
Common errors & fixes
ImportError: DLL load failed while importing libtorrent: The specified module could not be found.
Missing C++ runtime (MSVCP140.dll) on Windows.
fix
Install Microsoft Visual C++ Redistributable from https://aka.ms/vs/17/release/vc_redist.x64.exe
AttributeError: module 'libtorrent' has no attribute 'add_torrent_params'
Incorrect import pattern or older libtorrent version where the function name differed (1.x used 'torrent_info' etc.)
fix
Use 'import libtorrent as lt' and refer to 'lt.add_torrent_params'. For libtorrent 1.x, use 'lt.torrent_info()'.
Upgrade
Version history
2.0.11latest on PyPI · released Jan 29, 2025
Audit
Dependencies
pythonrequiredlibtorrent is a C extension; pre-built wheels available for CPython on PyPI
Agent activity
2 hits · last 30 days
node
2
Resources
libtorrent — pip install libtorrent · libregistry