PyTorrent
Simple BitTorrent client made in Python - Use for learning
Install / Use
/learn @gallexis/PyTorrentREADME
PyTorrent
PyTorrent is a CLI tool that downloads files from the BitTorrent network.
I wanted to make my own functional and straightforward program to learn how does BitTorrent protocol work and improve my python skills.
It is almost written from scratch with python 3.7, only the pubsub library was used to create events when a new peer is connected, or when data is received from a peer. You first need to wait for the program to connect to some peers first, then it starts downloading.
This tool needs a lot of improvements, but it does its job, you can :
- Read a torrent file
- Scrape udp or http trackers
- Connect to peers
- Ask them for the blocks you want
- Save a block in RAM, and when a piece is completed and checked, write the data into your hard drive
- Deal with the one-file or multi-files torrents
- Leech or Seed to other peers
But you can’t :
- Download more than one torrent at a time
- Benefit of a good algorithm to ask your peers for blocks (code of rarest piece algo is implemented but not used yet)
- Pause and resume download
Don't hesitate to ask me questions if you need help, or send me a pull request for new features or improvements.
Installation
You can run the following command to install the dependencies using pip
pip install -r requirements.txt
:boom: Because it's using the "select" function, this code will not be able to run on Windows: python-select-on-windows
Running the program
Simply run:
python main.py /path/to/your/file.torrent
The files will be downloaded in the same path as your main.py script.
Sources :
I wouldn't have gone that far without the help of Lita, Kristen Widman's & the Bittorrent Unofficial Spec, so thank you.
Related Skills
claude-opus-4-5-migration
107.6kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
model-usage
346.8kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
TrendRadar
50.7k⭐AI-driven public opinion & trend monitor with multi-platform aggregation, RSS, and smart alerts.🎯 告别信息过载,你的 AI 舆情监控助手与热点筛选工具!聚合多平台热点 + RSS 订阅,支持关键词精准筛选。AI 智能筛选新闻 + AI 翻译 + AI 分析简报直推手机,也支持接入 MCP 架构,赋能 AI 自然语言对话分析、情感洞察与趋势预测等。支持 Docker ,数据本地/云端自持。集成微信/飞书/钉钉/Telegram/邮件/ntfy/bark/slack 等渠道智能推送。
mcp-for-beginners
15.8kThis open-source curriculum introduces the fundamentals of Model Context Protocol (MCP) through real-world, cross-language examples in .NET, Java, TypeScript, JavaScript, Rust and Python. Designed for developers, it focuses on practical techniques for building modular, scalable, and secure AI workflows from session setup to service orchestration.
