Unofficial Lightweight Python API for ThePirateBay
Installation
$ pip install tpblite
Dependencies:
- lxml
Usage
from tpblite import TPB
# Create a TPB object with a domain name
t = TPB('https://tpb.party')
# Or create a TPB object with default domain
t = TPB()
N.B Before using you should check which ThePirateBay domain works for you, as this varies from country to country.
Search
# Quick search for torrents, returns a Torrents object
torrents = t.search('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:
print(torrent)
# Customize your search
from tpblite import CATEGORIES, ORDERS
torrents = t.search('public domain', page=2, order=ORDERS.NAME.DES, 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
print(torrent.magnetlink)
Browse
# You can browse all of the torrents from a single category
torrents = t.browse(category=CATEGORIES.VIDEO)
# Customize the page number and sort order
torrents = t.browse(category=CATEGORIES.VIDEO.MOVIES, page=1, order=ORDERS.UPLOADED.DES)
Top
from tpblite import TPB, CATEGORIES
t = TPB()
# Get the top recent torrents
torrents = t.top(CATEGORIES.GAMES.ALL)
# Customize with category and restriction to torrents from the last 48h
torrents = t.top(category=CATEGORIES.GAMES.ALL, last_48=True)
Categories and Sort Order
# To print all available categories, use the classmethod printOptions
CATEGORIES.printOptions()
# Or just a subset of categories, like VIDEO
CATEGORIES.VIDEO.printOptions()
# Similarly for the sort order
ORDERS.printOptions()
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
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)Torrent.url- URL of the torrent page (str)Torrent.is_trusted- Whether the torrent is from a trusted source.Torrent.is_vip- Whether the torrent is from a VIP source.Torrent.infohash- The info hash of the torrent (str)Torrent.category- The torrent category (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 = t.search('GIMP 2.10.8')
torrent = torrents.getBestTorrent()
subprocess.call(['aria2c', torrent.magnetlink])
Metadata
Release files for tpblite 0.8.0
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 |
|---|---|---|---|---|
| tpblite-0.8.0.tar.gz | 9.7 kB | Without provenance | Details for tpblite-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tpblite-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for tpblite-0.8.0-py3-none-any.whl |
Total release size: 18.7 kB
Release files / tpblite-0.8.0.tar.gz
| Download URL | tpblite-0.8.0.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b1dc7e8718050352488088e4d7d205c94cfe55499bcc4f24e931ee9114766b34
|
|
BLAKE2b-256 checksum How to use checksums |
0086b6f6f100c9bb092e4ab27ce0ee13ca52bc60d1c9ab450f1ab6d0c9bf103c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|
Release files / tpblite-0.8.0-py3-none-any.whl
| Download URL | tpblite-0.8.0-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ace83580dacd1770263edc0691d1765e12089bbbe825fd4163aee5a19498ec8c
|
|
BLAKE2b-256 checksum How to use checksums |
eeaa8d8f7fc154d46ca3f121d2fe00c95397fbfb72225b5407982dfbb087d6d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
|
Security for tpblite 0.8.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.