Whatbox Logo
Login for certain variables to be updated with your slot's information

Wiki > Using XMLRPC with Python

Introduction

XMLRPC is used by rTorrent as a means for sending and receiving information from the server. Queries can be made to retrieve information about current torrents as well as executing commands, for example pausing a torrent.

This guide hopes to cover using Python to interact with the rTorrent server. This allows us to write scripts that can automate the use of our rTorrent server.

Use Cases

Some use cases of using Python to interact with your rTorrent server through XMLRPC might be:

  • Script to automatically remove a torrent when it has seeded a certain amount
  • Web interface using Flask or Bottle to display torrent information
  • Script with a cron job to periodically send information about currently running torrents to an email address
    • Many more!

XMLRPC Login Details

The login details for the XMLRPC interface on your rTorrent server are as follows (don't forget to percent encode your password):

Protocol: HTTPS
Host: server.whatbox.ca
Port: 443
Mountpoint: /xmlrpc
Username: user
Password: (Your password)

We will use this information to connect to your server.

Python Script

This section contains an example Python script and will have comments within it explaining what it does. For further reference, the api documentation is here

The library xmlrpclib is required for this script to function. It should already by installed on your slot, so there is no need to install it.

script.py

# Import the XMLRPC library
# Note: It used to be called xmlrpclib (python 2: import xmlrpclib)
import xmlrpc.client

# Create an object to represent our server. Use the login information in the XMLRPC Login Details section here.
server_url = "https://user:(Your password)@server.whatbox.ca:443/xmlrpc"
server = xmlrpc.client.Server(server_url)

# Get torrents in the main view
mainview = server.download_list("", "main")

# For each torrent in the main view
for torrent in mainview:

    # Print the name of torrent
    print(server.d.name(torrent))
    # Print the directory of torrent
    print(server.d.directory(torrent))


    # If you are setting something, like for example changing all rutorrent labels (custom1 in xmlrpc) to "newL" if they had "oldL"
    if server.d.custom1(torrent) == "oldL":
        server.d.custom1.set(torrent, "newL")

This script essentially connects to the XMLRPC interface of the rTorrent server, retrieves a list of the torrents in the main view, and then for each of those torrents, gets the name of the torrent and the directory of the torrent.

Example of setting custom1 added for reference because update changed naming from d.set_X(...) to d.X.set(...), while also removing the "get" from getting name/directory/etc.

Due to the easy use of Python, creating scripts to interact with the XMLRPC interface of an rTorrent server is painless.