Skip to content

A lightweight BitTorrent library written in pure Python.

License

Notifications You must be signed in to change notification settings

Mys7erio/aiotorrent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aiotorrent

Aiotorrent is an asynchronous, ultra-lightweight torrent library written in pure Python with support for features such as downloading files to disk, streaming of files over HTTP & more.

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 some 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


You need to import the Torrent class and pass a torrent file to it:

from aiotorrent import Torrent
torrent = Torrent('path/to/torrent')

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

Downloading & Streaming


Files can be accessed from the files attribute of the torrent class which stores all the File objects in a list. To download a file, you can call the download() coroutine and pass in a File object:

# To download file2
await torrent.download(torrent.files[2])

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

await torrent.stream(torrent.files[2])

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


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



TODO

  • Test compatiability on older versions of Python.
  • Add documentation for all the classes in the library.
  • Add support for HTTP trackers (And later, WSS trackers).
  • Return downloaded pieces as soon as they are downloaded (replace batch downloading approach)
  • Replace print statements with logging.
  • Update the Torrent class to make the API more modular.
  • Implement functionality to get download status in the Torrent class.

Releases

No releases published

Packages

No packages published

Languages