rtapi is a small Go client for rTorrent's XML-RPC interface over SCGI. It is
the library used by rtelegram.
- Go 1.26 or newer.
- rTorrent built with XML-RPC support.
- A local SCGI endpoint such as a protected Unix socket or
scgi_port = 127.0.0.1:5000.
The rTorrent RPC endpoint has no authentication and exposes powerful methods. Prefer a permission-protected Unix socket. Never expose SCGI directly to an untrusted network; see rTorrent's official XML-RPC security guidance.
go get github.com/pyed/rtapi@latestpackage main
import (
"fmt"
"log"
"github.com/pyed/rtapi"
)
func main() {
rt, err := rtapi.NewRtorrent("/run/user/1000/rtorrent.sock")
if err != nil {
log.Fatal(err)
}
torrents, err := rt.Torrents()
if err != nil {
log.Fatal(err)
}
for _, torrent := range torrents {
fmt.Printf("%s: %d/%d bytes\n", torrent.Name, torrent.Completed, torrent.Size)
}
}TCP addresses such as 127.0.0.1:5000 are also accepted. Every SCGI request is
bounded by rtapi.DefaultTimeout (30 seconds) unless Rtorrent.Timeout is set.
Responses default to a 16 MiB safety bound; set Rtorrent.MaxResponseSize when
a legitimately large library needs more. Transport errors, malformed responses,
and XML-RPC faults are returned to the caller; errors.As can inspect an
*rtapi.XMLRPCFault.
- Transfer fields (
Size,Completed, andUpTotal) contain exact byte counts. SpeedsWithErrorreports failures.Speedsremains as a deprecated compatibility shim that cannot distinguish failure from zero traffic.DownloadRawloads torrent bytes directly, avoiding credential-bearing intermediary URLs.DownloadWithOptionsremains available for URL loading.Torrents.Sorttakes an explicitrtapi.Sortingvalue. The unsafe process-globalCurrentSortingvariable was removed; callSorton each returned value instead.DeleteMetadataerases metadata only after rTorrent acknowledges the RPC. The olderDelete(false, ...)form remains as a deprecated compatibility shim.Delete(true, ...)returnsErrUnsafeDataDeletebefore any RPC or local filesystem access. Data belongs to the rTorrent host; an application that offers data deletion must enforce its own explicit local root and containment policy.
go test ./...
go vet ./...
go build ./...