Skip to main content

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dsiunits-3.1.1.tar.gz (56.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dsiunits-3.1.1-py3-none-any.whl (44.7 kB view details)

Uploaded Python 3

File details

Details for the file dsiunits-3.1.1.tar.gz.

File metadata

  • Download URL: dsiunits-3.1.1.tar.gz
  • Upload date:
  • Size: 56.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.4

File hashes

Hashes for dsiunits-3.1.1.tar.gz
Algorithm Hash digest
SHA256 f0625361edde40d0a86b6e34ddfed6de6b6767964c4ee672a4c738477ab338de
MD5 0348fee52a9d2a5ee6db3c5c0326a00c
BLAKE2b-256 a8c189b3bed2ad5be061f3f3e28e9d3f370467e9f42594d54239259824b63ba9

See more details on using hashes here.

File details

Details for the file dsiunits-3.1.1-py3-none-any.whl.

File metadata

  • Download URL: dsiunits-3.1.1-py3-none-any.whl
  • Upload date:
  • Size: 44.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.4

File hashes

Hashes for dsiunits-3.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6719668cb821c84082ae3eb92e5d56fd0318d06ed2dbb2c455b77b9a5781a810
MD5 4008bf3af1f9baeceacc56feaad00905
BLAKE2b-256 bb073e4bcb53566e38d35827b1eaad7f4b6caa5f240a2311e4b44430d7de1c26

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

3.1.1 This release

2 files

3.1.0

2 files

3.0.2

2 files

3.0.1

2 files

3.0.0

2 files

2.5.2

2 files

2.5.1

2 files

2.4.2

1 file

2.4.1

2 files

2.4.0

2 files

2.3.2

2 files

2.3.1

2 files

2.3.0

2 files

2.2.3

2 files

2.2.2

2 files

2.2.1

2 files

2.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page