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.
- Host: GitHub
- URL: https://github.com/dhruvv1402/bittorrent-client-python
- Owner: dhruvv1402
- License: mit
- Created: 2025-03-23T23:18:26.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-03-23T23:27:38.000Z (10 months ago)
- Last Synced: 2025-03-24T00:26:33.568Z (10 months ago)
- Topics: asyncio, bencode, bittorrent, bittorrent-client, logging, python, requests, socket, threading, torrent
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.
---