Skip to main content

PH-Units:

A package for converting common Passive House unit types (IP | SI).

Usage:

The most basic usage is a simple conversion from one known unit to another:

>>> from ph_units.converter import convert
>>> # Convert 12.45 meters to feet...
>>> convert(12.45, "M", "FT") -> 40.85 # FT

The package also has a parser which can take simple text in the format: "{value} {unit}" and will split apart the text into a numeric part and a unit part:

>>> from ph_units.parser import parse_input
>>> val, unit = parse_input("0.17 BTU/HR-FT2-F")
>>> val  # 0.17
>>> unit # 'BTU/HR-FT2-F'

The results of the parser can then be fed into the converter

>>> from ph_units.converter import convert
>>> convert(val, "W/MK", unit) -> 0.098 # BTU/HR-FT2-F

Unit Types Supported:

  • area (M2, FT2)
  • density (KG/M3, LB/FT3)
  • emissions factors (G/KWH)
  • energy (Wh/M3, Wh/M2, kW/M2, kBtu/ft2, Btu/ft2)
  • envelope (U-Value, R-Value)
  • length (M, CM, MM, IN, FT)
  • moisture vapor resistance (MNS/G, PERM-IN)
  • power (kW, W, W/M2, W/ft2, W/cfm, Btu/h-ft2, Btu/h)
  • speed (m/d, m/s, m/h, ft/s, ft/d)
  • temperature (C, F)
  • volume flow (M3/HR, CFM)
  • volume (M2, FT3, LITER, GALLON)

Adding New Units:

The conversion factors used are stored as types in the ph_units.unit_types directory. Note that the types also allow for common 'alias' descriptions ie: 'feet' can be denoted as "FT", "ft." or even the symbol '

The Unit Type:

The package also includes a new Unit type which subclasses from float but also retains the unit-type information. This allows for easy conversion between units. For example:

>>> from ph_units.unit_type import Unit
>>> a_meter_value = Unit(1.0, "M")
>>> print(a_meter_value)
>>> "1.0 (M)"
>>> a_foot_value = a_meter_value.as_a("FT")
>>> print(a_foot_value)
>>> "3.281(FT)"

This Unit type supports basic mathematical operations like addition and subtraction, as well as unit-related operations like 'inversion'.

The Unit type also supports serialization and deserialization to and from JSON. Additionally, the Unit type can be used as a dataclass field type and should serialize properly when dataclass as_dict is called on the parent object.

Development:

PH-units is a dependency-free leaf library that must run under both IronPython 2.7 (it is loaded into Rhino via the Honeybee-PH plugins) and CPython 3.10+. Tests: python -m pytest. For contributor/agent orientation see CLAUDE.md and the context/ folder.


Tests versions IronPython

Download files

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

Source Distribution

ph_units-1.5.41.tar.gz (34.3 kB view details)

Uploaded Source

Built Distribution

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

ph_units-1.5.41-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

Details for the file ph_units-1.5.41.tar.gz.

File metadata

  • Download URL: ph_units-1.5.41.tar.gz
  • Upload date:
  • Size: 34.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ph_units-1.5.41.tar.gz
Algorithm Hash digest
SHA256 aeb0381e2d5f09aec32ef9c798ec2cf789b3707b5637ccca0421bfacd053b80b
MD5 386baf87f30d91baa2cf589dbcc0c1f0
BLAKE2b-256 cdfaf1305a4731035c5cb5882403bcb19d8f482de203c6db05961342ced2baf0

See more details on using hashes here.

Provenance

The following attestation bundles were made for ph_units-1.5.41.tar.gz:

Publisher: ci.yml on PH-Tools/PH_units

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ph_units-1.5.41-py3-none-any.whl.

File metadata

  • Download URL: ph_units-1.5.41-py3-none-any.whl
  • Upload date:
  • Size: 32.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ph_units-1.5.41-py3-none-any.whl
Algorithm Hash digest
SHA256 190abcc8ff041df0c9b186eb6cf828971831769c3bc4d66b81a06cc882ec89f3
MD5 78cde63e930a66d12a8abad236e61ce8
BLAKE2b-256 7b154f3c183c68e03cbb9d9bdb935136d3d6906542dd4cac831a7d5f35d2929f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ph_units-1.5.41-py3-none-any.whl:

Publisher: ci.yml on PH-Tools/PH_units

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.5.42

2 files

This release

1.5.41 This release

2 files

1.5.40

2 files

1.5.39

2 files

1.5.38

2 files

1.5.37

2 files

1.5.36

2 files

1.5.35

2 files

1.5.34

2 files

1.5.33

2 files

1.5.32

2 files

1.5.28

2 files

1.5.27

2 files

1.5.26

2 files

1.5.25

2 files

1.5.24

2 files

1.5.23

2 files

1.5.22

2 files

1.5.21

2 files

1.5.20

2 files

1.5.19

2 files

1.5.18

2 files

1.5.17

2 files

1.5.16

2 files

1.5.15

2 files

1.5.14

2 files

1.5.13

2 files

1.5.12

2 files

1.5.11

2 files

1.5.9

2 files

1.5.8

2 files

1.5.7

2 files

1.5.6

2 files

1.5.5

2 files

1.5.4

2 files

1.5.3

2 files

1.5.2

2 files

1.5.1

2 files

1.5.0

2 files

1.4.1

2 files

1.4.0

2 files

1.3.1

2 files

1.3.0

2 files

1.2.0

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

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