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')
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.
fixInstall 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.)
fixUse '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