An open API service indexing awesome lists of open source software.

https://github.com/dhruvv1402/bittorrent-client-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.
https://github.com/dhruvv1402/bittorrent-client-python

asyncio bencode bittorrent bittorrent-client logging python requests socket threading torrent

Last synced: 6 months ago
JSON representation

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.

Awesome Lists containing this project

README

          

# 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:
```bash
git clone https://github.com/yourusername/bittorrent-client.git
```
2. Install dependencies:
```bash
pip install -r requirements.txt
```
3. Run the client:
```bash
python main.py /path/to/your.torrent
```

## Example Usage 📂
```bash
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](LICENSE) for details.

---