unitforge


Nameunitforge JSON
Version 0.2.30 PyPI version JSON
download
home_pageNone
SummaryA library for unit and quantity consistent computations in Rust
upload_time2025-07-23 19:42:15
maintainerNone
docs_urlNone
authorDr.Q team <info@askdrq.com>, Henrik Stromberg <henrik@askdrq.com>
requires_python>=3.7
licenseMIT
keywords units quantities simulation physics
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Unitforge

**Unitforge** is a Python library for working with physical quantities that respect units, dimensional analysis, and arithmetic correctness — powered by high-performance Rust under the hood.

Built for scientific computing, simulation, and engineering workflows where unit safety is non-negotiable.

---

## Features

- **Strong unit enforcement**: Prevent unit mismatch bugs at runtime.
- **Arithmetic support**: Add, subtract, multiply, and divide quantities with automatic unit resolution.
- **Unit conversion**: Convert between compatible units on the fly.
- **Scientific formatting**: Values display with 4 significant digits and the configured unit.
- **3D Vectors & Matrices**: Perform vector/matrix math with quantities and units.
- **NumPy integration**: Convert to/from NumPy arrays easily.
- **Constants**: Built-in constants like the speed of light.
- **Serialization-ready**: Optional serde-based serialization support (if compiled with feature).

---

## Installation

```bash
pip install unitforge
```

---

## Example Usage

```python
from unitforge import Force, ForceUnit, Distance, DistanceUnit

f = Force(12.0, ForceUnit.N)
print(f.to(ForceUnit.mN))  # → 12000.0

d = Distance(2.0, DistanceUnit.m)
work = f * d
print(work)  # → 24 Nm
```

### Unit Conversion

```python
f = Force(1.0, ForceUnit.N)
print(f.to(ForceUnit.kN))  # → 0.001
```

### Arithmetic

```python
f1 = Force(5.0, ForceUnit.N)
f2 = Force(3.0, ForceUnit.N)
f_sum = f1 + f2
print(f_sum.to(ForceUnit.N))  # → 8.0
```

---

## Vector and Matrix Support

```python
from unitforge import Vector3, Distance, DistanceUnit

v = Vector3.from_list([
    Distance(3., DistanceUnit.m),
    Distance(4., DistanceUnit.m),
    Distance(12., DistanceUnit.m)
])

print(v.norm())  # → 13.0 m
```

---

## NumPy Interoperability

```python
import numpy as np
from unitforge import Vector3, ForceUnit

arr = np.array([1.0, 2.0, 3.0])
vec = Vector3.from_array(arr, ForceUnit.N)
arr_back = vec.to_array(ForceUnit.N)

print(arr_back)  # → [1. 2. 3.]
```

---

## Quantities Available

Examples include:

- `Acceleration`, `AreaOfMoment`, `Density`, `Stiffness`, `Time`, `Volume`, `Angle`, `Area`, `Distance`, `ForcePerVolume`, `Strain`, `Velocity`, `AngularAcceleration`, `Charge`, `ForceArea`, `Force`, `Stress`, `VelocitySquared`, `AngularVelocity`, `Compliance`, `ForceDistance`, `ForceVolume`, `Mass`, `Voltage`
- Each with associated unit enums (e.g., `ForceUnit`, `DistanceUnit`, ...)

---

```python
from math import isclose
from unitforge import Force, ForceUnit

f = Force(12., ForceUnit.N)
assert isclose((f * 2).to(ForceUnit.N), 24.)
```

---

## Contributing

Contributions are welcome! While the core is implemented in Rust, Python usage feedback, bug reports, and API improvements are highly valued.

---

## Repository

[GitLab – Unitforge Crate](https://gitlab.com/henrikjstromberg/unitforge)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "unitforge",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "units, quantities, simulation, physics",
    "author": "Dr.Q team <info@askdrq.com>, Henrik Stromberg <henrik@askdrq.com>",
    "author_email": "\"Dr.Q team\" <info@askdrq.com>, Henrik Stromberg <henrik@askdrq.com>",
    "download_url": "https://files.pythonhosted.org/packages/46/82/aebd65ef184ff7c5b6aa0f998cfab2a0cc6d8d9826b9fb4306713f3d715b/unitforge-0.2.30.tar.gz",
    "platform": null,
    "description": "# Unitforge\n\n**Unitforge** is a Python library for working with physical quantities that respect units, dimensional analysis, and arithmetic correctness \u2014 powered by high-performance Rust under the hood.\n\nBuilt for scientific computing, simulation, and engineering workflows where unit safety is non-negotiable.\n\n---\n\n## Features\n\n- **Strong unit enforcement**: Prevent unit mismatch bugs at runtime.\n- **Arithmetic support**: Add, subtract, multiply, and divide quantities with automatic unit resolution.\n- **Unit conversion**: Convert between compatible units on the fly.\n- **Scientific formatting**: Values display with 4 significant digits and the configured unit.\n- **3D Vectors & Matrices**: Perform vector/matrix math with quantities and units.\n- **NumPy integration**: Convert to/from NumPy arrays easily.\n- **Constants**: Built-in constants like the speed of light.\n- **Serialization-ready**: Optional serde-based serialization support (if compiled with feature).\n\n---\n\n## Installation\n\n```bash\npip install unitforge\n```\n\n---\n\n## Example Usage\n\n```python\nfrom unitforge import Force, ForceUnit, Distance, DistanceUnit\n\nf = Force(12.0, ForceUnit.N)\nprint(f.to(ForceUnit.mN))  # \u2192 12000.0\n\nd = Distance(2.0, DistanceUnit.m)\nwork = f * d\nprint(work)  # \u2192 24 Nm\n```\n\n### Unit Conversion\n\n```python\nf = Force(1.0, ForceUnit.N)\nprint(f.to(ForceUnit.kN))  # \u2192 0.001\n```\n\n### Arithmetic\n\n```python\nf1 = Force(5.0, ForceUnit.N)\nf2 = Force(3.0, ForceUnit.N)\nf_sum = f1 + f2\nprint(f_sum.to(ForceUnit.N))  # \u2192 8.0\n```\n\n---\n\n## Vector and Matrix Support\n\n```python\nfrom unitforge import Vector3, Distance, DistanceUnit\n\nv = Vector3.from_list([\n    Distance(3., DistanceUnit.m),\n    Distance(4., DistanceUnit.m),\n    Distance(12., DistanceUnit.m)\n])\n\nprint(v.norm())  # \u2192 13.0 m\n```\n\n---\n\n## NumPy Interoperability\n\n```python\nimport numpy as np\nfrom unitforge import Vector3, ForceUnit\n\narr = np.array([1.0, 2.0, 3.0])\nvec = Vector3.from_array(arr, ForceUnit.N)\narr_back = vec.to_array(ForceUnit.N)\n\nprint(arr_back)  # \u2192 [1. 2. 3.]\n```\n\n---\n\n## Quantities Available\n\nExamples include:\n\n- `Acceleration`, `AreaOfMoment`, `Density`, `Stiffness`, `Time`, `Volume`, `Angle`, `Area`, `Distance`, `ForcePerVolume`, `Strain`, `Velocity`, `AngularAcceleration`, `Charge`, `ForceArea`, `Force`, `Stress`, `VelocitySquared`, `AngularVelocity`, `Compliance`, `ForceDistance`, `ForceVolume`, `Mass`, `Voltage`\n- Each with associated unit enums (e.g., `ForceUnit`, `DistanceUnit`, ...)\n\n---\n\n```python\nfrom math import isclose\nfrom unitforge import Force, ForceUnit\n\nf = Force(12., ForceUnit.N)\nassert isclose((f * 2).to(ForceUnit.N), 24.)\n```\n\n---\n\n## Contributing\n\nContributions are welcome! While the core is implemented in Rust, Python usage feedback, bug reports, and API improvements are highly valued.\n\n---\n\n## Repository\n\n[GitLab \u2013 Unitforge Crate](https://gitlab.com/henrikjstromberg/unitforge)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A library for unit and quantity consistent computations in Rust",
    "version": "0.2.30",
    "project_urls": {
        "Repository": "https://gitlab.com/henrikjstromberg/unitforge"
    },
    "split_keywords": [
        "units",
        " quantities",
        " simulation",
        " physics"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8194481f5189f9b43b17b9183f2e702fe46c9c09eeb511689c2c88291d2a4007",
                "md5": "615399981f8966b5f899e5633afb63dc",
                "sha256": "8ead22fd54f9df5b03c04c90cbe514494fac09715387a2a6758ae1e22e7193c5"
            },
            "downloads": -1,
            "filename": "unitforge-0.2.30-cp312-cp312-manylinux_2_34_x86_64.whl",
            "has_sig": false,
            "md5_digest": "615399981f8966b5f899e5633afb63dc",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.7",
            "size": 543350,
            "upload_time": "2025-07-23T19:42:13",
            "upload_time_iso_8601": "2025-07-23T19:42:13.307151Z",
            "url": "https://files.pythonhosted.org/packages/81/94/481f5189f9b43b17b9183f2e702fe46c9c09eeb511689c2c88291d2a4007/unitforge-0.2.30-cp312-cp312-manylinux_2_34_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4682aebd65ef184ff7c5b6aa0f998cfab2a0cc6d8d9826b9fb4306713f3d715b",
                "md5": "8c77f4ab060d257b02ec304bb6b4d7de",
                "sha256": "abf8ca1f27ca9c6dc8124287bc267ecee53961778ec064731303403064bd4164"
            },
            "downloads": -1,
            "filename": "unitforge-0.2.30.tar.gz",
            "has_sig": false,
            "md5_digest": "8c77f4ab060d257b02ec304bb6b4d7de",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 45182,
            "upload_time": "2025-07-23T19:42:15",
            "upload_time_iso_8601": "2025-07-23T19:42:15.136858Z",
            "url": "https://files.pythonhosted.org/packages/46/82/aebd65ef184ff7c5b6aa0f998cfab2a0cc6d8d9826b9fb4306713f3d715b/unitforge-0.2.30.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-23 19:42:15",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "henrikjstromberg",
    "gitlab_project": "unitforge",
    "lcname": "unitforge"
}
        
Elapsed time: 0.77511s