siunitpy
SI-Unit-Py is a Python package for dealing with units.
This package implements NIST (National Institute of Standards and Technology) official unit definitions.
Moreover, it introduce uncertainty.
Installation
pip installable package: pypi: siunitpy
pip install siunitpy
Quickstart: module siunitpy.SI
import module siunitpy.SI to use 3 very useful classes: SI, si and prefix.
SI: common physical constants
use physical constants through class SI:
>>> from siunitpy.SI import SI
>>> SI.c
Constant(value=299792458, uncertainty=0, unit=m/s)
>>> print(SI.me)
9.1093837015e-31 ± 2.8e-40 kg
>>> print(SI.me * SI.c**2)
8.187105776823886e-14 ± 2.516514500463089e-23 J
constant class SI provide physical constants defined by (or derived from) SI unit system.
si: common SI units
use units through class si:
>>> from siunitpy.SI import si
>>> print(1 * si.kg * si.m / si.s**2)
1.0 N
>>> print(760 * si.mmHg.to("Pa"))
101325.0 Pa
prefix: unit prefix factor
class prefix contains prefix from quetta(Q, = 1e30) to quecto(q, = 1e-30), and byte prefix like ki(2^10, 1024), Mi(2^20), Gi(2^30)... It's just a number factor, not Quantity.
>>> from siunitpy.SI import prefix
>>> prefix.mega
1000000.0
>>> prefix.Pi # 2**50
1125899906842624
Define Quantity
import siunit to define a Quantity object:
>>> from siunitpy import Quantity
>>> F = Quantity(1, 'kg.m/s2')
>>> L = Quantity(1, 'm', 1e-4) # with uncertainty
where F is a Quantity object, and it has properties:
>>> F.value
1
>>> F.unit
Unit(kg·m/s², dim=T⁻²LM, value=1)
>>> F.dimension
Dimension(T=-2, L=1, M=1, I=0, H=0, N=0, J=0)
>>> L.uncertainty
1e-4
objects in SI are also Quantity objects.
Quantity objects can make unit conversion and operate with number or Quantity:
>>> print(SI.me.to("keV/c2")) # unit conversion
510.99894999616424 ± 1.5706848090652466e-07 keV/c²
>>> print(F / (1 * si.m)**2)
1.0 Pa
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file siunitpy-0.1.1.tar.gz.
File metadata
- Download URL: siunitpy-0.1.1.tar.gz
- Upload date:
- Size: 49.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c7069892c0d7fe2b656b8b4ebb02135c4fa2488eeaf2d57a501e65d83797fe3
|
|
| MD5 |
ecc45c072e461041928efa1a2c531fd8
|
|
| BLAKE2b-256 |
af5036b8cf0e49f00c2a57a8dc37b301c1701084df15281f80652885eb3b8af0
|