High-performance unit system library for Python with dimensional safety and fast unit conversions
Project description
Qnty
High-performance unit system library for Python with dimensional safety and fast unit conversions for engineering calculations.
⚠️ 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: 187 tests with performance benchmarks
🚀 Quick Start
Installation
pip install qnty
Basic Usage
from qnty import Length, Pressure, Area
# Create quantities with dimensional safety
width = Length(3, "meter", "Width")
height = Length(2, "meter", "Height")
# Solve mathematical expressions
area = Area("area", is_known=False)
area.solve_from(width * height)
print(f"Area: {area}") # Area: 6.0 m²
Engineering Example
from qnty import Problem, Length, Pressure
class PipeThickness(Problem):
"""Calculate pipe wall thickness"""
# Known parameters
pressure = Pressure(150, "pound_force_per_square_inch", "Internal Pressure")
diameter = Length(6, "inch", "Pipe Diameter")
allowable_stress = Pressure(20000, "pound_force_per_square_inch", "Allowable Stress")
# Unknown to solve for
thickness = Length("thickness", is_known=False)
# Engineering equation: t = (P × D) / (2 × S)
equation = thickness.equals((pressure * diameter) / (2 * allowable_stress))
# Solve the problem
problem = PipeThickness()
problem.solve()
print(f"Required thickness: {problem.thickness}")
Mathematical Operations
from qnty import Length, sqrt, Area
# Dimensional analysis with mathematical functions
area = Area(25, "square_meter", "Square Area")
side = Length("side", is_known=False)
side.solve_from(sqrt(area)) # Returns Length, not Area!
print(f"Side length: {side}") # Side length: 5.0 m
📚 Documentation
- 📖 Tutorial - Step-by-step learning guide
- 📋 API Reference - Complete API documentation
- 🏗️ Examples - Real-world engineering examples
- 📁 Full Documentation - Complete documentation index
🚀 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:
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
# Install dependencies
pip install -r requirements.txt
# Run tests
pytest
# Run specific test
pytest tests/test_dimension.py -v
# Run benchmarks
python tests/test_benchmark.py
# Lint code
ruff check src/ tests/
ruff format src/ tests/
📄 License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
🤝 Contributing
We welcome contributions! Please see CLAUDE.md for development guidelines and:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass:
pytest - Submit a pull request
Ready to supercharge your engineering calculations? 🚀
- Start with the Tutorial
- Browse the API Reference
- Try the Examples
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qnty-0.1.5.tar.gz.
File metadata
- Download URL: qnty-0.1.5.tar.gz
- Upload date:
- Size: 294.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43fe3774c242aa36eff369f8ed17a3800b6c69e565d521eaa5bff30e77a3d926
|
|
| MD5 |
e30c40a53753b3ddd38190462db1f0c6
|
|
| BLAKE2b-256 |
21e796471a9d4c72292834b639f3c5c949fe08a75269b99dc7593e438a8b1404
|
Provenance
The following attestation bundles were made for qnty-0.1.5.tar.gz:
Publisher:
release.yaml on tn3wman/qnty
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qnty-0.1.5.tar.gz -
Subject digest:
43fe3774c242aa36eff369f8ed17a3800b6c69e565d521eaa5bff30e77a3d926 - Sigstore transparency entry: 490277831
- Sigstore integration time:
-
Permalink:
tn3wman/qnty@a999b469f89409d59343101caf454c5a2eff5f18 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/tn3wman
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@a999b469f89409d59343101caf454c5a2eff5f18 -
Trigger Event:
push
-
Statement type:
File details
Details for the file qnty-0.1.5-py3-none-any.whl.
File metadata
- Download URL: qnty-0.1.5-py3-none-any.whl
- Upload date:
- Size: 314.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92d122b234d2a749b17c770d0de5c5a004fc5ccb4c18fbca99b3102b748bfa58
|
|
| MD5 |
dca63bf8d635499db990f6ce3589b7b4
|
|
| BLAKE2b-256 |
e5e062a2419bab48d54f38e58cb6dab6a9b20dda215265d726a4ed8fbfeba530
|
Provenance
The following attestation bundles were made for qnty-0.1.5-py3-none-any.whl:
Publisher:
release.yaml on tn3wman/qnty
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qnty-0.1.5-py3-none-any.whl -
Subject digest:
92d122b234d2a749b17c770d0de5c5a004fc5ccb4c18fbca99b3102b748bfa58 - Sigstore transparency entry: 490277899
- Sigstore integration time:
-
Permalink:
tn3wman/qnty@a999b469f89409d59343101caf454c5a2eff5f18 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/tn3wman
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@a999b469f89409d59343101caf454c5a2eff5f18 -
Trigger Event:
push
-
Statement type: