Stateful natural-language → pandas/matplotlib, offline-first.
Project description
speak2py v0.3.0— 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 full AI code generation — no keys, no cloud.
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” below):
out = speak2py('create a function is_prime(n); return {n:is_prime(n) for n in [2,3,4,17]}')
What you can do
Data basics (no setup): read / head / describe / histogram
Follow-ups that remember state: as orders, then reference orders later
Charts: returns a PNG file path when you ask for plots
Any Python code (with AI on): generate & run small functions/algorithms safely
Install pip install speak2py
That’s it. You can immediately do:
from speak2py import speak2py print(speak2py('read "data/iris.csv" and describe'))
Enable AI (optional, no build)
AI lets you ask for “any code” (not just data). To keep setup painless, speak2py looks for two files in your user cache and will also auto-download them if you give it URLs:
A small model (GGUF), e.g. TinyLlama (fast on CPU)
A tiny server binary (llama-server) that runs locally
You do not compile anything.
Option A — One-time auto-download (recommended)
Set these two environment variables to URLs you control (e.g., from your GitHub Release or shared drive) and run any speak2py command once. The library will download the files to your cache and start the local server automatically.
Windows (PowerShell):
$env:SPEAK2PY_MODEL_URL="https:///default.gguf" $env:SPEAK2PY_LLAMA_SERVER_URL="https:///llama-server.exe" python -c "from speak2py import speak2py; print(speak2py('1'))"
macOS/Linux (bash):
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 this first run, no internet or keys are required. The server starts automatically in the background whenever you call speak2py(...).
Option B — Manual copy (also simple)
If you don’t want auto-download, just 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 (and chmod +x)
Then use speak2py(...) — the AI is on.
Examples Data (no AI required) 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)
How it works (short)
Fast path (no AI): a tiny parser handles read/head/describe/hist and returns DataFrames/plots quickly.
AI path (local): speak2py talks to a local llama.cpp server running the small GGUF model. No network, no keys.
Safe sandbox: the generated code runs with a strict allowlist (no imports/OS/network). Final value must be result.
Tips & knobs (optional)
Slow CPU? Use a smaller model and shorter generations:
optional
set SPEAK2PY_MAX_TOKENS=200 # Windows (PowerShell: $env:SPEAK2PY_MAX_TOKENS="200") export SPEAK2PY_MAX_TOKENS=200 # macOS/Linux
If your IT blocks downloads, do Option B (manual copy).
Default server port is 11435. To change:
set SPEAK2PY_LLAMA_PORT=11436 # Windows export SPEAK2PY_LLAMA_PORT=11436 # macOS/Linux
Troubleshooting (plain English)
“Model not found at …/default.gguf” You haven’t provided the model yet. Use Option A (auto-download env vars) or Option B (manual copy).
“Server binary not found at …/llama-server(.exe)” Same as above: either set the download URL env var or copy the file to the runtime path.
It’s slow Use a smaller GGUF (e.g., TinyLlama “instruct”, Q4) and keep SPEAK2PY_MAX_TOKENS around 200.
“invalid magic … expected GGUF” Your model file is not a real GGUF (probably an HTML page). Re-download the model and make sure the first 4 bytes spell GGUF.
FAQ
Do I need to build anything? No. You either let speak2py auto-download a tiny server + model once, or you copy two files into your user cache. That’s it.
Do I need API keys? No. It runs locally.
Will this hit the internet after first run? No. After the one-time download (or manual copy), everything is local.
Can I still use speak2py without AI? Yes. The data basics work immediately after pip install.
Release maintainer notes (not for end users)
Host two files in your GitHub Release (or any static URL): default.gguf and llama-server(.exe) Then document those URLs for SPEAK2PY_MODEL_URL and SPEAK2PY_LLAMA_SERVER_URL.
If you prefer to bundle them in the wheel, place them on install and skip URLs entirely (bigger package size).
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.0.tar.gz.
File metadata
- Download URL: speak2py-0.3.0.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e74ec76bf66ead1ad59f5bdfa33961ed26fb8e589195220ab12bc095e7c171af
|
|
| MD5 |
6f4c7535c3be76c187e2b153fae673cb
|
|
| BLAKE2b-256 |
9860893a1fe5889a6d348a6ce8fcfca763e7853e547ddcab1b2cbcab7e31fd52
|
File details
Details for the file speak2py-0.3.0-py3-none-any.whl.
File metadata
- Download URL: speak2py-0.3.0-py3-none-any.whl
- Upload date:
- Size: 14.4 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 |
64888b5b306cb9cf16af85f6b64a069c9bd611b97143c1191d76884e3a61d85b
|
|
| MD5 |
701b251c7995942dfddeb5b95bf44998
|
|
| BLAKE2b-256 |
629d97e4d7eba398ddab17b389965ee8308819481f89fb97f1a6ab0c5259a03e
|