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.Diagnosissuggests analysis steps for your data.numpyai.NumpyAISessionchats 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 |
|---|---|
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
blackand lint withruff. - 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9642b05d22e22fe6e7680416f892106e4d8bad1dd441dfa296e5573d2d624a3
|
|
| MD5 |
45366f083d76065b51872832c9c785e4
|
|
| BLAKE2b-256 |
f1fdace0aaf496956f4d7c4eecd917e7a9c4abd02d80e4d36297aa9c177fb892
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd81f9bdda936de73020dde06a305a80d7fc02ab68fb0c97e906f53cef9a4d43
|
|
| MD5 |
74c3454cceed4890b201fc12cad7893d
|
|
| BLAKE2b-256 |
52cd25f989dc60386a1dc1b75805350c15ad365245429de922f86b448c764496
|