arxiv

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package arxiv finds papers on arXiv by their ids and names their PDFs as products to fetch, gently.

Every request, to the API and for a PDF, goes through one Gate: one at a time, three seconds apart at least, as arXiv's API terms ask. When arXiv answers 403, 429 or 503 it is asking us to stop, and nothing more is asked.

A gate held through a record keeps the pace, and any wait arXiv asked for, from one run to the next.

The API is asked through github.com/Epistemic-Technology/arxiv. Its v1.0.1 paces by three nanoseconds, replaces a limiter it is given, and parses a 429 as results; so its pacing is turned off, the Gate paces instead, and the answer's status is read here before it is.

Index

Constants

View Source
const API = "https://export.arxiv.org/api/query"

API is the address of arXiv's API on export.arxiv.org, the host arXiv sets aside for programs.

Variables

This section is empty.

Functions

func AskedToStop

func AskedToStop(err error) bool

AskedToStop is whether an error is arXiv asking us to stop: a 403, 429 or 503 from the API or a PDF fetched through a paced web, or a wait arXiv asked for that has not passed.

func Paced

func Paced(ctx context.Context, get web.Web, gate *Gate) (web.Web,
	error)

Paced is a web whose every request goes through the gate, waiting there while ctx lasts. One goes at a time, each begun at least the gate's pace after the last began. A Get holds the gate until its body is closed, so a slow download is still the only request.

It refuses a missing context, web or gate.

Types

type Clock

type Clock interface {
	Now() time.Time
	Sleep(ctx context.Context, wait time.Duration) error
}

Clock is the time a gate keeps. Its Sleep ends early when the context ends, and gives the context's error.

func Wall

func Wall() Clock

Wall is the clock on the wall.

type Gate

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

Gate lets one request at a time through to arXiv. Each starts at least its pace after the one before started. A request enters, is answered and leaves; the next waits at the gate.

Held, a gate keeps its last start and any time arXiv asked it to wait until in a record, so the pace and the wait carry over between runs.

func NewGate

func NewGate(pace time.Duration, clock Clock) (*Gate, error)

NewGate is a gate at a pace, on a clock. It refuses a pace quicker than arXiv's least, so a mistake in a numbers file cannot ask faster than arXiv allows. It refuses a missing clock too.

func (*Gate) Asked

func (gate *Gate) Asked() int

Asked is how many requests the gate has let through. Read it when none is waiting.

func (*Gate) Hold

func (gate *Gate) Hold(path string) error

Hold has the gate keep its pace across runs, for this user on this machine. Its record at path holds when the last request began, and any time arXiv asked it to wait until; it is written after each request, so a run that is stopped keeps the pace it had.

A lock on a file beside the record stops a second run from asking while this one is. The system lets the lock go when the run ends, however it ends; Release writes the record and lets it go too.

It refuses while another run holds the lock, and a record it cannot read.

func (*Gate) Release

func (gate *Gate) Release() error

Release writes the record, so the next run keeps the pace from this one's last request and waits as long as arXiv asked, and lets the lock go. A gate that holds no record has nothing to release.

type ID

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

ID is a paper's name on arXiv, with the version asked for or found, or none. A new-style name is four digits of year and month, a dot and four or five digits: 1809.03507. An old-style one is an archive, perhaps a subject, a slash and seven digits: astro-ph/0602086.

func ParseID

func ParseID(written string) (*ID, error)

ParseID reads an id as people and papers write one. That is the name alone, after arXiv:, or in an abs or pdf address on arxiv.org, with a version or without. It refuses anything else before arXiv is asked, says what it was given, and gives nil beside the error.

An old-style name with a subject is read as arXiv names the paper, without it: math.GT/0309136 is math/0309136, the only name arXiv's API answers to.

func (ID) Holds

func (id ID) Holds(file string) bool

Holds is whether a file is the paper the id names: the version's own file, or, for an id without a version, the file of any version.

func (ID) String

func (id ID) String() string

String is the id as arXiv writes it: the name, then the version when there is one.

type Papers

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

Papers finds papers on arXiv, so many ids a query. Each query goes through the gate.

func New

func New(search Searcher, gate *Gate, most int) (*Papers, error)

New is papers found through a searcher and a gate, most ids a query. It refuses a missing searcher or gate, and fewer than one id a query.

func (*Papers) Look

func (papers *Papers) Look(ctx context.Context, ids []ID) (
	[]*celestialdata.Product, []ID, error)

Look is the papers the ids name, as products to fetch, and the ids arXiv has no paper for. Each paper is named for the version arXiv has: its latest, unless the id names one.

A version named twice, as 1809.03507 and 1809.03507v2 may, is found once. When a query fails, what was found before it comes back beside the error.

type Searcher

type Searcher interface {
	RawSearch(ctx context.Context,
		params library.SearchParams) (*http.Response, error)
}

Searcher is what papers are looked up through. It gives the API's answer raw, as the library's Client.RawSearch does.

func NewSearcher

func NewSearcher(address string, wait time.Duration) Searcher

NewSearcher is the library's client asking the API at an address, waiting so long for an answer. Its own pacing is off, since a Gate paces every request to arXiv, and so are its retries: a server that asks us to wait is waited on, not asked again.

Jump to

Keyboard shortcuts

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