Cython-powered JIT decorator for Python functions and classes
Project description
native_jit
native_jit is a Cython-powered JIT decorator for Python functions and classes.
It tries to compile decorated objects for speed and automatically falls back to the original Python object if compilation is not available in the current environment.
Features
@jitfor functions and classes- Cython compilation pipeline (
.pyx -> .c -> extension module) - In-memory and disk cache for compiled modules
- Concurrent compilation deduplication
- Cross-platform compiler detection (
CC/ system compiler fallback) - Safe fallback mode: no hard failure when compilation is unavailable
Install
pip install native-jit
For local development:
pip install -e .[dev]
Quick Start
from native_jit import jit
@jit
def add(a: int, b: int) -> int:
return a + b
print(add(1, 2))
Advanced usage:
from native_jit import jit
@jit(nopython=True)
def fast_sum(n: int) -> int:
s = 0
for i in range(n):
s += i
return s
print(fast_sum(1000000))
API
jit(...): decorate function/class/methodjit.from_pyx(func_name, pyx_code, **kwargs): compile raw Cython sourcejit.warmup(): warm up compiler flag probingjit.cache_info(): inspect cache and compiler flagsjit.clear_cache(disk=False): clear in-memory/disk cache
Notes on Compilers
Cython does not bundle a C compiler. A system C toolchain is still required for native compilation.
native_jit detects compiler command from:
CCenvironment variable- Python build configuration (
sysconfig) - common fallback commands (
cc,clang,gcc,cl)
If no compiler is available, decorated code still runs with Python fallback mode.
Publish to GitHub
git init
git add .
git commit -m "chore: prepare package for release"
git branch -M main
git remote add origin https://github.com/<your-user>/<your-repo>.git
git push -u origin main
Build and Publish to PyPI
- Create PyPI account and API token.
- Export token:
export TWINE_USERNAME=__token__
export TWINE_PASSWORD=<pypi-token>
- Build package:
python -m build
- Verify artifacts:
python -m twine check dist/*
- Upload to TestPyPI (recommended first):
python -m twine upload --repository testpypi dist/*
- Upload to PyPI:
python -m twine upload dist/*
Verify Install
pip install native-jit
python -c "from native_jit import jit; print(callable(jit))"
Project details
Release history Release notifications | RSS feed
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 native_jit-0.1.0.tar.gz.
File metadata
- Download URL: native_jit-0.1.0.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ee65038e053677fb18f953cb867ec65596ed2494c5239e733c313f524ac2d86
|
|
| MD5 |
d726854eb916604f5d38444ea972755a
|
|
| BLAKE2b-256 |
744de64c66dd319a5e790de81d613b48fddbf1241e4c7ba634411dda3ca32727
|
File details
Details for the file native_jit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: native_jit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
792b4c0f1d61085607b659ee1146793bdeed49b395760b1f83b64286197b16ed
|
|
| MD5 |
a810bc9031b9a8690ff70a6ce1db5225
|
|
| BLAKE2b-256 |
6e3cdd15d17e788ab54eceedf00e4c7ff8834ff908641ed4d2f553375a2cc272
|