Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatic access to On-Line Encyclopedia of Integer Sequences

Is there a way to search and retrieve the results from On-Line Encyclopedia of Integer Sequences (http://oeis.org) programmatically?

I have searched their site and the results are always returned in html. They do not seem to provide an API but in the policy statement they say its acceptable to access the database programmatically. But how to do it without screen scraping?

Thanks a lot for your help.

like image 316
nabeelmukhtar Avatar asked May 13 '11 12:05

nabeelmukhtar


People also ask

What is OEIS used for?

The main use for the OEIS is to identify a number sequence that you have come across, perhaps in your work, while reading a book, or in a quiz, etc. For example, you discover what you think may be a new algorithm for checking that a file of medical records is in the correct order.

How do you cite OEIS?

Referencing the OEIS (2022), The On-Line Encyclopedia of Integer Sequences, Published electronically at http://oeis.org. To reference a particular sequence, use one of these forms: OEIS Foundation Inc. (2022), The Catalan numbers, Entry A000108 in The On-Line Encyclopedia of Integer Sequences, http://oeis.org/A000108.

Which sequence is not in OEIS?

8795, 9935, 11147, 11446, 11612, 11630 were the first integers not appearing in any OEIS sequence, 8267 and 9734 were the first integers lower than 10000 appearing only once, 7495, 8758 and 9820 appeared in 2 sequences.


2 Answers

The OEIS now provides several points of access, not just ones using their internal format. These seem largely undocumented, so here are all of the endpoints that I have found:


https://oeis.org/search?fmt=json&q=<sequenceTerm>&start=<itemToStartAt> 

Returns a JSON formatted response of the results found from the sequenceTerm given. If too many results were returned, count will be > 0 whilst results will be null. If no results were returned, count will be 0. itemToStartAt is used for pagination of results, as only a maximum of 10 are ever returned. This starts at 0. If you wanted to return a second page of results, this would equal 10. Information about what each of the entries means can be found here.


https://oeis.org/search?fmt=text&q=<sequenceTerm>&start=<itemToStartAt> 

Exactly the same arguments as before, however this returns it in the OEIS internal format. Which is largely written about here. Unless your project requires it, I'd highly recommend using the JSON format over this.


https://oeis.org/search?fmt=<json|text>&q=id:A<sequenceNumber> 

Will return a single result if the sequenceNumber is found. This is the suggested method for obtaining single sequences, as it appears to be far more optimised than some of the alternative methods that can be used as queries. Requests often take under a second. Alternative search query methods can be found on this page.


https://oeis.org/A<sequenceNumber>/graph?png=1 

This endpoint can be used to grab the images used to graph the data points. Alternatively, setting png to equal to zero returns the HTML page containing a graph of it.


https://oeis.org/recent.txt 

This returns a list of recently updated entries in the OEIS internal format. There are no parameters available, or JSON format, as this seems like a static text file that is simply being served to the client. Due to the length of replies from the OEIS database (for some sequences replies can take above five seconds), I'd highly recommend heavily caching requests and using the above endpoint to update them when they change.

like image 143
Alexander Craggs Avatar answered Sep 22 '22 14:09

Alexander Craggs


A URL of the form http://oeis.org/search?fmt=text&q=2,5,14,50,233 gives a nicely formatted text output.

But it seems there is no way to get a single sequence in text form.

like image 27
nabeelmukhtar Avatar answered Sep 22 '22 14:09

nabeelmukhtar