Metadata-Version: 2.4
Name: dimvexa
Version: 0.11.1
Classifier: Programming Language :: Rust
Classifier: Topic :: Scientific/Engineering
Classifier: Typing :: Typed
Requires-Dist: numpy>=1.23 ; extra == 'numpy'
Requires-Dist: pytest ; extra == 'test'
Requires-Dist: numpy>=1.23 ; extra == 'test'
Provides-Extra: numpy
Provides-Extra: test
Summary: Exact factors. Loud failures. Zero guessing. Unit conversion with exact rational factors.
License: MIT OR Apache-2.0
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

<p align="center"><img src="https://raw.githubusercontent.com/welworx/dimvexa/main/docs/brand/icon-256.png" alt="Dimvexa" width="96" height="96"></p>

# dimvexa (Python)

Python binding for [Dimvexa](https://github.com/welworx/dimvexa): *Exact factors. Loud failures.
Zero guessing.* A thin PyO3 layer; all conversion logic is in the Rust core.

```python
import dimvexa

dimvexa.convert(10.0, "m/s", "km/h")  # 36.0
c = dimvexa.conversion("m", "km")  # parse once ...
c(numpy_array)  # ... apply to float64 arrays, lists or floats

try:
    dimvexa.convert(1.0, "gal", "L")
except dimvexa.DimvexaError as e:
    e.code, e.candidates  # 'ambiguous_symbol', ['gal_us', 'gal_imp']
```

Configs, densities and constants work as in the CLI (`dimvexa-config` does the loading):

```python
dimvexa.convert("4pi", "rad", "deg")  # 720.0: a string is an exact value (pi, * / ^, parentheses)
dimvexa.convert("pi/2", "rad", "deg"), dimvexa.quantity("2*pi rad").to("deg")  # 90.0, 360 deg
dimvexa.convert(1.0, "ton", "kg", configs=["us-customary"])  # 907.18474; a name or a file path
dimvexa.convert(1.0, "L", "kg", density="998.2067kg/m3")  # never assumed, only when asked
dimvexa.convert(1.0, "L", "kg", configs=["water"], density="water_25C")
dimvexa.constants(config_texts=[toml_text])  # pi, planck_constant, elementary_charge, boltzmann_constant, avogadro_constant, speed_of_light, molar_gas_constant, then your own
dimvexa.quantity("1 L", density="998.2067kg/m3").to("kg")  # exact; quantity() takes the same options
dimvexa.calc("sqrt(9 m2)")  # {"value": 3.0, "unit": "m", "exact": True, "text": "3 m"}
dimvexa.calc("sqrt(2 * dp / rho)", vars={"dp": "50 kPa", "rho": "998 kg/m3"}, to="m/s")  # exact when the mathematics is, "≈ ..." when not
dimvexa.calc("1500 m", autoprefix=True)["text"]  # "1.5 km"; sci=True or sci=4 for 1.5e3 / 1.500e3; exact=True adds the fraction
dimvexa.units(configs=["us-customary"]), dimvexa.unit_info("bbl_oil", config_texts=[toml_text])  # config units too
```

Every refusal is a `DimvexaError` (a `ValueError`) with a stable `code`, `suggestions` and
`candidates`. `exact=True` routes through the exact rational path, rounded once. A string value is always exact; `1/2pi` is refused as ambiguous (`ambiguous_expression`), write `pi/2` or `1/(2*pi)`.

## Build and test

This crate is its own workspace (it needs PyO3 and NumPy from the registry; the main workspace is
std-only and offline). It is not part of `cargo xtask ci`.

```console
cd bindings/python
python -m venv .venv && . .venv/bin/activate
pip install maturin pytest numpy
maturin develop
pytest
```

Wheels are `abi3` (Python 3.9+). No performance claim is made until a dated benchmark run exists
(`docs/benchmarking.md`).

