Skip to main content

Quick n' dirty torrent streaming with libtorrent and python

Project description


Libtorrent made easy

This is pythonic high-level libtorrent API, inspired on the for-humans trend set by Kenneth Reitz (

TorrentStream is centered around the principle of streaming a torrent (sequential download, buffering and playing).

pypi release downloads python_versions pypi_versions

TorrentStream exposes a CLI command, intended as an example usage.


Torrent objects are context managers that can clean up torrent content after you finish using them.

add_torrent method of a TorrentSession returns a Torrent object, thus can be used directly as a context manager.

async def stream_torrent(hash_torrent):
    session = TorrentSession()

    # By default this will cleanup torrent contents after playing
    with session.add_torrent(magnet_link=hash_torrent, remove_after=True) as torrent:
        # Force sequential mode

        # Wait for torrent to be started
        await torrent.wait_for('started')

        # Get first match of a media file
            media = next(a for a in torrent
                         if a.is_media and not 'sample' in a.path.lower())
        except StopIteration:
            raise Exception('Could not find a playable source')

        with timeout(5 * 60):  # Abort if we can't fill 5% in 5 minutes
            await media.wait_for_completion(5)

        return await asyncio.gather(media.wait_for_completion(100),

Project details

Download files

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

Files for torrentstream, version 0.3.1
Filename, size File type Python version Upload date Hashes
Filename, size torrentstream-0.3.1.tar.gz (5.7 kB) File type Source Python version None Upload date Hashes View
Filename, size torrentstream-0.3.1-py3-none-any.whl (6.4 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page