npmai-fast
Zero-dependency AST-to-native compiler for hot numeric Python functions.
from npmai_fast import optimize
@optimize
def total(a: int, b: int) -> int:
result = 0
for i in range(a):
result += b
return result
Just decorate and call. No config, no build step you have to run yourself.
What actually happens
On first call, the function's source is analyzed. If it fits the
compilable numeric subset (int/float params and return, arithmetic,
comparisons, if/while/for-range loops — see below), it is transpiled to
C++20, compiled once with whatever compiler is on your machine (g++,
clang++, or MSVC), cached in ~/.cache/npmai_fast/, and called natively
through ctypes on every call after that.
If the function does not fit that subset (dicts, lists, generators, closures, exceptions, dynamic typing, etc.) — or no C++ compiler is installed — it transparently falls back to plain CPython. Same result, just not accelerated. This is by design: correctness first, speed second.
Supported today
- Parameters and return value annotated
intorfloat + - * / // % **(with correct Python floor-division/modulo semantics)- Comparisons,
and/or/not if/elif/else,while,for x in range(...)- Single-name local variables (no re-typing a variable mid-function)
Not yet supported (falls back automatically, does not error)
- Lists, dicts, strings, objects, classes
- Function calls to anything other than
range() - Exceptions, generators, closures over outer state
*args/**kwargs, default arguments
This puts npmai-fast in the same category as Numba's @njit or Pythran —
a numeric hot-loop compiler, not a general Python-to-native compiler. The
difference is a zero-dependency implementation (no LLVM) plus AST-level
inlining planned for a future release.
CLI
npmai-fast check # is a C++ compiler available on this machine?
npmai-fast stats # cache size / compiled function count
npmai-fast clear # wipe the compiled-function cache
Requirements
A C++20-capable compiler must be installed for acceleration to kick in:
- Linux:
sudo apt install g++(or your distro's equivalent) - macOS:
xcode-select --install - Windows: Visual Studio Build Tools, "Desktop development with C++"
Without one, functions still run correctly — just as plain Python.
Metadata
Release files for npmai-fast 1.0.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 | |
|---|---|---|---|
| npmai_fast-1.0.0.tar.gz | 10.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| npmai_fast-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.4 kB
Release files / npmai_fast-1.0.0.tar.gz
| Download URL | npmai_fast-1.0.0.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d8fee80761fcd7af3a08ebd5373cc66f3da840b7d286a76f876448c579e61e7
|
|
BLAKE2b-256 checksum How to use checksums |
ce32d2dbb0d3fefbf50daaaf87e06b52cfbc9bea91bfd7d088e23a49ff3f1bce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / npmai_fast-1.0.0-py3-none-any.whl
| Download URL | npmai_fast-1.0.0-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb24c35875c68b80e6162b72b4f8b64793c6b6060d11c15fadb7ed08a142d23b
|
|
BLAKE2b-256 checksum How to use checksums |
b6863654df3fd9e233bccd2689b3099921e00f47edb0b0c75e6ff2e6380d228c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|