PyCUC: A lightweight Python package for creating custom unit conversions. Easily define and convert between units with simplicity and flexibility.
Project description
🔄 Python Custom Unit Converter (PyCUC)
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:
- Density: Convert between units like kg/m³, g/cm³, lb/ft³, etc.
- Energy: Convert between units like J, kJ, cal, BTU, etc.
- Heat Capacity: Convert between units like J/mol·K, kJ/mol·K, cal/mol·K, etc.
- Volume: Convert between units like m³, L, mL, ft³, etc.
- Mass: Convert between units like kg, g, lb, oz, etc.
- Power: Convert between units like W, kW, HP, etc.
- Length: Convert between units like m, cm, mm, in, ft, etc.
- Force: Convert between units like N, kN, lbf, etc.
📊 Google Colab
You can use the following code to run PyCUC in Google 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'))
✏️ 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycuc-2.6.0.tar.gz.
File metadata
- Download URL: pycuc-2.6.0.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdff57493d6aaff82277d5d818422c936ebf3f1840361c4089d2aab083bb7b80
|
|
| MD5 |
922b786006bf3e22382c7642bc6206a2
|
|
| BLAKE2b-256 |
59e84edc209c16d117579fe9f7e161cf6b8d929358dc36bb66a22d1a982e2936
|
File details
Details for the file pycuc-2.6.0-py3-none-any.whl.
File metadata
- Download URL: pycuc-2.6.0-py3-none-any.whl
- Upload date:
- Size: 26.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4129ae731758855cdabb4bdb63b94724b8ef913f25618ff1080623c4305584c8
|
|
| MD5 |
a66594542b2a057fdde8da8eda24f39e
|
|
| BLAKE2b-256 |
98c152c8329607fd01f0ca5a844f6d04f5a4cc11f891e2d3a86851f5ffacff34
|