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 python-aiotorrent

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

$ pip install python-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

python_aiotorrent-0.8.3.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

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

python_aiotorrent-0.8.3-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file python_aiotorrent-0.8.3.tar.gz.

File metadata

  • Download URL: python_aiotorrent-0.8.3.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for python_aiotorrent-0.8.3.tar.gz
Algorithm Hash digest
SHA256 e3137b8b966cfd48aece93c5fce9c5104d39d7adfbd05f93cadc0e1e5fd739c7
MD5 d95f46b6a84d0796d5a3f9ffc9efdf26
BLAKE2b-256 c8288acade5e855833ad3490d42984d212e4fef6fb2e487d117a75bdbb32422f

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_aiotorrent-0.8.3.tar.gz:

Publisher: publish.yml on Mys7erio/aiotorrent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_aiotorrent-0.8.3-py3-none-any.whl.

File metadata

File hashes

Hashes for python_aiotorrent-0.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0567770371ed638cfebf4a176485da091b4fd016af285ef35285bcd218a7b6c8
MD5 d34fb3d86cacefc84b6800fed7e22b78
BLAKE2b-256 a8c673d6510e6e883dcfdfffb2d58a93a3b6e37209462a3c020c094d93f004fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_aiotorrent-0.8.3-py3-none-any.whl:

Publisher: publish.yml on Mys7erio/aiotorrent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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