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.
Metadata
Release files for python-aiotorrent 0.8.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_aiotorrent-0.8.3.tar.gz | 18.4 kB | With provenance | Details for python_aiotorrent-0.8.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_aiotorrent-0.8.3-py3-none-any.whl | Python 3 | none | any | Details for python_aiotorrent-0.8.3-py3-none-any.whl |
Total release size: 40.2 kB
Release files / python_aiotorrent-0.8.3.tar.gz
| Download URL | python_aiotorrent-0.8.3.tar.gz |
|---|---|
| Size | 18.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3137b8b966cfd48aece93c5fce9c5104d39d7adfbd05f93cadc0e1e5fd739c7
|
|
BLAKE2b-256 checksum How to use checksums |
c8288acade5e855833ad3490d42984d212e4fef6fb2e487d117a75bdbb32422f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 30, 2024.
Transparency logRelease files / python_aiotorrent-0.8.3-py3-none-any.whl
| Download URL | python_aiotorrent-0.8.3-py3-none-any.whl |
|---|---|
| Size | 21.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0567770371ed638cfebf4a176485da091b4fd016af285ef35285bcd218a7b6c8
|
|
BLAKE2b-256 checksum How to use checksums |
a8c673d6510e6e883dcfdfffb2d58a93a3b6e37209462a3c020c094d93f004fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 30, 2024.
Transparency logSecurity for python-aiotorrent 0.8.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for python_aiotorrent-0.8.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 30, 2024.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.