# API

## `OEISClient` objects

class `client.` `OEISClient`

  Maintains a `Session` [http://docs.python-requests.org/en/latest/api/#requests.Session] and contains all methods for querying the OEIS.

  `get_by_id`(id)

    Returns a `Sequence` for the sequence with the ID id, or else raises `NoResultsError`.

    Note

    On the OEIS website, IDs are displayed with an uppercase letter and 6 (for A IDs) or 4 (for M and N IDs) digits. However, this method does not require an uppercase letter or leading zeros to be used.

  `lookup_by_name`(name, max_seqs=10)

    Returns a list of at most max_seqs `Sequence` objects whose names contain name.

    Note

    Sequences are retrieved in sets of 10 and sequences are then removed if necessary. So, there is no speed improvement between, for example, a max_seqs of 10 and one of 15. This applies to all methods with a max_seqs argument.

  `lookup_by_author`(author, max_seqs=10)

    Returns a list of at most max_seqs `Sequence` objects whose authors contain author.

  `lookup_by`(prefix, query, max_seqs=10, list_func=False)

    If prefix is “”, search OEIS with string query, otherwise use string ‘prefix:query‘.

    If list_func is true, return a list of at most max_seqs `Sequence` objects or else an empty list if there are no results. If list_func is false, return the first Sequence found, or else raise a `NoResultsError`.

  `lookup_by_keywords`(keywords)

    Returns a list of at most max_seqs `Sequence` objects which are tagged with keywords.

  `lookup_by_terms`(terms, **kwargs)

    Returns a list of at most max_seqs `Sequence` objects which contain terms anywhere within them. If none exist, returns an empty list. If ordered is false, terms may be in any order. If signed is false, terms may be positive or negative.

## `Sequence` objects

class `sequence.` `Sequence`(sequence_entry)

  Takes internal format sequence entry as constructor argument.

  Has attributes to contain information for each field of a sequence entry in the OEIS and methods fot retrieving a certain number of the sequence’s signed or unsigned terms.

  `generate`(n)

    If a parsable formula exists, returns the nth term of the sequence, else raises a `NoFunctionError`.

  `signed`(n)

    Returns the first n signed integers in the sequence.

  `unsigned`(n)

    Returns the first n unsigned integers in the sequence.

### Attributes

id | The sequence’s unique ID in the OEIS, as a string. Begins ‘A’.
alt_ids | Other IDs, as a list of strings beginning ‘M’ and ‘N’ which the sequence carried in the “The Encyclopedia of Integer Sequences”, 1995 or the “Handbook of Integer Sequences”, 1973, respectively.
unsigned_list | A list of terms in the sequence without any minus signs.
signed_list | A list of terms in the sequence including any minus signs.
name | The name of the sequence, as a string.
references | A list of references to the sequence.
links | A list of links about the sequence.
formulae | Formulae for generating the sequence, as a list of strings.
cross_references | Cross-references to the sequence from elsewhere in the OEIS, as a list of strings.
author | The author of the sequence entry, as a string.
offset | The subscript of the first term and the position of the first term whose modulus exceeds 1, as a tuple of two numbers.
errors | Errors in the sequence entry, as a list of strings.
examples | Examples to illustrate the sequence, as a list of strings.
maple | Maple code to generate the sequence, as a string.
mathematica | Mathematica code to generate the sequence, as a string.
other_programs | Code to generate the sequence in other programs/languages, as a list of strings.
keywords | The sequence’s keywords, as a list of strings.
comments | Comments on the sequence entry, as a list of strings.

More information about the fields in a sequence entry can be found here [http://oeis.org/eishelp2.html].

## `Errors`

exception `errors.` `InvalidQueryError`(response)

  Raised when a search is invalid according to the OEIS search syntax.

exception `errors.` `MalformedSequenceError`(malformed_line)

  Raised when a sequence entry does not contain the required information in a parsable format.

exception `errors.` `NoFunctionError`(seq)

  Raised when a sequence has no formula.

exception `errors.` `NoResultsError`(query)

  Raised when a search gives no results and it is unacceptable to return an empty list.

exception `errors.` `OEISException`

  Base class for PyOEIS exceptions.

exception `errors.` `TooManyResultsError`(query)

  Raised when too many results are found for a search for them to be properly parsed.