Code Monkey home page Code Monkey logo

arxiv.py's Introduction

arxiv.py

Python wrapper for the arXiv API: http://arxiv.org/help/api/index

About arXiv

arXiv is a project by the Cornell University Library that provides open access to 1,000,000+ articles in Physics, Mathematics, Computer Science, Quantitative Biology, Quantitative Finance, and Statistics.

They have an API that uses ATOM feeds to serve simple database queries. Unfortunately, handling these ATOM requsts can be clumsy (especially given inconsistency in data between different result objects, even in the same query). This is where arxiv.py comes it: it constructs requests for arXiv and gets ATOM feeds via a simple handful of methods, and parses the results into an intuitive format.

Usage

Installation

$ pip install arxiv

In your Python script, include the line

import arxiv

Query

arxiv.query(search_query, id_list, prune, start, max_results, sort_by, sort_order)
Argument Type Default Required?
search_query string "" No
id_list list of strings [] No
start int 0 No
max_results int 10 No
sort_by string "relevance" No
sort_order string "descending" No
  • search_query is a query string; details of its usage are documented here.
  • id_list contains arXiv record IDs (typically of the format "0710.5765v1")
  • start is the result offset for paging through a long query result. If set to 0, the API response will begin with the first result; if set to 10, the API response will begin with the 11th.
  • max_results is the maximum number of results per query.

All of these arguments are documented more comprehensively in the arXiv API documentation.

Query examples:

import arxiv
# Keyword search
arxiv.query(search_query="quantum")
# Get single record by ID
arxiv.query(id_list=["1707.08567"])
# Get multiple records by ID
arxiv.query(id_list=["1707.08567", "1707.08567"])

For a more detailed description of the interaction between search_query and id_list, see this section of the arXiv documentation.

Download PDF

arxiv.download(obj, dirname, prepend_id, slugify)
Argument Type Default Required?
obj dict N/A Yes
dirname string "./" No
prepend_id boolean False No
slugify boolean False No
  • obj is a result object, one of a list returned by query(). This function looks up keys pdf_url and title in obj to make the download request.
  • dirname is the relative directory path to which the downloaded PDF will be saved. It defaults to the present working directory.
  • When prepend_id is True, the arXiv record ID will be prepended to the download filename.
  • When slugify is True, the paper title will be stripped of non-alphanumeric characters before being used as a filename.

Download PDF examples:

import arxiv
# Query for a paper of interest, then download
paper = arxiv.query(id_list=["1707.08567"])[0]
arxiv.download(paper)
# You can skip the query step if you have the paper info!
paper2 = {"pdf_url": "http://arxiv.org/pdf/1707.08567v1",
          "title": "The Paper Title"}
arxiv.download(paper2)

arxiv.py's People

Contributors

jacquerie avatar japoneris avatar lukasschwab avatar mdamien avatar msoelch avatar natfarleydev avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.