A lightweight, asynchronous BitTorrent client implemented in Python. This project demonstrates the core functionality of the BitTorrent protocol, including peer communication, piece management, and file downloading.
- Asynchronous I/O: Built with
asyncio
for high-performance peer communication. - Multi-File Support: Handles both single-file and multi-file torrents.
- Piece Management: Efficiently manages and validates downloaded pieces using SHA-1 hashes.
- Tracker Support: Communicates with HTTP trackers to discover peers.
- Rich Progress Tracking: Real-time download progress with the
rich
library.
- Parse Torrent File: Extracts metadata (e.g., trackers, piece hashes, file structure).
- Connect to Trackers: Retrieves a list of peers sharing the file.
- Peer Communication: Establishes connections with peers to request and download pieces.
- Piece Validation: Verifies downloaded pieces using SHA-1 hashes.
- File Assembly: Combines downloaded pieces into the final file(s).
- Clone the repository:
git clone https://github.com/yourusername/bittorrent-client.git
- Install dependencies:
pip install -r requirements.txt
- Run the client:
python main.py /path/to/your.torrent
python main.py ubuntu-22.04.torrent
bittorrent-client/
├── client/ # Core client modules
│ ├── client.py # Main client logic
│ ├── torrent.py # Torrent file parsing
│ ├── tracker.py # Tracker communication
│ ├── peer.py # Peer connection handling
│ ├── piece_manager.py # Piece management
│ └── utils.py # Utility functions
├── requirements.txt # Dependencies
└── main.py # Entry point
bencodepy
: For parsing.torrent
files.requests
: For HTTP tracker communication.rich
: For beautiful progress tracking.async-timeout
: For handling timeouts in async operations.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License. See LICENSE for details.