Skip to main content

An ultra-lightweight torrent library written in pure Python.

Project description

Aiotorrent

Aiotorrent is an asynchronous, ultra-lightweight torrent library written in pure Python with support for unique features such as serving of files over HTTP without downloading to disk & more.
A comprehensive list of features supported by aiotorrent as of now are:
  • Complete asyncio support
  • Connecting to various types of torrent trackers (HTTP & UDP)
  • Specifying an appropriate piece download strategy (default and sequential downloading)
  • Downloading files to disk
  • Serving files over HTTP without saving them to disk

[!NOTE] This library is still in active development and many additional features such as downloading files from a magnet link, resuming torrent downloads, etc are yet to (but soon will) be implemented.


Requirements

Tested on Python 3.11 but it should work on Python ^3.9 versions just fine.

  1. Dependencies: The only 2 dependencies which are needed for aiotorrent to work are fast-bencode and bitstring.

  2. Streaming dependencies: built-in support for streaming files over HTTP. To use this feature, you need to install extra streaming dependencies.


Installation

Install aiotorrent from PyPI using:

$ pip install aiotorrent

In order to use the streaming feature, you can install the dependencies using:

$ pip install aiotorrent[stream-support]

Quickstart

Initialisation

# Import the Torrent class and pass a torrent file to it:
from aiotorrent import Torrent
torrent = Torrent('path/to/file.torrent')

# To initialise the torrent, you need to call the init() coroutine.
await torrent.init()

Downloading & Streaming

Torrent files are stored inside Torrent.files as a list. We can access them by sub-scripting the Torrent.files attribute, like as follows:

Example to download and stream files

# To download the third file
await torrent.download(torrent.files[2])

Similarly, to serve a torrent file over HTTP, you can call the stream() coroutine, as follows:

# To stream the second file, etc
await torrent.stream(torrent.files[1])

This starts up a uvicorn server on localhost:8080 which uses starlette behind the scenes as the ASGI framework to stream files over http.

Piece downloading strategy

You can also change how pieces of a particular file are being downloaded. Currently, this library offers two download strategies:

  • Default: This strategy is used when the strategy parameter is not specified to the Torrent.download() function. It downloads file pieces in a pseudo-sequential manner. For instance, it will start fetching pieces in order, but it may or may not yield the pieces in order.

  • Sequential: This strategy is straight forward, and it always yields pieces in a sequential manner.

[!IMPORTANT] The stream() coroutine always uses the SEQUENTIAL download strategy, and this behaviour cannot be changed.

from aiotorrent import DownloadStrategy
from aiotorrent import Torrent

torrent = Torrent("path/to/file.torrent")
file = torrent.files[1]

# The download strategies available are: DownloadStrategy.DEFAULT and DownloadStrategy.SEQUENTIAL
await torrent.download(file, strategy=DownloadStrategy.SEQUENTIAL)

The above methods can take additional parameters to customize the behaviour of this library. Read the documentation to know more.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiotorrent-0.9.0.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiotorrent-0.9.0-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file aiotorrent-0.9.0.tar.gz.

File metadata

  • Download URL: aiotorrent-0.9.0.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.1 Windows/11

File hashes

Hashes for aiotorrent-0.9.0.tar.gz
Algorithm Hash digest
SHA256 1d8b1f4a0de45e7e37d169bae363b53933b6ef5621b4e53da0ba94ccaf82a798
MD5 9209de4145476b3fa01183193f8edb9f
BLAKE2b-256 7d0f6fe83a99df030d105fb7b4d845803423d22bf390b6b5ec60e7390799559a

See more details on using hashes here.

File details

Details for the file aiotorrent-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: aiotorrent-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 26.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.1 Windows/11

File hashes

Hashes for aiotorrent-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c558e21a132f6df0dd3806538186a3e827a4c66236370e8b1960b960f8f36b1
MD5 d5e18da2b28732eb91cef1bfdb0f5b4a
BLAKE2b-256 16b0b2e0293dbdd60b90f4bdbf2a961c298d8ae8852e8719c5230215cab52ba7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page