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.
Metadata
Release files for numpyai 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| numpyai-0.4.0.tar.gz | 16.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| numpyai-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.1 kB
Release files / numpyai-0.4.0.tar.gz
| Download URL | numpyai-0.4.0.tar.gz |
|---|---|
| Size | 16.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a9642b05d22e22fe6e7680416f892106e4d8bad1dd441dfa296e5573d2d624a3
|
|
BLAKE2b-256 checksum How to use checksums |
f1fdace0aaf496956f4d7c4eecd917e7a9c4abd02d80e4d36297aa9c177fb892
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / numpyai-0.4.0-py3-none-any.whl
| Download URL | numpyai-0.4.0-py3-none-any.whl |
|---|---|
| Size | 17.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd81f9bdda936de73020dde06a305a80d7fc02ab68fb0c97e906f53cef9a4d43
|
|
BLAKE2b-256 checksum How to use checksums |
52cd25f989dc60386a1dc1b75805350c15ad365245429de922f86b448c764496
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|