Skip to main content

A Python toolkit for programmatic access, analysis, and visualization of integer sequences from the OEIS (Online Encyclopedia of Integer Sequences).

Project description

oeis-tools

CI codecov PyPI version Python versions Wheel Package format License: MIT

A focused Python toolkit for working with OEIS integer sequences: fetch metadata, parse b-files, and plot sequence values quickly.

Features

  • Validate OEIS IDs like A000045
  • Build canonical OEIS URLs and b-file names
  • Fetch sequence JSON metadata via Sequence
  • Fetch and parse b-file numeric data via BFile
  • Plot b-file values with line or scatter styles

Requirements

  • Python 3.9+
  • Optional: matplotlib for plotting

Installation

pip install oeis-tools

For local development:

git clone https://github.com/oeistools/oeis-tools.git
cd oeis-tools
pip install -e ".[dev]"

Quick Start

Utility Functions

import oeis_tools as ot

print(ot.check_id("A000045"))                # True
print(ot.oeis_bfile("A000045"))              # b000045.txt
print(ot.oeis_url("A000045"))                # https://oeis.org/A000045
print(ot.oeis_url("A000045", fmt="json"))    # https://oeis.org/search?q=id:A000045&fmt=json

Sequence API

from oeis_tools import Sequence

seq = Sequence("A000045")

print(seq.id)         # A000045
print(seq.name)       # Fibonacci numbers
print(seq.data)       # [0, 1, 1, 2, 3, 5, ...]
print(seq.author)     # list[str]
print(seq.keyword)    # list[str]
print(seq.offset)     # list[int]
print(seq.link)       # parsed links as markdown-style text

info = seq.get_bfile_info()
print(info["available"], info["length"])

B-file API

from oeis_tools import BFile

bfile = BFile("A000045")

print(bfile.get_filename())   # b000045.txt
print(bfile.get_url())        # https://oeis.org/A000045/b000045.txt
print(bfile.get_bfile_data()) # list[int] or None
bfile.plot_data(50, show=False)                                # first 50 points
bfile.plot_data(50, show=False, plot_style="scatter")          # scatter plot
bfile.plot_data(50, show=False, plot_style="joined")           # joined/line plot
ax = bfile.plot_data(show=False, return_ax=True)               # matplotlib Axes

Plotting Examples

Overlay two sequences on one plot:

import matplotlib.pyplot as plt
import oeis_tools

N_POINTS = 200

bfile = oeis_tools.BFile("A114906")
bfile2 = oeis_tools.BFile("A114904")
fig, ax = plt.subplots()
bfile.plot_data(n=N_POINTS, ax=ax, show=False, color="red")
bfile2.plot_data(n=N_POINTS, ax=ax, show=True, color="blue")
plt.show()

Scatter versus joined:

import matplotlib.pyplot as plt
from oeis_tools import BFile

bfile = BFile("A000045")
fig, ax = plt.subplots()
bfile.plot_data(80, ax=ax, show=False, plot_style="scatter", color="black")
bfile.plot_data(80, ax=ax, show=False, plot_style="joined", color="orange")
plt.show()

API Summary

  • check_id(oeis_id: str) -> bool
  • oeis_bfile(oeis_id: str) -> str
  • oeis_url(oeis_id: str, fmt: str | None = None) -> str
  • Sequence(oeis_id: str)
  • Sequence.get_bfile_info() -> dict
  • BFile(oeis_id: str)
  • BFile.get_filename() -> str
  • BFile.get_url() -> str
  • BFile.get_bfile_data() -> list[int] | None
  • BFile.plot_data(n: int | None = None, show: bool = True, ax=None, return_ax: bool = False, plot_style: str = "line", **plot_kwargs)

Error Behavior

  • Sequence(...) raises ValueError for invalid IDs.
  • Sequence(...) propagates HTTP errors from the OEIS JSON endpoint.
  • BFile.get_bfile_data() returns None when a b-file cannot be fetched or parsed.

Development

Run tests:

pytest -q

Run lint checks:

ruff format .
ruff check . --fix

Build distributions:

python -m build
python -m twine check dist/*

Contribution guide: see CONTRIBUTING.md.

Publishing

This repository includes a GitHub Actions publish workflow at .github/workflows/publish.yml.

  • Automatic publish trigger: GitHub Release published
  • Manual publish trigger: workflow_dispatch
  • Upload target: PyPI via trusted publishing (id-token)

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oeis_tools-0.2.0.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oeis_tools-0.2.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file oeis_tools-0.2.0.tar.gz.

File metadata

  • Download URL: oeis_tools-0.2.0.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for oeis_tools-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b44758bd4f3e2f478aa4e9e283b20f2e454377a33ee97ea07b579072ad18f001
MD5 e7a08fcfc9b553f497cdbeef23604d6b
BLAKE2b-256 689e98c4197c90f426b8601c96f5b6ca6023cba2a630455719a30afb4fc4d05c

See more details on using hashes here.

Provenance

The following attestation bundles were made for oeis_tools-0.2.0.tar.gz:

Publisher: publish.yml on oeistools/oeis-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oeis_tools-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: oeis_tools-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for oeis_tools-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d97528605ab4605d05e8383bcb2bb62ae913ae6d8fee382259b83e4d82dde881
MD5 fb2fe3167c4753d0b2224576b81100ff
BLAKE2b-256 a29218852a79e1d1590b5f90c1b45c89ebdb37f0142618c6e892b51247f718b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for oeis_tools-0.2.0-py3-none-any.whl:

Publisher: publish.yml on oeistools/oeis-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page