Skip to main content

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

  • @jit for 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/method
  • jit.from_pyx(func_name, pyx_code, **kwargs): compile raw Cython source
  • jit.warmup(): warm up compiler flag probing
  • jit.cache_info(): inspect cache and compiler flags
  • jit.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:

  1. CC environment variable
  2. Python build configuration (sysconfig)
  3. 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

  1. Create PyPI account and API token.
  2. Export token:
export TWINE_USERNAME=__token__
export TWINE_PASSWORD=<pypi-token>
  1. Build package:
python -m build
  1. Verify artifacts:
python -m twine check dist/*
  1. Upload to TestPyPI (recommended first):
python -m twine upload --repository testpypi dist/*
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

native_jit-0.1.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

native_jit-0.1.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

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

Hashes for native_jit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9ee65038e053677fb18f953cb867ec65596ed2494c5239e733c313f524ac2d86
MD5 d726854eb916604f5d38444ea972755a
BLAKE2b-256 744de64c66dd319a5e790de81d613b48fddbf1241e4c7ba634411dda3ca32727

See more details on using hashes here.

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

Hashes for native_jit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 792b4c0f1d61085607b659ee1146793bdeed49b395760b1f83b64286197b16ed
MD5 a810bc9031b9a8690ff70a6ce1db5225
BLAKE2b-256 6e3cdd15d17e788ab54eceedf00e4c7ff8834ff908641ed4d2f553375a2cc272

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page