Skip to main content

The Unofficial Pirate Bay Lightweight Python API

Project description

Unofficial Lightweight Python API for ThePirateBay


$ pip install tpblite


  • BeautifulSoup
  • purl


from tpblite import TPB

# Create a TPB object with a domain name
t = TPB('')

# Or create a TPB object with default domain
t = TPB()


# Quick search for torrents, returns a Torrents object
torrents ='public domain')

# See how many torrents were found
print('There were {0} torrents found.'.format(len(torrents))

# Iterate through list of torrents and print info for Torrent object
for torrent in torrents:

# Customize your search
from tpb import CATEGORIES, ORDERS
torrents ='public domain', page=2, order=ORDERS.NAME.DEC, category=CATEGORIES.VIDEO.MOVIES)

# Get the most seeded torrent based on a filter
torrent = torrents.getBestTorrent(min_seeds=30, min_filesize='500 MiB', max_filesize='4 GiB')

# Or select a particular torrent by indexing
torrent = torrents[3]

# Get the magnet link for a torrent

Torrents object

The search function returns a Torrents object, which is a list-like collection of the torrents found.

You can also iterate over the Torrents object just by calling it in a for loop (see example above).

You can see how many Torrent objects your query has returned, by using the len() function

Torrent object

Torrent objects represent each torrent found in the Torrents class, they have the following attributes


  • Torrent.title - The name of the torrent (str)
  • Torrent.seeds - The number of seeders (int)
  • Torrent.leeches - The number of leechers (int)
  • Torrent.upload_date - Date the torrent was uploaded (str)
  • Torrent.uploader - Name of user who uploaded torrent (str)
  • Torrent.filesize - The filesize in *iB format, eg. 5 GiB (str)
  • Torrent.byte_size - The filesize in bytes of the torrent (int)
  • Torrent.magnetlink - magnetlink of the torrent (str)

Example Workflow

With a commandline torrent client such as aria2, you can automate search and downloading of torrents like so:

import subprocess
from tpblite import TPB

t = TPB()
torrents ='GIMP 2.10.8')
torrent = torrents.getBestTorrent()['aria2c', torrent.magnetlink])

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 tpblite, version 0.2.3
Filename, size File type Python version Upload date Hashes
Filename, size tpblite-0.2.3.tar.gz (6.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page