Simple BitTorrent Client

A compact BitTorrent client focused on fast peer acquisition and reliable downloads

Python 3.10+ DHT Support Magnet Links Fast Peer Discovery
main.py
# Download a torrent file
python main.py download -o output.file sample.torrent

# Download from magnet link
python main.py magnet_download -o file.zip "magnet:?xt=..."

# Get peer information
python main.py peers sample.torrent

Key Features

Fast Peer Acquisition

Immediate piece requests after handshake with no startup delay to reduce idle time and maximize download speed.

DHT Support (BEP 5)

Trackerless peer discovery with DHT port advertisement and consumption via message type 9 for metadata/magnet support.

Auto-Replenish Peers

Automatic peer replenishment through DHT lookups when connections drop, ensuring continuous download progress.

Magnet Link Support

Optional magnet metadata downloader with full support for magnet links and metadata exchange protocols.

PEX Support

Peer Exchange (PEX) support where available using ut_pex for efficient peer discovery and sharing.

Parallel Downloads

Parallel block requests per piece with configurable concurrency for higher throughput and faster downloads.

Project Overview

This project implements a simple BitTorrent client designed for experimentation, research, and lightweight seeding. It's not intended as a production-grade client but rather as a tool for:

  • Testing swarm behavior - Analyze how peers interact in BitTorrent swarms
  • Research on peer discovery - Study different strategies for finding and connecting to peers
  • Small-scale seeding - Lightweight seeding implementation for sharing files
  • Educational purposes - Learn how BitTorrent protocol works under the hood

The client emphasizes speed and efficiency with immediate piece requests, DHT support, and intelligent peer management.

2000+
Lines of Code
15+
Commands
5
Core Classes

Quick Start

1

Install Requirements

pip install requests
# Optional: pip install libtorrent (for seeder.py)
2

Download a File

python app/main.py download -o myfile.zip sample.torrent
3

Use Magnet Links

python app/main.py magnet_download -o file.zip "magnet:?xt=urn:btih:..."

Architecture

Core Components

  • PeerManager - Manages peer connections and DHT integration
  • PieceManager - Handles piece downloading and verification
  • DHT - Distributed Hash Table for peer discovery
  • MetadataManager - Manages torrent metadata exchange

Protocol Support

  • BitTorrent Protocol - Standard peer-to-peer communication
  • DHT (BEP 5) - Trackerless peer discovery
  • PEX (ut_pex) - Peer exchange extension
  • Magnet Links - Metadata exchange protocol