D-SI Units
A Python library for parsing, validating, and performing mathematical operations on SI units using the D-SI (Digital SI) and BIPM-RP (SI Reference Point) syntax.
The library allows:
- Unit Parsing & Validation: Parse units from D-SI and BIPM-RP notation strings
- Mathematical Operations: Perform multiplication, division, and power operations on units while preserving dimensional consistency
- Multiple Output Formats: Convert units to LaTeX, UTF-8, and SIRP representations
- Scale Factor Calculations: Calculate conversion factors between compatible units
- Base Unit Conversions: Convert complex units to their base SI unit representation
The Javascript version of this library has moved to https://gitlab1.ptb.de/digitaldynamicmeasurement/dsiunits-js/
Installation
pip install dsiUnits
Requirements: Python 3.9+
Quick Start
from dsi_unit import DsiUnit
# Create units from D-SI notation
meter = DsiUnit(r"\metre")
second = DsiUnit(r"\second")
kilogram = DsiUnit(r"\kilogram")
# Or from BIPM-RP notation
velocity = DsiUnit("m.s-1") # meters per second
Usage Examples
Basic Unit Operations
from dsi_unit import DsiUnit
# Mathematical operations
velocity = DsiUnit(r"\metre") / DsiUnit(r"\second")
print(velocity) # \metre\per\second
acceleration = velocity / DsiUnit(r"\second")
print(acceleration) # \metre\per\second\tothe{2}
force = DsiUnit(r"\kilogram") * acceleration
print(force) # \kilogram\metre\per\second\tothe{2}
# Power operations
area = DsiUnit(r"\metre") ** 2
print(area) # \metre\tothe{2}
Unit Conversions
# Check if units are scalable (convertible)
joule = DsiUnit(r"\joule")
watt_second = DsiUnit(r"\watt") * DsiUnit(r"\second")
print(joule.is_scalable(watt_second)) # True
# Get scale factor between compatible units
km = DsiUnit(r"\kilo\metre")
m = DsiUnit(r"\metre")
scale = km.get_scale_factor(m) # 0.001 (1 km = 1000 m, so 1 km * 0.001 = 1 m)
# Convert to base units
newton = DsiUnit(r"\newton")
base = newton.to_base_unit_tree()
print(base) # \kilogram\metre\per\second\tothe{2}
Output Formats
unit = DsiUnit(r"\kilo\metre\tothe{2}\per\second")
# LaTeX representation
print(unit.to_latex()) # $$\frac{\mathrm{k}\mathrm{m}^{2}}{\mathrm{s}}$$
# UTF-8 representation
print(unit.to_utf8()) # km²/s
# SIRP (SI Reference Point) representation
print(unit.to_sirp()) # km2.s-1
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Metadata
Release files for dsiUnits 3.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dsiunits-3.1.3.tar.gz | 56.3 kB | Without provenance | Details for dsiunits-3.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dsiunits-3.1.3-py3-none-any.whl | Python 3 | none | any | Details for dsiunits-3.1.3-py3-none-any.whl |
Total release size: 101.0 kB
Release files / dsiunits-3.1.3.tar.gz
| Download URL | dsiunits-3.1.3.tar.gz |
|---|---|
| Size | 56.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b2209bdf14d5abd2c1a033d34e199b4375fe1245602f65306531bcf72040c666
|
|
BLAKE2b-256 checksum How to use checksums |
4ee73e7d3e34d1dda1d604226087b0cd9b2bd9629806b081b53f3a19fce0a2d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / dsiunits-3.1.3-py3-none-any.whl
| Download URL | dsiunits-3.1.3-py3-none-any.whl |
|---|---|
| Size | 44.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
31cadef5f2541e4448c3188e48ed287fa4cf80964ec13cfd814121413c118f7a
|
|
BLAKE2b-256 checksum How to use checksums |
340f0f112a10e55f0b81ae3bdb4ae1cc2d70004a48979c8c40f34539928a3077
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for dsiUnits 3.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.