Skip to content

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.

License

Notifications You must be signed in to change notification settings

dhruvv1402/BitTorrent-Client-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BitTorrent Client in Python 🐍

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.

Features 🌟

  • 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.

How It Works 🛠️

  1. Parse Torrent File: Extracts metadata (e.g., trackers, piece hashes, file structure).
  2. Connect to Trackers: Retrieves a list of peers sharing the file.
  3. Peer Communication: Establishes connections with peers to request and download pieces.
  4. Piece Validation: Verifies downloaded pieces using SHA-1 hashes.
  5. File Assembly: Combines downloaded pieces into the final file(s).

Getting Started 🚀

  1. Clone the repository:
    git clone https://github.com/yourusername/bittorrent-client.git
  2. Install dependencies:
    pip install -r requirements.txt
  3. Run the client:
    python main.py /path/to/your.torrent

Example Usage 📂

python main.py ubuntu-22.04.torrent

Project Structure 📁

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

Dependencies 📦

  • bencodepy: For parsing .torrent files.
  • requests: For HTTP tracker communication.
  • rich: For beautiful progress tracking.
  • async-timeout: For handling timeouts in async operations.

Contributing 🤝

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

License 📜

This project is licensed under the MIT License. See LICENSE for details.


About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages