A Python toolkit for programmatic access, analysis, and visualization of integer sequences from the OEIS (Online Encyclopedia of Integer Sequences).
Project description
oeis-tools
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:
matplotlibfor 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) -> booloeis_bfile(oeis_id: str) -> stroeis_url(oeis_id: str, fmt: str | None = None) -> strSequence(oeis_id: str)Sequence.get_bfile_info() -> dictBFile(oeis_id: str)BFile.get_filename() -> strBFile.get_url() -> strBFile.get_bfile_data() -> list[int] | NoneBFile.plot_data(n: int | None = None, show: bool = True, ax=None, return_ax: bool = False, plot_style: str = "line", **plot_kwargs)
Error Behavior
Sequence(...)raisesValueErrorfor invalid IDs.Sequence(...)propagates HTTP errors from the OEIS JSON endpoint.BFile.get_bfile_data()returnsNonewhen 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b44758bd4f3e2f478aa4e9e283b20f2e454377a33ee97ea07b579072ad18f001
|
|
| MD5 |
e7a08fcfc9b553f497cdbeef23604d6b
|
|
| BLAKE2b-256 |
689e98c4197c90f426b8601c96f5b6ca6023cba2a630455719a30afb4fc4d05c
|
Provenance
The following attestation bundles were made for oeis_tools-0.2.0.tar.gz:
Publisher:
publish.yml on oeistools/oeis-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oeis_tools-0.2.0.tar.gz -
Subject digest:
b44758bd4f3e2f478aa4e9e283b20f2e454377a33ee97ea07b579072ad18f001 - Sigstore transparency entry: 1338653853
- Sigstore integration time:
-
Permalink:
oeistools/oeis-tools@4111a1662b3dabf97fd6a8a5804622fa83d9540b -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/oeistools
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4111a1662b3dabf97fd6a8a5804622fa83d9540b -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d97528605ab4605d05e8383bcb2bb62ae913ae6d8fee382259b83e4d82dde881
|
|
| MD5 |
fb2fe3167c4753d0b2224576b81100ff
|
|
| BLAKE2b-256 |
a29218852a79e1d1590b5f90c1b45c89ebdb37f0142618c6e892b51247f718b4
|
Provenance
The following attestation bundles were made for oeis_tools-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on oeistools/oeis-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oeis_tools-0.2.0-py3-none-any.whl -
Subject digest:
d97528605ab4605d05e8383bcb2bb62ae913ae6d8fee382259b83e4d82dde881 - Sigstore transparency entry: 1338653861
- Sigstore integration time:
-
Permalink:
oeistools/oeis-tools@4111a1662b3dabf97fd6a8a5804622fa83d9540b -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/oeistools
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4111a1662b3dabf97fd6a8a5804622fa83d9540b -
Trigger Event:
release
-
Statement type: