Skip to main content

btdht: A python implementation of the Bittorrent distributed hash table

github_version pypi_version licence doc

The aim of btdht is to provide a powerful implementation of the Bittorrent mainline DHT easily extended to build application over the DHT. The author currently uses it to crawl the dht and has been able to retrieve more than 200.000 torrents files a day.

The implementation is fully compliant with the BEP5 and the kademlia paper [1] (with a predominance of the BEP5 over the paper) For example, this implementation uses a bucket-based approach for the routing table.

Dependencies

Build dependencies

  • A C compiler

  • cython

  • python header files

Installation

The recommended installation mode is to use a virtualenv.

To Install btdht using the last published release, run:

$ pip install btdht

Alternatively if you want to use the version of the git repository, you can clone it:

$ git clone https://github.com/nitmir/btdht
$ cd btdht
$ pip install -r requirements-dev.txt

Then, run make install to compile the sources and create a python package and install it with pip.

For installing or building on linux and unix systems, you will need a C compiler and the python headers (installing the packages build-essential and python-dev should be enough on debian like systems, you’ll probably gonna need make, gcc, python2-devel and redhat-rpm-config on centos like systems).

On windows systems, we provide pre-builded releases for python 2.7 and 3.5 so just running pip install btdht should be fine. If you want to build from the sources of the repository or, for another python version, you will also need a C compiler.

Usage examples

Search for the peers announcing the torrent 0403fb4728bd788fbcb67e87d6feb241ef38c75a (Ubuntu 16.10 Desktop (64-bit))

>>> import btdht
>>> import binascii
>>> dht = btdht.DHT()
>>> dht.start()  # now wait at least 15s for the dht to boostrap
init socket for 4c323257aa6c4c5c6ccae118db93ccce5bb05d92
Bootstraping
>>> dht.get_peers(binascii.a2b_hex("0403fb4728bd788fbcb67e87d6feb241ef38c75a"))
[
    ('81.171.107.75', 17744),
    ('94.242.250.86', 3813),
    ('88.175.164.228', 32428),
    ('82.224.107.213', 61667),
    ('85.56.118.178', 6881),
    ('78.196.28.4', 38379),
    ('82.251.140.70', 32529),
    ('78.198.108.3', 10088),
    ('78.235.153.136', 10619),
    ('88.189.113.32', 33192),
    ('81.57.9.183', 5514),
    ('82.251.17.155', 14721),
    ('88.168.207.178', 31466),
    ('82.238.89.236', 32970),
    ('78.226.209.88', 2881),
    ('5.164.219.48', 6881),
    ('78.225.252.39', 31002)
]

Subsequent calls to get_peers may return more peers.

You may also inherit btdht.DHT_BASE and overload some of the on_`msg`_(query|response) functions. See the doc for a full overview of the btdht API.

Metadata

Release files for btdht 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for btdht 0.3.0
File Size Uploaded Provenance Actions
btdht-0.3.0.tar.gz 580.0 kB Without provenance Details for btdht-0.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for btdht 0.3.0
File Actions
btdht-0.3.0-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details for btdht-0.3.0-cp35-cp35m-win_amd64.whl
btdht-0.3.0-cp35-cp35m-win32.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-32 Details for btdht-0.3.0-cp35-cp35m-win32.whl
btdht-0.3.0-cp27-cp27m-win_amd64.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-64 Details for btdht-0.3.0-cp27-cp27m-win_amd64.whl
btdht-0.3.0-cp27-cp27m-win32.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-32 Details for btdht-0.3.0-cp27-cp27m-win32.whl

Total release size: 4.4 MB

Release files / btdht-0.3.0.tar.gz

Download URL btdht-0.3.0.tar.gz
Size 580.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5a157c43704b462573402808e2e75464e2f9a5d433d3f6e5b54489eb11fc63b7
BLAKE2b-256 checksum
How to use checksums
37c0d923fef89ae99cc511a914ccbca4dfb6e8b0ff1bcebb59b6dcd793c8aa30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / btdht-0.3.0-cp35-cp35m-win_amd64.whl

Download URL btdht-0.3.0-cp35-cp35m-win_amd64.whl
Size 962.3 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
84e4e475a15ff4c7835cd029b6f88b4778259be44c91bbfca0cdf12532832d8a
BLAKE2b-256 checksum
How to use checksums
f6e6b95bd4e64707f0e23c349852ce5d37b338984601d605b6cf34ca9f45c5d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / btdht-0.3.0-cp35-cp35m-win32.whl

Download URL btdht-0.3.0-cp35-cp35m-win32.whl
Size 928.0 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
20f7e272ef9455bc9d4895706a7a1f974c85430064aa8c2a2a000d3bf41a6671
BLAKE2b-256 checksum
How to use checksums
e2aa049d250230871d7afc94f2990d847e867746a335acd6b5ba5f0f755dc4fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / btdht-0.3.0-cp27-cp27m-win_amd64.whl

Download URL btdht-0.3.0-cp27-cp27m-win_amd64.whl
Size 992.3 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
781ece97f73e0b80961d5b8940d34ae0268da5ded54d6a353645f8376bcf6d8f
BLAKE2b-256 checksum
How to use checksums
0a216d27ee824a2a274592aa8336eb0433ec1e4f9b8a709a4532d1b1e2555e77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / btdht-0.3.0-cp27-cp27m-win32.whl

Download URL btdht-0.3.0-cp27-cp27m-win32.whl
Size 934.6 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
fa9931a7f5812fe3c2c519ddc7411b8bbfdd5af946f09dbea60b82d5d667ed57
BLAKE2b-256 checksum
How to use checksums
ffb430175771f5d4a569a33b28b13a437d460fc117c40c259a83ab552c1c5296
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for btdht 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page