SPQ - Simple Physical Quantities
raw JSON → 1.0.5 verified Sat May 09 auth: no python
A lightweight library for handling physical quantities with units and uncertainties. Version 1.0.5, semi-active development, sporadic releases.
pip install spq Common errors
error ImportError: cannot import name 'Quantity' from 'spq' ↓
cause spq is not installed or imported from wrong module (e.g., spq.core).
fix
Install with
pip install spq and import using from spq import Quantity. error ValueError: Unknown unit symbol: 'meters' ↓
cause Using plural or non-standard unit strings.
fix
Use singular SI symbols: 'm' for meters, 'kg' for kilograms, etc.
Warnings
gotcha The 'Q' shorthand for creating quantities with uncertainties is undocumented in older versions. Use 'Quantity' constructor with uncertainty argument or 'Q' from spq. ↓
fix Use `from spq import Q` then `Q(value, uncertainty, unit)` or `Quantity(value, unit, uncertainty=...)`.
gotcha Unit string parsing is strict; unknown unit strings raise an error. Do not use plural or alternative spellings (e.g., 'meters' instead of 'm'). ↓
fix Always use SI base unit symbols (m, kg, s, A, K, mol, cd) or derived units (N, J, etc.).
deprecated The 'magnitude' attribute is deprecated in favor of 'value' in v1.0.5. ↓
fix Replace `q.magnitude` with `q.value`.
Imports
- Quantity
from spq import Quantity - Unit wrong
from spq.core import Unitcorrectfrom spq import Unit
Quickstart
from spq import Quantity, Q
# Create a length with units
length = Quantity(5.0, 'm')
print(length) # 5.0 m
# Arithmetic with automatic unit handling
area = length * length
print(area) # 25.0 m^2
# Use Q shorthand for uncertainties
value = Q(10, 0.5, 'kg') # 10 ± 0.5 kg
print(value)
# Unit conversion
print(length.to('cm')) # 500.0 cm