mcpField
U
unit-converter

unit-converter

github.com/dkyazzentwatwaOther12465 installsUpdated 29w ago
Repository

About unit-converter

unit-converter is a Python library and CLI for converting measurements across physical dimensions. It is intended for users who need single or batch conversions, with configurable precision and optional formula details.

Key features

  1. 01Convert units across multiple categories
  2. 02Handle compound units such as speed and pressure
  3. 03Set decimal precision
  4. 04Convert lists of values in batches
  5. 05Show conversion formulas and details

Use cases

  1. 01Convert measurements in scripts or from the command line
  2. 02Convert a batch of weights between kilograms and pounds
  3. 03Inspect the formula used for a temperature conversion

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/dkyazzentwatwa/chatgpt-skills --skill unit-converter

After installing, type/unit-converterin Claude Code to confirm it loaded.

Bundled filesscripts/requirements.txtscripts/unit_converter.py

Details

From the project README

Unit Converter

Convert between units across multiple physical dimensions.

Features

  • Multiple Categories: Length, mass, temperature, time, volume, etc.
  • Compound Units: Speed, density, pressure
  • Precision Control: Configurable decimal places
  • Batch Conversion: Convert lists of values
  • Formula Display: Show conversion formulas

Quick Start

from unit_converter import UnitConverter

converter = UnitConverter()

# Simple conversion
result = converter.convert(100, "km", "miles")
print(f"100 km = {result:.2f} miles")

# With full details
result = converter.convert_with_details(72, "fahrenheit", "celsius")
print(result)

CLI Usage

# Basic conversion
python unit_converter.py 100 km miles

# Temperature
python unit_converter.py 98.6 fahrenheit celsius

# With precision
python unit_converter.py 1.5 kg lbs --precision 4

# List supported units
python unit_converter.py --list

# List units in category
python unit_converter.py --list length

# Show formula
python unit_converter.py 100 cm inches --formula

API Reference

UnitConverter Class
class UnitConverter:
    def __init__(self)

    # Conversion
    def convert(self, value: float, from_unit: str, to_unit: str) -> float
    def convert_with_details(self, value: float, from_unit: str, to_unit: str) -> dict
    def batch_convert(self, values: list, from_unit: str, to_unit: str) -> list

    # Information
    def list_categories(self) -> list
    def list_units(self, category: str = None) -> dict
    def get_formula(self, from_unit: str, to_unit: str) -> str
    def find_unit(self, query: str) -> list

Supported Categories

Length
UnitAliases
meterm
kilometerkm
centimetercm
millimetermm
inchin
footft
yardyd
milemi
nautical_milenm
Mass
UnitAliases
kilogramkg
gramg
milligrammg
poundlb, lbs
ounceoz
ton
metric_tontonne
Temperature
UnitAliases
celsiusc
fahrenheitf
kelvink
Time
UnitAliases
seconds, sec
minutemin
hourh, hr
dayd
weekwk
monthmo
yearyr
Volume
UnitAliases
literl
milliliterml
gallongal
quartqt
pintpt
cup
fluid_ouncefl_oz
cubic_meterm3
Area
UnitAliases
square_meterm2, sqm
square_kilometerkm2
square_footsqft, ft2
acre
hectareha
Speed
UnitAliases
meters_per_secondm/s, mps
kilometers_per_hourkm/h, kph
miles_per_hourmph
knotskt
Digital Storage
UnitAliases
byteb
kilobytekb
megabytemb
gigabytegb
terabytetb
Energy
UnitAliases
joulej
kilojoulekj
caloriecal
kilocaloriekcal
watt_hourwh
kilowatt_hourkwh

Example Workflows

Batch Conversion
converter = UnitConverter()
weights_kg = [50, 75, 100, 125]
weights_lbs = converter.batch_convert(weights_kg, "kg", "lbs")
for kg, lbs in zip(weights_kg, weights_lbs):
    print(f"{kg} kg = {lbs:.1f} lbs")
Find Compatible Units
converter = UnitConverter()
# Search for units
matches = converter.find_unit("meter")
# Returns: ['meter', 'kilometer', 'centimeter', ...]
Get Conversion Formula
converter = UnitConverter()
formula = converter.get_formula("celsius", "fahrenheit")
print(formula)  # "F = (C × 9/5) + 32"

Output Format

convert_with_details()
{
    "value": 100,
    "from_unit": "km",
    "to_unit": "miles",
    "result": 62.1371,
    "formula": "miles = km × 0.621371",
    "category": "length"
}

Dependencies

No external dependencies - uses Python standard library.

Comments

Markdown supported