The existing answers give you everything you need ... but there is code to make it explicit:
import libtorrent as lt info = lt.torrent_info(open('example.torrent','rb').read()) info_hash = info.info_hash() hexadecimal = str(info_hash) integer = int(hexadecimal, 16)
EDIT : this is actually not true - torrent_info() should pass the length of the torrent file and its contents. Revised (working) version:
import libtorrent as lt torrent = open('example.torrent','rb').read() info = lt.torrent_info(torrent, len(torrent)) info_hash = info.info_hash() hexadecimal = str(info_hash) integer = int(hexadecimal, 16)
source share