Skip to main content

NumpyAI logo

NumpyAI

A natural-language interface for NumPy, powered by LLMs.

NumpyAI lets you interact with NumPy arrays using plain English. It ships as a small, provider-agnostic library built on top of Pydantic AI - so you can plug in Google Gemini, OpenAI, Anthropic, or any other model Pydantic AI supports without touching the library code.

Features

  • Ask questions in English; NumpyAI generates and executes NumPy code for you.
  • numpyai.Diagnosis suggests analysis steps for your data.
  • numpyai.NumpyAISession chats over multiple arrays at once.
  • Generated code is syntax-checked and independently validated before returning.
  • Automatic retries with error context.
  • Verbose mode (verbose=True) prints every intermediate step.
  • Provider-agnostic - any Pydantic AI model spec works.

Installation

pip install "numpyai[all]"

Or install only the providers you need:

pip install "numpyai[google]"    # Google Gemini
pip install "numpyai[openai]"    # OpenAI
pip install "numpyai[anthropic]" # Anthropic Claude

From source

git clone https://github.com/AadyaChinubhai/numpyai
cd numpyai
pip install -e ".[all,dev]"

Setup

Set the API key for your chosen provider. Pydantic AI reads standard env vars:

Provider Environment variable
Google GEMINI_API_KEY
OpenAI OPENAI_API_KEY
Anthropic ANTHROPIC_API_KEY
export GEMINI_API_KEY=...

Usage

Single array

import numpy as np
import numpyai as npi

data = np.array([[1, 2, 3, 4, 5, np.nan], [np.nan, 3, 5, 3.1415, 2, 2]])
arr = npi.array(data)  # defaults to google:gemini-2.5-flash

print(arr.chat("Compute the height and width of the image using NumPy."))
# Expected output: (2, 6)

Choosing a model

Pass any Pydantic AI model spec via model=:

npi.array(data, model="anthropic:claude-sonnet-4-5")
npi.array(data, model="openai:gpt-4o")
npi.array(data, model="google:gemini-2.5-pro")

You can also pass a pre-configured pydantic_ai.models.Model instance for full control.

Multiple arrays

import numpy as np
import numpyai as npi

arr1 = np.array([[1, 2, 3], [4, 5, 6]])
arr2 = np.random.random((2, 3))

sess = npi.NumpyAISession([arr1, arr2])
imputed = sess.chat("Impute the first array with the mean of the second array.")

Diagnosis

sess = npi.NumpyAISession([arr1, arr2])
diag = npi.Diagnosis(sess)
steps = diag.steps(
    task="Give me exactly 7 pithy steps to select an ML model for this data."
)

Supported LLM providers

Anything Pydantic AI supports - Google (Gemini), OpenAI, Anthropic, Groq, Mistral, Ollama, and OpenAI-compatible endpoints. See the Pydantic AI model docs for the full list.

Contributing

  • Format with black and lint with ruff.
  • Add tests under tests/.
  • Public API surface (array, NumpyAISession, Diagnosis) should stay stable.

License

MIT - see LICENSE.

Download files

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

Source Distribution

numpyai-0.4.0.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

numpyai-0.4.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file numpyai-0.4.0.tar.gz.

File metadata

  • Download URL: numpyai-0.4.0.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for numpyai-0.4.0.tar.gz
Algorithm Hash digest
SHA256 a9642b05d22e22fe6e7680416f892106e4d8bad1dd441dfa296e5573d2d624a3
MD5 45366f083d76065b51872832c9c785e4
BLAKE2b-256 f1fdace0aaf496956f4d7c4eecd917e7a9c4abd02d80e4d36297aa9c177fb892

See more details on using hashes here.

File details

Details for the file numpyai-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: numpyai-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for numpyai-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd81f9bdda936de73020dde06a305a80d7fc02ab68fb0c97e906f53cef9a4d43
MD5 74c3454cceed4890b201fc12cad7893d
BLAKE2b-256 52cd25f989dc60386a1dc1b75805350c15ad365245429de922f86b448c764496

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 files

0.2.0

1 file

Supported by

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