Skip to main content

esio-units

A high-performance hub-and-spoke unit conversion library for industrial IoT applications, designed to handle complex unit conversions with scale and offset support.

Features

  • 🎯 Hub-and-Spoke Pattern: Efficient O(N) conversion system instead of O(N²)
  • 🔄 Bidirectional Conversion: Guaranteed round-trip accuracy
  • 📊 Scale & Offset Support: Handle device-specific scaling
  • 🏭 Industrial Focus: Units for oil & gas, manufacturing, utilities
  • ⚡ High Performance: Optimized for IoT telemetry processing
  • 🛡️ Type Safe: Full type hints and validation

Why Hub-and-Spoke?

Traditional unit conversion libraries require N×(N-1) conversion functions for N units. Our hub-and-spoke pattern requires only 2N functions, making it much more maintainable and extensible.

Traditional: °F↔°C, °F↔K, °F↔°R, °C↔K, °C↔°R, K↔°R = 6 functions for 4 units
Hub-and-Spoke: °F↔K, °C↔K, °R↔K = 6 functions (3×2) for 4 units
Adding °Ra: Traditional needs +4 functions, Hub-and-spoke needs +2

Installation

pip install esio-units

Quick Start

from esio_units import convert, convert_with_scale

# Simple conversion
celsius = 25.0
fahrenheit = convert(celsius, 'degC', 'degF')
print(f"{celsius}°C = {fahrenheit}°F")  # 25.0°C = 77.0°F

# With scale and offset (device reports 0-100 for -50°C to +150°C)
device_value = 50  # Mid-scale
actual_celsius = convert_with_scale(
    value=device_value,
    from_unit='percent',
    to_unit='degC',
    from_scale=(0, 100),
    to_scale=(-50, 150)
)
print(f"Device {device_value}% = {actual_celsius}°C")  # Device 50% = 50.0°C

# Round-trip verification
original = 100.5
converted = convert(original, 'psi', 'bar')
back = convert(converted, 'bar', 'psi')
print(f"Round-trip: {original} → {converted} → {back}")
# Round-trip: 100.5 → 6.929 → 100.5

Supported Categories

Temperature

  • Hub: Kelvin (K)
  • Units: K, °C (degC), °F (degF), °R (degR)

Pressure

  • Hub: Pascal (Pa)
  • Units: Pa, kPa, MPa, bar, psi, atm, mmHg, inHg

Length

  • Hub: Meter (m)
  • Units: m, km, cm, mm, ft, in, mi, yd

Mass

  • Hub: Kilogram (kg)
  • Units: kg, g, mg, lb, oz, ton, metric_ton

Volume

  • Hub: Cubic Meter (m³)
  • Units: m3, L, mL, gal, ft3, bbl, cf

Flow Rate

  • Hub: Cubic Meter per Second (m³/s)
  • Units: m3/s, L/s, L/min, gpm, cfm, bbl/day

Power

  • Hub: Watt (W)
  • Units: W, kW, MW, hp, BTU/h

Energy

  • Hub: Joule (J)
  • Units: J, kJ, MJ, kWh, BTU, cal

Dimensionless

  • Hub: Ratio (0-1)
  • Units: ratio, percent, ppm, ppb

Advanced Usage

Custom Scale Conversions

from esio_units import ScaleConverter

# Device outputs 4-20mA for 0-100 psi
converter = ScaleConverter(
    from_unit='mA',
    to_unit='psi',
    from_range=(4, 20),
    to_range=(0, 100)
)

current = 12  # mA
pressure = converter.convert(current)
print(f"{current}mA = {pressure} psi")  # 12mA = 50.0 psi

Unit Registry

from esio_units import UnitRegistry

registry = UnitRegistry()

# Get all units in a category
temp_units = registry.get_category_units('temperature')
print(f"Temperature units: {temp_units}")

# Get hub unit for category
hub = registry.get_hub_unit('pressure')
print(f"Pressure hub: {hub}")  # Pressure hub: Pa

# Check if conversion is possible
can_convert = registry.can_convert('degC', 'psi')
print(f"Can convert °C to PSI: {can_convert}")  # False

Validation

from esio_units import validate_conversion

# Check if conversion is valid
is_valid = validate_conversion('degF', 'degC')  # True
is_invalid = validate_conversion('degF', 'kg')  # False

# Get conversion path
from esio_units import get_conversion_path

path = get_conversion_path('psi', 'bar')
print(f"Conversion path: {path}")
# Conversion path: ['psi', 'Pa', 'bar']

Performance

The library is optimized for high-throughput telemetry processing:

  • Conversion functions are cached after first use
  • No string parsing in hot paths
  • Minimal object allocation
  • Thread-safe for concurrent processing

Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=esio_units

# Run specific category tests
pytest tests/test_temperature.py

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT License - see LICENSE file for details

Acknowledgments

Built for the EdgeStack IoT platform to provide reliable, efficient unit conversions for industrial telemetry data.

Metadata

Release files for esio-units 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for esio-units 0.1.0
File Size Uploaded Provenance Actions
esio_units-0.1.0.tar.gz 26.2 kB Without provenance Details for esio_units-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for esio-units 0.1.0
File Interpreter ABI Platform Actions
esio_units-0.1.0-py3-none-any.whl Python 3 none any Details for esio_units-0.1.0-py3-none-any.whl

Total release size: 38.8 kB

Release files / esio_units-0.1.0.tar.gz

Download URL esio_units-0.1.0.tar.gz
Size 26.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8a6abae203637c244e4a3c50af1a64ad03aa20c74d0bc602c9d94b4070bc20a5
BLAKE2b-256 checksum
How to use checksums
9782c965347f3a8d015f897b5e0db6abf04970e27a7c8a9d9d4de4a25825e02c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / esio_units-0.1.0-py3-none-any.whl

Download URL esio_units-0.1.0-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
464787c9b41baef3cd84a2cd15c2eef217eb409d897760430cd760464b9d8573
BLAKE2b-256 checksum
How to use checksums
77cfcc2c5656be4b7bda3aa183f5dea3bbaba711906d2ba7c2efa214b1766db3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for esio-units 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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