Metadata-Version: 2.2
Name: pylignum
Version: 0.2.0
Summary: Bit-exact, fast inference for LightGBM and XGBoost models: interpreter, compiled trees, Arrow input
Keywords: lightgbm,xgboost,gradient boosting,inference,decision trees,arrow
Author: Kacper Piotrowski
License: Copyright (c) 2026 Kacper Piotrowski
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Project-URL: Repository, https://github.com/misterekkk/lignum
Project-URL: Documentation, https://misterekkk.github.io/lignum/
Project-URL: Issues, https://github.com/misterekkk/lignum/issues
Requires-Python: >=3.10
Requires-Dist: numpy>=1.21
Provides-Extra: test
Requires-Dist: pytest>=7.0.0; extra == "test"
Requires-Dist: lightgbm; extra == "test"
Requires-Dist: xgboost; extra == "test"
Requires-Dist: scikit-learn; extra == "test"
Requires-Dist: pandas; extra == "test"
Requires-Dist: pyarrow; extra == "test"
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://raw.githubusercontent.com/misterekkk/lignum/main/docs/assets/logo.svg" width="96" alt="lignum logo">
</p>

# lignum

Fast inference for LightGBM and XGBoost models, with predictions that are **bit-identical** to the
library that trained them.

```bash
pip install pylignum
```

```python
import lignum

model = lignum.load("model.txt")    # LightGBM model.txt / JSON, XGBoost .json / .ubj
preds = model.predict(X)            # numpy array, or Arrow data (pyarrow, polars, ...)
```

The package is installed as `pylignum` and imported as `lignum`.

## What it does

- **Exact.** Raw scores and probabilities equal `booster.predict(...)` bit for bit, including NaN,
  zero-as-missing and categorical splits, for LightGBM and XGBoost (XGBoost's float32 arithmetic
  included).
- **Fast to start.** `model.save("model.bin")` writes a binary file that loads by memory mapping in
  well under a millisecond.
- **Fast to predict.** A cache-friendly interpreter for any batch size, and an optional compiled
  mode that turns the trees into native code with the system C compiler in a few seconds:

  ```python
  model.compile(library="model.so")                       # once, where a compiler is available
  model = lignum.load("model.bin", compiled="model.so")   # production: no compiler needed
  ```

  `model.autotune(X_sample)` measures both on your data and uses each where it is faster.
- **Arrow input without copies.** `predict` reads pyarrow tables and batches, polars data frames and
  any object with the Arrow PyCapsule interface directly; dictionary columns are categories.
- **C API** for services in other languages (`include/lignum/c_api.h`), with Arrow input as well.

## Requirements

Python 3.10 or newer, numpy. Wheels are available for Linux (x86_64, aarch64), macOS 15+ (arm64,
x86_64) and Windows (x64); other platforms build from source with a C++20 compiler. The compiled mode
needs a C compiler at compile time only (cc on Linux and macOS; Visual Studio, MinGW gcc or clang on
Windows).

## Links

- Source and issues: https://github.com/misterekkk/lignum
- Documentation: https://misterekkk.github.io/lignum/
