Skip to main content

🔄 Python Custom Unit Converter (PyCUC)

PyCUC Logo

PyPI Downloads PyPI Python Version License Read the Docs

Python Custom Unit Converter (PyCUC) is an open-source package designed to simplify unit conversions in Python. With PyCUC, you can effortlessly create custom conversion factors, convert between units, and streamline calculations in various fields, such as physics, engineering, and scientific computing.

✨ Key Features

  • 📐 Custom Conversion Factors: Define your own conversion factors for unique units
  • 🔄 Flexible Unit Conversions: Convert between units with ease, using simple and intuitive methods
  • 🪶 Lightweight: Minimal dependencies and optimized for performance
  • 🚀 Easy to Use: Simple installation and straightforward usage

References

PyCUC supports a wide range of unit conversions. Below are the updated references you can use for conversions:

  • Pressure: Convert between units like bar, Pa, kPa, MPa, atm, mmHg, psi, etc.
  • Temperature: Convert between units like C, F, K, R.
  • Density: Convert between units like g/cm3, kg/L, kg/m3, lb/ft3, mol/L, kmol/m3, etc.
  • Concentration: Convert between units like mol/m3, mol/L, M, mM, uM, nM, etc.
  • Energy: Convert between units like J, kJ, cal, kcal, Wh, kWh, BTU, ft-lb, etc.
  • Energy Rate: Convert between units like W, kW, MW, HP, BTU/s, BTU/min, BTU/h, cal/s, etc.
  • Gibbs Free Energy: Convert between units like J/mol, kJ/mol, J/kmol, cal/mol, kcal/mol, J/kg, etc.
  • Enthalpy: Convert between units like J/mol, kJ/mol, J/kmol, cal/mol, kcal/mol, J/kg, etc.
  • Heat Capacity: Convert between units like J/kg.K, kJ/kg.K, cal/kg.K, BTU/lb.F, J/mol.K, kJ/mol.K, etc.
  • Heat Transfer Coefficient: Convert between units like W/m2.K, kW/m2.K, W/cm2.K, W/ft2.K, BTU/(hr.ft2.F), etc.
  • Volume: Convert between units like m3, L, cm3, dm3, ft3, in3, gal(US), gal(UK), etc.
  • Mass: Convert between units like kg, g, mg, lb, oz, t, st, etc.
  • Molecular Weight: Convert between units like g/mol, kg/kmol, lb/lbmol, kg/mol, mg/mol, g/kmol, etc.
  • Power: Convert between units like W, kW, MW, GW, HP, BTU/h, ft-lb/min, etc.
  • Length: Convert between units like m, cm, mm, km, ft, in, yd, mi, etc.
  • Area Per Length: Convert between units like m2/m, cm2/m, mm2/m, ft2/ft, in2/in, yd2/yd, mi2/mi, etc.
  • Area: Convert between units like m2, cm2, mm2, km2, ft2, in2, yd2, hectare, acre, etc.
  • Force: Convert between units like N, kN, lbf, kgf, dyn, ozf, etc.
  • Viscosity: Convert between units like P, cP, Pa.s, mPa.s, g/cm.s, N.s/m2, lb/ft.s, etc.
  • Flow Rate: Convert between units like mol/s, kmol/h, kg/s, g/min, m3/s, L/min, ft3/min, gal/min, bbl/day, etc.
  • Velocity: Convert between units like m/s, cm/s, mm/s, km/h, ft/s, ft/min, in/s, mph, knot, etc.

📊 Google Colab

You can use the following code to run PyCUC in Google Colab:

Open In Colab

📥 Installation

Install PyCUC with pip:

import pycuc
# check version
print(pycuc.__version__)

🔍 Usage Examples

📋 Example 1: Basic Operations

🔍 Check References

print(pycuc.check_reference('pressure'))

🛠️ Create a Custom Unit Converter

# ! pressure
my_cuc_1 = pycuc.create_cuc(1, 'MPa')
# convert to Pa
print(my_cuc_1.convert('Pa'))
print(my_cuc_1.convert('bar'))
print(my_cuc_1.convert('kPa'))

# ! temperature
my_cuc_2 = pycuc.create_cuc(358, 'K')
# convert to K
print(my_cuc_2.convert('C'))
print(my_cuc_2.convert('F'))
print(my_cuc_2.convert('R'))

↔️ Convert From/To

# ! pressure
print(pycuc.convert_from_to(1, 'MPa', 'Pa'))
# ! temperature
print(pycuc.convert_from_to(358, 'K', 'C'))
print(pycuc.convert_from_to(25, 'C', 'K'))

🔄 Convert From/To (Short Format)

# ! pressure
print(pycuc.to(125, 'MPa => Pa'))
# ! temperature
print(pycuc.to(360, 'K => C'))
print(pycuc.to(250, 'C => K'))

Area Per Length Conversion

# ! check area per length reference
print(pycuc.check_reference('AREA_PER_LENGTH'))

# ! metric area per length
print(pycuc.to(1, 'm2/m => cm2/m'))
print(pycuc.to(1, 'cm2/m => m2/m'))
print(pycuc.to(1, 'm2/m => mm2/m'))
print(pycuc.to(1, 'mm2/m => m2/m'))

# ! imperial area per length
print(pycuc.to(1, 'm2/m => ft2/ft'))
print(pycuc.to(1, 'ft2/ft => m2/m'))
print(pycuc.to(1, 'm2/m => in2/in'))
print(pycuc.to(1, 'in2/in => m2/m'))

✏️ Define a New Unit

# ! heat capacity unit: J/mol.K
my_cuc_3 = pycuc.create_cuc(25, 'J/mol.K')
# add custom
my_cuc_3.add_custom_unit('J/mol.K', 1)
my_cuc_3.add_custom_unit('kJ/mol.K', 1000)
# conversion
print(my_cuc_3.convert('J/mol.K'))
print(my_cuc_3.convert('kJ/mol.K'))

📚 Check Reference

# ! pressure
print(my_cuc_3.check_reference('pressure'))
# ! temperature
print(my_cuc_3.check_reference('temperature'))
# ! custom
print(my_cuc_3.check_reference('custom'))

📋 Example 2: Advanced Usage

📂 Load Custom Units from YML Files

# load unit yml file
unit_file = os.path.join(os.getcwd(), 'test', 'custom-unit.yml')
my_cuc = pycuc.go(reference_file=unit_file)

🔀 Using from_to Method

# ! pressure
print(my_cuc.from_to(1, 'MPa', 'Pa'))

🚀 Using to Method

# ! pressure
print(my_cuc.to(125, 'MPa => Pa'))

📋 Check References

# ! from yml file
print(my_cuc.check_reference('custom::CUSTOM'))
print(my_cuc.check_reference('custom::HEAT-CAPACITY'))
print(my_cuc.check_reference('custom::ENERGY'))

❓ FAQ

For any questions, contact me on LinkedIn

👨‍💻 Authors

Metadata

Release files for pycuc 2.10.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 pycuc 2.10.0
File Size Uploaded
pycuc-2.10.0.tar.gz 27.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycuc 2.10.0
File Interpreter ABI Platform
pycuc-2.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 62.8 kB

Release files / pycuc-2.10.0.tar.gz

Download URL pycuc-2.10.0.tar.gz
Size 27.8 kB
Tags Source
SHA-256 checksum
How to use checksums
905cbfb5b89bfb0aee06a12d279b784f4add38d24312bd5af6df1b65ba622e20
BLAKE2b-256 checksum
How to use checksums
f48cb07aac1e41fc6fc85564d696596745fa9b95764c068271e2335eb90274a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.3

Release files / pycuc-2.10.0-py3-none-any.whl

Download URL pycuc-2.10.0-py3-none-any.whl
Size 35.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
388ed084c431edebf935b308308cdd2ffb4988838966678c82a9c9392e5dd404
BLAKE2b-256 checksum
How to use checksums
930d4f0a6fbc1b95fb5ed2988bbc74a1d237d8d19c497d940e0ca64817edd37c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.3

Release history Release notifications | RSS feed

3.1.0

2 release files

3.0.0

2 release files

This release

2.10.0 This release

2 release files

2.9.0

2 release files

2.8.0

2 release files

2.7.1

2 release files

2.7.0

2 release files

2.6.0

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release 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