qnty


Nameqnty JSON
Version 0.3.0 PyPI version JSON
download
home_pageNone
SummaryHigh-performance unit system library for Python with dimensional safety and fast unit conversions
upload_time2025-10-22 00:49:55
maintainerNone
docs_urlNone
authortn3wman
requires_python<3.14,>=3.11
licenseApache-2.0
keywords units dimensional analysis engineering physics quantities measurements
VCS
bugtrack_url
requirements flexcache flexparser iniconfig numpy packaging Pint platformdirs pluggy Pygments pytest typing_extensions
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Qnty

**High-performance unit system library for Python with dimensional safety and fast unit conversions for engineering calculations.**

[![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
[![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Development Status](https://img.shields.io/badge/status-beta-orange.svg)](https://pypi.org/project/qnty/)

## ⚠️ Important Disclaimer

**🚧 Work in Progress**: Qnty is currently in active development and has not been thoroughly vetted for production engineering calculations. While we strive for accuracy, this library should not be used for critical engineering applications without independent verification.

**📐 Accuracy Notice**: The authors are not responsible or liable for incorrect results, calculation errors, or any consequences arising from the use of this library. Always validate calculations independently using established engineering tools and practices.

*Use Qnty to help prevent unit errors, but always verify critical calculations through multiple methods.*

---

## ✨ Key Features

- **🚀 Ultra-Fast Performance**: Prime number encoding and pre-computed conversion tables
- **🛡️ Type Safety**: Compile-time dimensional analysis prevents unit errors
- **⚡ Zero-Cost Abstractions**: Optimized operations with `__slots__` and caching
- **🔗 Fluent API**: Intuitive method chaining for readable code
- **🧮 Engineering-Focused**: Built for real-world engineering calculations
- **🧬 Mathematical System**: Built-in equation solving and expression trees
- **📊 Comprehensive Testing**: 80+ tests with performance benchmarks and real engineering examples

## 🚀 Quick Start

### Installation

```bash
pip install qnty
```

### Basic Usage

```python
from qnty import Length, Pressure, Area

# Create quantities with dimensional safety
width = Length(3, "meter", "Width")
height = Length(2, "meter", "Height")

# Mathematical operations preserve dimensional integrity
area = width * height  # Automatically becomes Area quantity
print(f"Area: {area}")  # Area: 6.0 m²

# Fluent API for unit conversions
print(f"In square feet: {area.to_unit.square_foot}")  # 64.58 ft²
```

### Engineering Example

```python
from qnty import Problem, Length, Pressure, Dimensionless
from qnty.algebra import equation

class PipeDesign(Problem):
    """ASME B31.3 Pipe Wall Thickness Calculation"""

    # Known parameters (fluent API)
    P = Pressure("Design Pressure").set(90).pound_force_per_square_inch
    D = Length("Outside Diameter").set(0.84).inch
    S = Pressure("Allowable Stress").set(20000).pound_force_per_square_inch
    E = Dimensionless("Quality Factor").set(0.8).dimensionless
    Y = Dimensionless("Y Coefficient").set(0.4).dimensionless

    # Unknowns to solve
    t = Length("Pressure Design Thickness")
    P_max = Pressure("Maximum Allowable Pressure")

    # ASME equations
    t_eqn = equation(t, (P * D) / (2 * (S * E + P * Y)))
    P_max_eqn = equation(P_max, (2 * t * S * E) / (D - 2 * t * Y))

# Solve and validate
problem = PipeDesign()
problem.solve()
print(f"Required thickness: {problem.t}")
print(f"Max pressure: {problem.P_max}")
```

### Mathematical Operations

```python
from qnty import Length, Area, Force, Pressure
from qnty.algebra import sqrt

# Mathematical functions preserve dimensional correctness
area = Area(25, "square_meter")
side = sqrt(area)  # Returns Length, not Area!
print(f"Side length: {side}")  # 5.0 m

# Unit conversions with type safety
force = Force(100, "newton")
pressure_area = Area(0.01, "square_meter")
pressure = force / pressure_area  # Automatically becomes Pressure
print(f"Pressure: {pressure.to_unit.pound_force_per_square_inch}")  # 145.04 psi
```

## 📚 Documentation & Examples

- **[🏗️ Examples](examples/)** - Real-world engineering problems including pipe design, composed problems, and conversions
- **[🔧 Development Guide](CLAUDE.md)** - Architecture and development guidelines
- **[📊 Performance Benchmarks](tests/test_benchmark.py)** - Comparison with Pint and other libraries

## 🚀 Performance

Qnty significantly outperforms other unit libraries with **18.9x average speedup** over Pint:

| Operation | Qnty | Pint | **Speedup** |
|-----------|------|------|-------------|
| Mixed Unit Addition | 0.76 μs | 17.52 μs | **23.1x** |
| Complex ASME Equation | 4.07 μs | 106.17 μs | **26.1x** 🚀 |
| Type-Safe Variables | 0.98 μs | 9.65 μs | **9.8x** |
| **AVERAGE** | **1.89 μs** | **35.83 μs** | **18.9x** 🏆 |

*Run `pytest tests/test_benchmark.py -v -s` to verify on your system.*

## 🧮 100+ Engineering Quantities

Qnty provides comprehensive coverage of engineering domains:

```python
from qnty import (
    # Mechanical
    Length, Area, Volume, Mass, Force, Pressure, Temperature,
    # Electrical  
    ElectricPotential, ElectricCurrentIntensity, ElectricResistance,
    # Thermal
    ThermalConductivity, HeatTransferCoefficient,
    # Fluid Dynamics
    ViscosityDynamic, MassFlowRate, VolumetricFlowRate,
    # And 80+ more...
)
```

## 🔧 Development

```bash
# Install for development
pip install -e ".[dev,benchmark]"

# Run all tests (80+ comprehensive tests)
pytest

# Run specific test module
pytest tests/test_dimension.py -v

# Run performance benchmarks vs Pint
pytest tests/test_benchmark.py -v -s

# Code formatting and linting
ruff check src/ tests/
ruff format src/ tests/

# Regenerate auto-generated catalog files
python codegen/cli.py
```

## 📄 License

This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.

## 🤝 Contributing

We welcome contributions! Please see [CLAUDE.md](CLAUDE.md) for development guidelines and:

1. Fork the repository
2. Create a feature branch
3. Add comprehensive tests for new functionality
4. Ensure all tests pass: `pytest`
5. Verify performance benchmarks: `pytest tests/test_benchmark.py -s`
6. Run code quality checks: `ruff check src/ tests/`
7. Submit a pull request

**Important**: Never edit `*_catalog.py` files directly - they are auto-generated. Modify generators in `codegen/` instead.

---

**Ready to supercharge your engineering calculations?** 🚀

- Explore the **[Examples](examples/)** - Real ASME pipe design, composed problems, and more
- Check the **[Performance Benchmarks](tests/test_benchmark.py)** - See the 18.9x speedup
- Read the **[Development Guide](CLAUDE.md)** - Architecture and contribution guidelines


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "qnty",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.14,>=3.11",
    "maintainer_email": null,
    "keywords": "units, dimensional analysis, engineering, physics, quantities, measurements",
    "author": "tn3wman",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/d0/f2/018b43f602ffe2abf59a52a1349198f79bb73f70416f75027555eb5621be/qnty-0.3.0.tar.gz",
    "platform": null,
    "description": "# Qnty\n\n**High-performance unit system library for Python with dimensional safety and fast unit conversions for engineering calculations.**\n\n[![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)\n[![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![Development Status](https://img.shields.io/badge/status-beta-orange.svg)](https://pypi.org/project/qnty/)\n\n## \u26a0\ufe0f Important Disclaimer\n\n**\ud83d\udea7 Work in Progress**: Qnty is currently in active development and has not been thoroughly vetted for production engineering calculations. While we strive for accuracy, this library should not be used for critical engineering applications without independent verification.\n\n**\ud83d\udcd0 Accuracy Notice**: The authors are not responsible or liable for incorrect results, calculation errors, or any consequences arising from the use of this library. Always validate calculations independently using established engineering tools and practices.\n\n*Use Qnty to help prevent unit errors, but always verify critical calculations through multiple methods.*\n\n---\n\n## \u2728 Key Features\n\n- **\ud83d\ude80 Ultra-Fast Performance**: Prime number encoding and pre-computed conversion tables\n- **\ud83d\udee1\ufe0f Type Safety**: Compile-time dimensional analysis prevents unit errors\n- **\u26a1 Zero-Cost Abstractions**: Optimized operations with `__slots__` and caching\n- **\ud83d\udd17 Fluent API**: Intuitive method chaining for readable code\n- **\ud83e\uddee Engineering-Focused**: Built for real-world engineering calculations\n- **\ud83e\uddec Mathematical System**: Built-in equation solving and expression trees\n- **\ud83d\udcca Comprehensive Testing**: 80+ tests with performance benchmarks and real engineering examples\n\n## \ud83d\ude80 Quick Start\n\n### Installation\n\n```bash\npip install qnty\n```\n\n### Basic Usage\n\n```python\nfrom qnty import Length, Pressure, Area\n\n# Create quantities with dimensional safety\nwidth = Length(3, \"meter\", \"Width\")\nheight = Length(2, \"meter\", \"Height\")\n\n# Mathematical operations preserve dimensional integrity\narea = width * height  # Automatically becomes Area quantity\nprint(f\"Area: {area}\")  # Area: 6.0 m\u00b2\n\n# Fluent API for unit conversions\nprint(f\"In square feet: {area.to_unit.square_foot}\")  # 64.58 ft\u00b2\n```\n\n### Engineering Example\n\n```python\nfrom qnty import Problem, Length, Pressure, Dimensionless\nfrom qnty.algebra import equation\n\nclass PipeDesign(Problem):\n    \"\"\"ASME B31.3 Pipe Wall Thickness Calculation\"\"\"\n\n    # Known parameters (fluent API)\n    P = Pressure(\"Design Pressure\").set(90).pound_force_per_square_inch\n    D = Length(\"Outside Diameter\").set(0.84).inch\n    S = Pressure(\"Allowable Stress\").set(20000).pound_force_per_square_inch\n    E = Dimensionless(\"Quality Factor\").set(0.8).dimensionless\n    Y = Dimensionless(\"Y Coefficient\").set(0.4).dimensionless\n\n    # Unknowns to solve\n    t = Length(\"Pressure Design Thickness\")\n    P_max = Pressure(\"Maximum Allowable Pressure\")\n\n    # ASME equations\n    t_eqn = equation(t, (P * D) / (2 * (S * E + P * Y)))\n    P_max_eqn = equation(P_max, (2 * t * S * E) / (D - 2 * t * Y))\n\n# Solve and validate\nproblem = PipeDesign()\nproblem.solve()\nprint(f\"Required thickness: {problem.t}\")\nprint(f\"Max pressure: {problem.P_max}\")\n```\n\n### Mathematical Operations\n\n```python\nfrom qnty import Length, Area, Force, Pressure\nfrom qnty.algebra import sqrt\n\n# Mathematical functions preserve dimensional correctness\narea = Area(25, \"square_meter\")\nside = sqrt(area)  # Returns Length, not Area!\nprint(f\"Side length: {side}\")  # 5.0 m\n\n# Unit conversions with type safety\nforce = Force(100, \"newton\")\npressure_area = Area(0.01, \"square_meter\")\npressure = force / pressure_area  # Automatically becomes Pressure\nprint(f\"Pressure: {pressure.to_unit.pound_force_per_square_inch}\")  # 145.04 psi\n```\n\n## \ud83d\udcda Documentation & Examples\n\n- **[\ud83c\udfd7\ufe0f Examples](examples/)** - Real-world engineering problems including pipe design, composed problems, and conversions\n- **[\ud83d\udd27 Development Guide](CLAUDE.md)** - Architecture and development guidelines\n- **[\ud83d\udcca Performance Benchmarks](tests/test_benchmark.py)** - Comparison with Pint and other libraries\n\n## \ud83d\ude80 Performance\n\nQnty significantly outperforms other unit libraries with **18.9x average speedup** over Pint:\n\n| Operation | Qnty | Pint | **Speedup** |\n|-----------|------|------|-------------|\n| Mixed Unit Addition | 0.76 \u03bcs | 17.52 \u03bcs | **23.1x** |\n| Complex ASME Equation | 4.07 \u03bcs | 106.17 \u03bcs | **26.1x** \ud83d\ude80 |\n| Type-Safe Variables | 0.98 \u03bcs | 9.65 \u03bcs | **9.8x** |\n| **AVERAGE** | **1.89 \u03bcs** | **35.83 \u03bcs** | **18.9x** \ud83c\udfc6 |\n\n*Run `pytest tests/test_benchmark.py -v -s` to verify on your system.*\n\n## \ud83e\uddee 100+ Engineering Quantities\n\nQnty provides comprehensive coverage of engineering domains:\n\n```python\nfrom qnty import (\n    # Mechanical\n    Length, Area, Volume, Mass, Force, Pressure, Temperature,\n    # Electrical  \n    ElectricPotential, ElectricCurrentIntensity, ElectricResistance,\n    # Thermal\n    ThermalConductivity, HeatTransferCoefficient,\n    # Fluid Dynamics\n    ViscosityDynamic, MassFlowRate, VolumetricFlowRate,\n    # And 80+ more...\n)\n```\n\n## \ud83d\udd27 Development\n\n```bash\n# Install for development\npip install -e \".[dev,benchmark]\"\n\n# Run all tests (80+ comprehensive tests)\npytest\n\n# Run specific test module\npytest tests/test_dimension.py -v\n\n# Run performance benchmarks vs Pint\npytest tests/test_benchmark.py -v -s\n\n# Code formatting and linting\nruff check src/ tests/\nruff format src/ tests/\n\n# Regenerate auto-generated catalog files\npython codegen/cli.py\n```\n\n## \ud83d\udcc4 License\n\nThis project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.\n\n## \ud83e\udd1d Contributing\n\nWe welcome contributions! Please see [CLAUDE.md](CLAUDE.md) for development guidelines and:\n\n1. Fork the repository\n2. Create a feature branch\n3. Add comprehensive tests for new functionality\n4. Ensure all tests pass: `pytest`\n5. Verify performance benchmarks: `pytest tests/test_benchmark.py -s`\n6. Run code quality checks: `ruff check src/ tests/`\n7. Submit a pull request\n\n**Important**: Never edit `*_catalog.py` files directly - they are auto-generated. Modify generators in `codegen/` instead.\n\n---\n\n**Ready to supercharge your engineering calculations?** \ud83d\ude80\n\n- Explore the **[Examples](examples/)** - Real ASME pipe design, composed problems, and more\n- Check the **[Performance Benchmarks](tests/test_benchmark.py)** - See the 18.9x speedup\n- Read the **[Development Guide](CLAUDE.md)** - Architecture and contribution guidelines\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "High-performance unit system library for Python with dimensional safety and fast unit conversions",
    "version": "0.3.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/tn3wman/qnty/issues",
        "Documentation": "https://github.com/tn3wman/qnty#readme",
        "Homepage": "https://github.com/tn3wman/qnty",
        "Repository": "https://github.com/tn3wman/qnty"
    },
    "split_keywords": [
        "units",
        " dimensional analysis",
        " engineering",
        " physics",
        " quantities",
        " measurements"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9293d634e39cb24a997bff11ec9715a0cb5d60c1c81d3c410a9b9315286844dd",
                "md5": "c0b896dc4f63b97f32241411a52ab30b",
                "sha256": "385646a4dc8217d753f099c730ad2c2b05f71a485095d946800ef30ed9dd62d0"
            },
            "downloads": -1,
            "filename": "qnty-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c0b896dc4f63b97f32241411a52ab30b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.14,>=3.11",
            "size": 39011226,
            "upload_time": "2025-10-22T00:49:52",
            "upload_time_iso_8601": "2025-10-22T00:49:52.472243Z",
            "url": "https://files.pythonhosted.org/packages/92/93/d634e39cb24a997bff11ec9715a0cb5d60c1c81d3c410a9b9315286844dd/qnty-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d0f2018b43f602ffe2abf59a52a1349198f79bb73f70416f75027555eb5621be",
                "md5": "c87c593be513be1c4eae722e5961ee5a",
                "sha256": "8335d713f0e815bc5a4912e5a909fc80ef3f29c8f254a0ba87e06011e1eb11d6"
            },
            "downloads": -1,
            "filename": "qnty-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c87c593be513be1c4eae722e5961ee5a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.14,>=3.11",
            "size": 38811776,
            "upload_time": "2025-10-22T00:49:55",
            "upload_time_iso_8601": "2025-10-22T00:49:55.688579Z",
            "url": "https://files.pythonhosted.org/packages/d0/f2/018b43f602ffe2abf59a52a1349198f79bb73f70416f75027555eb5621be/qnty-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-22 00:49:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tn3wman",
    "github_project": "qnty",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "flexcache",
            "specs": [
                [
                    "==",
                    "0.3"
                ]
            ]
        },
        {
            "name": "flexparser",
            "specs": [
                [
                    "==",
                    "0.4"
                ]
            ]
        },
        {
            "name": "iniconfig",
            "specs": [
                [
                    "==",
                    "2.1.0"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    "==",
                    "2.3.2"
                ]
            ]
        },
        {
            "name": "packaging",
            "specs": [
                [
                    "==",
                    "25.0"
                ]
            ]
        },
        {
            "name": "Pint",
            "specs": [
                [
                    "==",
                    "0.24.4"
                ]
            ]
        },
        {
            "name": "platformdirs",
            "specs": [
                [
                    "==",
                    "4.3.8"
                ]
            ]
        },
        {
            "name": "pluggy",
            "specs": [
                [
                    "==",
                    "1.6.0"
                ]
            ]
        },
        {
            "name": "Pygments",
            "specs": [
                [
                    "==",
                    "2.19.2"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    "==",
                    "8.4.1"
                ]
            ]
        },
        {
            "name": "typing_extensions",
            "specs": [
                [
                    "==",
                    "4.14.1"
                ]
            ]
        }
    ],
    "lcname": "qnty"
}
        
Elapsed time: 2.59365s