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.
-
Dependencies: The only 2 dependencies which are needed for aiotorrent to work are
fast-bencodeandbitstring. -
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
strategyparameter is not specified to theTorrent.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3137b8b966cfd48aece93c5fce9c5104d39d7adfbd05f93cadc0e1e5fd739c7
|
|
| MD5 |
d95f46b6a84d0796d5a3f9ffc9efdf26
|
|
| BLAKE2b-256 |
c8288acade5e855833ad3490d42984d212e4fef6fb2e487d117a75bdbb32422f
|
Provenance
The following attestation bundles were made for python_aiotorrent-0.8.3.tar.gz:
Publisher:
publish.yml on Mys7erio/aiotorrent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_aiotorrent-0.8.3.tar.gz -
Subject digest:
e3137b8b966cfd48aece93c5fce9c5104d39d7adfbd05f93cadc0e1e5fd739c7 - Sigstore transparency entry: 158282837
- Sigstore integration time:
-
Permalink:
Mys7erio/aiotorrent@a0ba238572b7811283132f91055a0faf5396c21e -
Branch / Tag:
refs/tags/v0.8.3 - Owner: https://github.com/Mys7erio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a0ba238572b7811283132f91055a0faf5396c21e -
Trigger Event:
release
-
Statement type:
File details
Details for the file python_aiotorrent-0.8.3-py3-none-any.whl.
File metadata
- Download URL: python_aiotorrent-0.8.3-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0567770371ed638cfebf4a176485da091b4fd016af285ef35285bcd218a7b6c8
|
|
| MD5 |
d34fb3d86cacefc84b6800fed7e22b78
|
|
| BLAKE2b-256 |
a8c673d6510e6e883dcfdfffb2d58a93a3b6e37209462a3c020c094d93f004fc
|
Provenance
The following attestation bundles were made for python_aiotorrent-0.8.3-py3-none-any.whl:
Publisher:
publish.yml on Mys7erio/aiotorrent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_aiotorrent-0.8.3-py3-none-any.whl -
Subject digest:
0567770371ed638cfebf4a176485da091b4fd016af285ef35285bcd218a7b6c8 - Sigstore transparency entry: 158282839
- Sigstore integration time:
-
Permalink:
Mys7erio/aiotorrent@a0ba238572b7811283132f91055a0faf5396c21e -
Branch / Tag:
refs/tags/v0.8.3 - Owner: https://github.com/Mys7erio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a0ba238572b7811283132f91055a0faf5396c21e -
Trigger Event:
release
-
Statement type: