Skip to content

Python Public API

The eigenvue Python package provides a high-level interface for listing algorithms, generating step sequences, launching interactive visualizations, and embedding them in Jupyter notebooks. All four public functions are importable directly from the top-level eigenvue module.

import eigenvue
Terminal window
pip install eigenvue

The package requires Python 3.10 or later.


Returns a list of all registered algorithms, optionally filtered by category.

def list(category: str | None = None) -> list[dict]
ParameterTypeRequiredDefaultDescription
categorystr | NoneNoNoneFilter by algorithm category. Valid values: "classical", "deep-learning", "generative-ai", "quantum". If None, returns all algorithms.

list[dict] — A list of dictionaries, each containing the algorithm metadata fields id, name, category, description, and complexity.

import eigenvue
# List all algorithms
all_algorithms = eigenvue.list()
for algo in all_algorithms:
print(f"{algo.id}: {algo.name} ({algo.category})")
# Filter by category
classical = eigenvue.list(category="classical")
genai = eigenvue.list(category="generative-ai")
[
{
"id": "binary-search",
"name": "Binary Search",
"category": "classical",
"description": {
"short": "Efficiently find a target in a sorted array by halving the search space.",
"long": "Binary search is a divide-and-conquer algorithm..."
},
"complexity": {
"time": "O(log n)",
"space": "O(1)",
"level": "beginner"
}
},
# ... more algorithms
]
ExceptionCondition
ValueErrorcategory is not one of the recognized category strings.

Launches an interactive visualization of the specified algorithm in a local web browser. Starts a lightweight local server on the given port and opens the algorithm page.

def show(
algorithm_id: str,
inputs: dict | None = None,
port: int | None = None,
) -> None
ParameterTypeRequiredDefaultDescription
algorithm_idstrYesThe URL-safe identifier of the algorithm (e.g., "binary-search", "self-attention").
inputsdict | NoneNoNoneCustom input parameters. Keys and values must match the algorithm’s input schema. If None, the algorithm’s default inputs from meta.json are used.
portint | NoneNoNonePort number for the local server. If None, an available port is selected automatically.

None — The function opens a browser window and blocks until the server is stopped (e.g., via Ctrl+C).

import eigenvue
# Launch with default inputs
eigenvue.show("binary-search")
# Launch with custom inputs
eigenvue.show("binary-search", inputs={
"array": [2, 4, 6, 8, 10, 12, 14, 16],
"target": 10,
})
# Specify a port
eigenvue.show("dijkstra", port=8080)
ExceptionCondition
ValueErroralgorithm_id is not a recognized algorithm identifier.
ValueErrorinputs does not conform to the algorithm’s input schema.
OSErrorThe specified port is already in use.
KeyboardInterruptThe user pressed Ctrl+C to stop the server (normal shutdown path).

The local server runs in a background thread. Calling show() from multiple threads concurrently is not supported. If you need multiple visualizations, open them sequentially or use jupyter() for notebook embedding.


Generates the complete step sequence for an algorithm without launching a visualization. Useful for programmatic analysis, testing, and building custom integrations.

def steps(
algorithm_id: str,
inputs: dict | None = None,
) -> list[dict]
ParameterTypeRequiredDefaultDescription
algorithm_idstrYesThe URL-safe identifier of the algorithm.
inputsdict | NoneNoNoneCustom input parameters. If None, the algorithm’s default inputs are used.

list[dict] — A list of step dictionaries conforming to the Step Format Specification. Each dictionary uses the same camelCase keys as the wire format, so the result can be serialised to JSON unchanged. The list is guaranteed to be non-empty, with the last step having isTerminal: True.

import eigenvue
# Generate steps with default inputs
result = eigenvue.steps("binary-search")
print(f"Total steps: {len(result)}")
# Inspect individual steps
for s in result:
print(f"Step {s['index']}: {s['title']}")
print(f" Phase: {s.get('phase', 'N/A')}")
print(f" Actions: {len(s['visualActions'])}")
# Generate with custom inputs
result = eigenvue.steps("bubble-sort", inputs={
"array": [5, 3, 8, 1, 2],
})
[
{
"index": 0,
"id": "init",
"title": "Initialize Binary Search",
"explanation": "Set left = 0, right = 9, searching for target 13.",
"state": {
"array": [1, 3, 5, 7, 9, 11, 13, 15, 17, 19],
"target": 13,
"left": 0,
"right": 9,
"mid": None,
},
"visualActions": [
{"type": "highlightRange", "from": 0, "to": 9, "color": "highlight"},
{"type": "movePointer", "id": "left", "to": 0},
{"type": "movePointer", "id": "right", "to": 9},
],
"codeHighlight": {"language": "pseudocode", "lines": [2, 3]},
"isTerminal": False,
"phase": "initialization",
},
# ... more steps
]

Step dictionaries keep the wire format’s camelCase keys — visualActions, codeHighlight, isTerminal — rather than being converted to snake_case. That keeps a step identical whether it came from the Python package, the npm package or the web app, so serialised output and cross-language fixtures compare directly. The package’s own function names and parameters follow Python convention; only the step payload preserves the wire format.

ExceptionCondition
ValueErroralgorithm_id is not a recognized algorithm identifier.
ValueErrorinputs does not conform to the algorithm’s input schema.
RuntimeErrorThe generator produced an invalid step sequence.

steps() is stateless and safe to call from multiple threads concurrently, provided each call operates on independent inputs. No global state is modified.


Renders an interactive visualization inline in a Jupyter notebook. Returns an IPython.display.IFrame that embeds the Eigenvue visualization.

def jupyter(
algorithm_id: str,
inputs: dict | None = None,
width: int = 960,
height: int = 600,
) -> IFrame
ParameterTypeRequiredDefaultDescription
algorithm_idstrYesThe URL-safe identifier of the algorithm.
inputsdict | NoneNoNoneCustom input parameters. If None, the algorithm’s default inputs are used.
widthintNo960Width of the embedded IFrame in pixels. Must be a positive integer.
heightintNo600Height of the embedded IFrame in pixels. Must be a positive integer.

IFrame — An IPython.display.IFrame object. In Jupyter notebooks, this renders automatically when returned as the last expression in a cell. It can also be displayed explicitly with IPython.display.display().

import eigenvue
# Basic usage -- returns an IFrame that renders in the notebook
eigenvue.jupyter("binary-search")
# Custom inputs and dimensions
eigenvue.jupyter(
"self-attention",
inputs={"tokens": ["The", "cat", "sat"]},
width=1200,
height=800,
)
# Explicit display
from IPython.display import display
iframe = eigenvue.jupyter("bubble-sort", inputs={"array": [5, 3, 8, 1, 2]})
display(iframe)
ExceptionCondition
ValueErroralgorithm_id is not a recognized algorithm identifier.
ValueErrorinputs does not conform to the algorithm’s input schema.
ValueErrorwidth or height is not a positive integer.
ImportErrorIPython is not installed (required for IFrame support).

This function requires a Jupyter-compatible environment (Jupyter Notebook, JupyterLab, Google Colab, or VS Code with the Jupyter extension). The IPython package must be installed. In non-Jupyter environments, use show() instead.


The current package version is accessible via:

import eigenvue
print(eigenvue.__version__) # "0.1.0"

All public functions validate their inputs eagerly and raise descriptive exceptions. The general pattern:

import eigenvue
try:
result = eigenvue.steps("nonexistent-algorithm")
except ValueError as e:
print(f"Invalid input: {e}")
except RuntimeError as e:
print(f"Generator failure: {e}")

All exceptions include the algorithm ID and a description of what went wrong.


show() and steps() check the inputs you pass against the algorithm’s declared input schema before running its generator, and raise ValueError if anything does not conform. Every algorithm publishes that schema in its meta.json under inputs.schema, and it is what the Algorithm Reference pages describe.

The checks are:

RuleExample message
Unknown parameterUnknown input 'targt'. Expected one of: array, target.
Missing parameterMissing required input 'array'.
Wrong typeInput 'array' must be an array, got string.
Out of rangeInput 'target' must be at most 999, got 5000.
Wrong lengthInput 'array' must have at least 1 item, got 0.
Not in the allowed setInput 'optimizer' must be one of: 'sgd', 'momentum', 'adam'. Got 'nope'.
Out of orderInput 'array' must be sorted in ascending order, but index 1 (3) is less than index 0 (5).

Passing no inputs at all uses the algorithm’s defaults, which always conform. A parameter documented as optional may be omitted; None counts as omitted.

Ordering matters more than it looks. Binary search on an unsorted array does not raise anything by itself — it returns a confidently wrong answer, which is the pitfall that algorithm’s own reference page warns about. Validating the input is what turns that into an error you can act on:

import eigenvue
try:
eigenvue.steps("binary-search", inputs={"array": [5, 3, 1, 9], "target": 9})
except ValueError as e:
print(e)
# Invalid inputs for 'binary-search':
# - Input 'array' must be sorted in ascending order, but index 1 (3) is less than index 0 (5).

The npm package applies the same rules and reports the same messages; a cross-language test compares the two implementations case by case.