Metadata-Version: 2.4
Name: unitful
Version: 1.1.0
Summary: Physical units as first-class values with dimensional analysis
Project-URL: Homepage, https://github.com/nazarhktwitch/unitful
Project-URL: Repository, https://github.com/nazarhktwitch/unitful
Project-URL: Issues, https://github.com/nazarhktwitch/unitful/issues
License: MIT License
        
        Copyright (c) 2026 NazarHK
        
        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.
License-File: LICENSE
Keywords: dimensional analysis,physics,quantities,units
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: numpy>=1.24; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Provides-Extra: numpy
Requires-Dist: numpy>=1.24; extra == 'numpy'
Description-Content-Type: text/markdown

# unitful

[![PyPI version](https://img.shields.io/pypi/v/unitful.svg?style=flat-square&color=blue)](https://pypi.org/project/unitful/)
[![Python](https://img.shields.io/pypi/pyversions/unitful.svg?style=flat-square)](https://pypi.org/project/unitful/)
[![CI](https://img.shields.io/github/actions/workflow/status/nazarhktwitch/unitful/publish.yml?style=flat-square&label=CI)](https://github.com/nazarhktwitch/unitful/actions)
[![License](https://img.shields.io/pypi/l/unitful.svg?style=flat-square)](LICENSE)

Physical units as first-class Python values

Attach a unit to any number, arithmetic propagates units automatically
Dimension mismatches raise `DimensionError` at runtime instead of producing
silently wrong results

## Getting Started

```
pip install unitful
```

```python
from unitful import m, s, kg, km, h

distance = 100 * m
time     = 9.58 * s
speed    = distance / time        # Quantity(10.44, 'm/s')

speed.to(km / h)                  # Quantity(37.58, 'km/h')
speed.to(kg)                      # DimensionError: [Length/Time] != [Mass]
```

## Features

- Dimension checking: all arithmetic validates physical dimensions and raises
  `DimensionError` with a clear message on mismatch
- Unit conversion: `.to(unit)` converts between compatible units, including
  offset temperature scales (`degC`, `degF`, `K`)
- NumPy integration: `np.array([...]) * m` returns a `QuantityArray`; ufuncs
  and reduction functions (`np.mean`, `np.sum`, etc.) preserve units
- Decorators: `@requires` and `@returns` enforce dimensions on function
  arguments and return values
- Custom units and dimensions: `define_unit` and `new_dimension` extend the
  registry at runtime
- Serialization: `to_json` / `from_json` for plain-dict round-trips; pickle
  and `copy` work without extra setup
- Formatting: `f"{q:.2f~P}"` (Unicode), `f"{q:.2f~L}"` (LaTeX),
  `f"{q:.2f~H}"` (HTML)

## Requirements

Python 3.10 or later. NumPy is optional; install it with:

```
pip install "unitful[numpy]"
```

## License

[MIT](LICENSE)
