Stateful natural-language → pandas/matplotlib, offline-first.
Project description
speak2py v0.3.1 — English → Python (stateful, optional offline AI)
Turn plain English into executable Python. Works out-of-the-box for common data tasks; add a tiny local model (one-time download) to unlock AI code generation — no keys, no cloud.
TL;DR Quickstart
pip install speak2py
from speak2py import speak2py
# Zero-setup (no AI needed)
df = speak2py('read "data/iris.csv" and head 5')
# With AI (optional; see “Enable AI”)
out = speak2py('create a function is_prime(n); return {n:is_prime(n) for n in [2,3,4,17]}')
print(out) # -> {2: True, 3: True, 4: False, 17: True}
Why speak2py?
- Data basics, instantly —
read/head/describe/histogramwithout setup. - Stateful steps — name results (e.g.,
... as orders) and reference them later. - Charts — ask for a plot, get a PNG file path back.
- Any Python (optional AI) — generate & run small functions locally in a sandbox.
- Offline — no API keys, no cloud, runs on your machine.
Installation
pip install speak2py
Then immediately:
from speak2py import speak2py
print(speak2py('read "data/iris.csv" and describe'))
Enable AI (optional, no build)
AI mode lets you ask for “any code”, not just data tasks. speak2py uses a tiny local llama.cpp server and a small GGUF model.
- Model (GGUF) — e.g., TinyLlama (fast on CPU)
- Server binary —
llama-server(.exe)that runs locally - You do not compile anything.
Option A — One-time auto-download (recommended)
Set these once, then run any speak2py(...). Files are cached under your user folder and the server starts automatically.
Windows (PowerShell):
$env:SPEAK2PY_MODEL_URL = "https://huggingface.co/datasets/Varunpulipati/speak2py-assets/resolve/main/default.gguf"
$env:SPEAK2PY_LLAMA_SERVER_URL = "https://huggingface.co/datasets/Varunpulipati/speak2py-assets/resolve/main/win/llama-server.exe"
python -c "from speak2py import speak2py; print(speak2py('1'))"
macOS / Linux:
Provide a macOS/Linux llama-server URL when available. Until then, use Option B to copy a local binary.
export SPEAK2PY_MODEL_URL="https://…/default.gguf"
export SPEAK2PY_LLAMA_SERVER_URL="https://…/llama-server"
python -c "from speak2py import speak2py; print(speak2py('1'))"
After the first run, no internet or keys are required. The local server starts automatically whenever you call speak2py(...).
Option B — Manual copy (also simple)
Place the two files yourself:
Model →
- Windows:
%USERPROFILE%\.cache\speak2py\models\default.gguf - macOS/Linux:
~/.cache/speak2py/models/default.gguf
Server binary →
- Windows:
%USERPROFILE%\.cache\speak2py\runtime\llama-server.exe - macOS/Linux:
~/.cache/speak2py/runtime/llama-server(thenchmod +x ~/.cache/speak2py/runtime/llama-server)
Then just use speak2py(...) — AI is on.
Examples
Data (no AI required)
from speak2py import speak2py
speak2py('read "data/orders.csv" as orders and head 10')
speak2py('filter orders where status == "shipped" and amount > 100 as shipped_big')
speak2py('group shipped_big by region and sum amount as totals')
png = speak2py('plot a bar chart of totals_amount by region from totals')
print(png) # -> path to saved image
Any Python (with AI enabled)
speak2py('create a function fib(n); return [fib(i) for i in range(8)]')
speak2py('make a function is_palindrome(s); result = [is_palindrome(x) for x in ["aba","abc","abba"]]')
Prefer to see the code without running it?
from speak2py import speak2py_code
code = speak2py_code('write a function fizzbuzz(n) and set result = [fizzbuzz(i) for i in range(1,21)]')
print(code)
Configuration (env vars)
| Variable | Default | Purpose |
|---|---|---|
SPEAK2PY_MODEL_URL |
— | URL to a .gguf model for auto-download (Option A). |
SPEAK2PY_LLAMA_SERVER_URL |
— | URL to llama-server binary for auto-download (Option A). |
SPEAK2PY_LLAMA_PORT |
11435 |
Port for local llama.cpp server. |
SPEAK2PY_MAX_TOKENS |
256 |
Upper bound on AI generation length. |
SPEAK2PY_HTTP_TIMEOUT |
180 |
Timeout (s) for local server requests. |
Tips: On slow CPUs, try SPEAK2PY_MAX_TOKENS=200. Behind a proxy? Set HTTP(S)_PROXY before the first run.
Security model (sandbox)
- Generated code runs with a strict allowlist (no arbitrary imports, file system, OS, or network).
- The final value must be assigned to
resultto be returned. - If unsafe operations are attempted, the sandbox will block and return code instead of executing it.
Troubleshooting
- “Model not found at …/default.gguf” — Provide the model (Option A env vars or Option B manual copy).
- “Server binary not found at …/llama-server(.exe)” — Same—provide the server URL/file.
- “invalid magic … expected GGUF” — Your download isn’t a real GGUF (likely an HTML login page). Re-download; first 4 bytes should be
GGUF. - Slow results — Keep the TinyLlama default and set
SPEAK2PY_MAX_TOKENS=200. - Code returned instead of running — The sandbox blocked execution or the model wrapped output. Try again with: “assign the final value to result and no extra text”.
Release maintainer notes (not for end users)
Host two files somewhere static (e.g., Hugging Face Dataset):
default.gguf and llama-server(.exe)
Then document those URLs for SPEAK2PY_MODEL_URL and SPEAK2PY_LLAMA_SERVER_URL.
Windows URLs used today:
- Model: https://huggingface.co/datasets/Varunpulipati/speak2py-assets/resolve/main/default.gguf
- Server (Windows): https://huggingface.co/datasets/Varunpulipati/speak2py-assets/resolve/main/win/llama-server.exe
For macOS/Linux, add corresponding mac/llama-server and/or linux/llama-server and document those URLs.
Contributing
Contributions welcome! Please open an issue or submit a pull request.
License
MIT © 2025 Speak2Py Contributors
Project details
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 speak2py-0.3.1.tar.gz.
File metadata
- Download URL: speak2py-0.3.1.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10f760a59ff3d5c7876145a66cf98ea5adba9d2bf90d2cee474d0379bd202fca
|
|
| MD5 |
8d436b6f0cba4ec4f899daf584069d6a
|
|
| BLAKE2b-256 |
2f454381e323e2155ec9336a5e48957025357d1fb954fb14f63395c1286d8d31
|
File details
Details for the file speak2py-0.3.1-py3-none-any.whl.
File metadata
- Download URL: speak2py-0.3.1-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f53f60ad16eee5ac357aa85d9f40202ce605c83a4abd1258f613bb390fc7d4d
|
|
| MD5 |
bb26a859205e8e905282d03fbedfe99c
|
|
| BLAKE2b-256 |
7b77ba20232927cbbcf1e32ab13c4773f031299a34a354e7e5ec75f6b0f43e94
|