Skip to content

mtreilly/goarxiv

Repository files navigation

goarxiv

Go Reference Go Report Card License: MIT

Go SDK for the arXiv API. Provides an ergonomic, type-safe client for searching and retrieving arXiv articles while honoring the platform's usage guidelines.

Features

  • Idiomatic Client with functional options, request/response hooks, and context support
  • Declarative query builder with full category taxonomy validation
  • Built-in 3-second rate limiter (required by arXiv ToU)
  • Pagination helpers (SearchAll, StreamResults, Iterate) capped at 30,000 results
  • Export helpers (BibTeX, JSON, CSV) for downstream workflows
  • Rate-limit-friendly PDF downloader with progress callbacks

Installation

go get github.com/mtreilly/goarxiv

Quick Start

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/mtreilly/goarxiv"
)

func main() {
    client, err := goarxiv.New()
    if err != nil {
        log.Fatal(err)
    }

    ctx := context.Background()
    results, err := client.Search(ctx, "all:quantum computing", nil)
    if err != nil {
        log.Fatal(err)
    }

    for _, article := range results.Articles {
        fmt.Printf("%s - %s\n", article.ID, article.Title)
    }
}

Pagination

// Iterate through results one at a time
iter := client.Iterate("cat:cs.LG", 50, nil)
for iter.Next(ctx) {
    article := iter.Article()
    fmt.Printf("%s - %s\n", article.ID, article.Title)
}
if err := iter.Err(); err != nil {
    log.Fatal(err)
}

Export Formats

// Export to BibTeX
bibtex := article.ToBibTeX()

// Export to JSON
jsonData, _ := article.ToJSON()

// Export to CSV row
csvRow := article.ToCSV()

Download PDFs

err := client.DownloadPDF(ctx, article, &goarxiv.DownloadOptions{
    OutputDir: "./papers",
    OnProgress: func(downloaded, total int64) {
        fmt.Printf("%.1f%%\n", float64(downloaded)/float64(total)*100)
    },
})

Rate Limiting

The arXiv API requires a minimum 3-second delay between requests. This client enforces rate limiting automatically. For local testing against mock servers, you can use WithDebugMode(), but never use this against the real API.

Attribution

This project uses the arXiv API. Thank you to arXiv for use of its open access interoperability.

arXiv API Terms of Use: https://arxiv.org/help/api/tou

Development

# Run unit tests
go test ./...

# Run integration tests (hits real arXiv API)
ARXIV_INTEGRATION_TESTS=1 go test ./...

License

MIT License - see LICENSE for details.

About

Go SDK for the arXiv API

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages