arxiv

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 15 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 it asked for that has not passed. Such an error is a *web.Stopped.

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.

A 403, 429 or 503 is arXiv asking us to stop, and the request says so, with the wait asked.

It refuses a missing context, web or gate.

Types

type Clock

type Clock = web.Clock

Clock is the time a gate keeps. It is the web package's, so a clock made for either is a clock for both.

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 at least its pace after the one before began, and none while arXiv has asked to be left alone. It keeps the web package's gentle, asked for arXiv by its numbers. The gentle is not exported: a caller asks through the gate.

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, and any wait arXiv asked for, in a record at path. The record is written after each request begins, so a run that is stopped keeps the pace it had; Release writes it again and lets the lock go.

It refuses while another run holds the lock, and a record it cannot read. See web.Gentle.Hold, which keeps the record. Those two are refusals; a folder or file that will not open is given as it came.

func (*Gate) Insist added in v0.0.4

func (gate *Gate) Insist(say io.Writer) error

Insist has the gate ask arXiv anyway, for this run. What arXiv asked for is written to say before the request goes. It refuses a missing writer, since what is overridden must be said.

func (*Gate) Release

func (gate *Gate) Release() error

Release writes the record again and lets the lock go, so the next run may ask. A gate that holds no record has nothing to write.

func (*Gate) Say added in v0.0.4

func (gate *Gate) Say(say io.Writer)

Say gives the gate a writer for saying what it cannot keep, such as a record that will not write. With none it stays quiet and goes on.

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