arxiv

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package arxiv is the library behind the arxiv command: the HTTP client, request shaping, and the typed data models for the arXiv Open Access API.

The API endpoint is https://export.arxiv.org/api/query. It returns Atom XML and requires no key. The arXiv ToS recommends no more than 3 requests per second; the default rate is 400 ms between calls.

Index

Constants

View Source
const DefaultUserAgent = "arxiv/dev (+https://github.com/tamnd/arxiv-cli)"

DefaultUserAgent identifies the client to arXiv.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when the API returns an empty entry list for a given id.

Functions

func ParsePaperID

func ParsePaperID(s string) (string, error)

ParsePaperID extracts a bare arXiv id (e.g. "1706.03762") from:

The version suffix is always stripped. Returns an error if s does not look like any recognized arXiv id form.

Types

type Category

type Category struct {
	Code        string `json:"code"`
	Description string `json:"description"`
}

Category is the static record used by the categories command.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the arXiv Open Access API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given config.

func (*Client) Paper

func (c *Client) Paper(ctx context.Context, id string) (Paper, error)

Paper fetches the single paper with the given id (version suffix stripped). Returns ErrNotFound if the id produces an empty result.

func (*Client) Search

func (c *Client) Search(ctx context.Context, opts SearchOptions) ([]Paper, error)

Search returns up to opts.Limit papers matching the query.

func (*Client) SearchByAuthor

func (c *Client) SearchByAuthor(ctx context.Context, name string, n int) ([]Paper, error)

SearchByAuthor returns up to n papers authored by name, sorted newest first.

type Config

type Config struct {
	UserAgent string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
}

Config holds constructor parameters.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Paper

type Paper struct {
	ID        string   `json:"id"`
	Title     string   `json:"title"`
	Authors   []string `json:"authors"`
	Category  string   `json:"category"`
	Published string   `json:"published"`
	Updated   string   `json:"updated"`
	Summary   string   `json:"summary"`
	URL       string   `json:"url"`
	PDF       string   `json:"pdf"`
}

Paper is the canonical record emitted for every search, paper, and author result. JSON keys are stable.

type SearchOptions

type SearchOptions struct {
	Query    string // free-text query
	Category string // "" = no category filter
	Sort     string // "relevance" | "date" | "updated"
	Limit    int
}

SearchOptions controls a Search call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL