1337x Python API

repository·main·Indexed 41 days ago

https://github.com/hemantapkh/1337x

An unofficial Python API wrapper for 1337x.to (version 2.1.1) that allows developers to search for torrents, view trending content, and retrieve detailed torrent information and magnet links. Provides both synchronous (Py1337x) and asynchronous (AsyncPy1337x) implementations.

Tokens
772
Snippets
4
Records
4
Agent score
50%

What's inside 1337x

  1. Install 1337x via pip

    main

    You can install the 1337x Python wrapper using PyPi or directly from the GitHub source.

    # Install via PyPi
    pip install 1337x
    
    # Or install from source
    pip install git+https://github.com/hemantapkh/1337x
  2. Get detailed torrent information

    main

    Once you have a search result, you can retrieve specific details like the magnet link by using the .info() method with a torrent_id. You can also convert the resulting information object into a standard Python dictionary using .to_dict().

    # Assuming 'results' is a search result object
    torrent_id = results.items[0].torrent_id
    
    # Get detailed info
    info = torrents.info(torrent_id=torrent_id)
    print(info)
    
    # Convert the result to a dictionary
    info_dict = info.to_dict()
    print(info_dict)
  3. Use 1337x asynchronously with AsyncPy1337x

    main

    For asynchronous environments, use the AsyncPy1337x class. The method signatures and functionalities are identical to the synchronous Py1337x class, but you must await the calls.

    import asyncio
    from py1337x import AsyncPy1337x
    
    async def main():
        torrents = AsyncPy1337x()
        # Await the search results
        results = await torrents.search('vlc media player')
        print(results)
    
    asyncio.run(main())
  4. Search for torrents using Py1337x

    main

    Use the Py1337x class to perform searches.

    Important Note: Due to changes on the 1337x website, it is highly recommended to specify a category when calling .search(), otherwise you may receive empty results.

    Available parameters for .search():

    • query (str): The search term.
    • page (int): The page number to retrieve.
    • category: Use py1337x.category constants (e.g., py1337x.category.APPS).
    • sort_by: Use py1337x.sort constants (e.g., py1337x.sort.SEEDERS).
    import py1337x
    
    torrents = py1337x.Py1337x()
    
    # Basic search with category (recommended)
    results = torrents.search(
        'ubuntu',
        page=1,
        category=py1337x.category.APPS
    )
    
    # Search with sorting by seeders
    results = torrents.search(
        'vlc',
        sort_by=py1337x.sort.SEEDERS,
        category=py1337x.category.APPS
    )
    
    # Get today's trending torrents
    trending_results = torrents.trending()