# Measurement Converter




A powerful Python library for handling various unit conversions with high precision and type safety. Perfect for applications requiring measurement conversions, scientific calculations, and engineering tools.
## ð Key Features
- ð **Multiple Measurement Types**: Support for length, weight, volume, temperature, and more
- ðŊ **High Precision Calculations**: Configurable precision for all conversions
- ð **Type Hints**: Full typing support for better development experience
- ð **Locale Support**: Format results according to different locales
- ⥠**Batch Conversions**: Convert multiple values at once
- ð§Ū **Formula Tracking**: See the conversion formulas used
- ð ïļ **Extensible**: Easy to customize and extend
## ðĶ Installation
```bash
pip install measurement_converter
```
## ð Quick Start
```python
from measurement_converter import MeasurementConverter
from measurement_converter.types import ConversionResult
# Simple length conversion
result = MeasurementConverter.convert(100, 'km', 'm')
print(f"Result: {MeasurementConverter.format_result(result)}")
# Output: Result: 100 km = 100000 m
# Temperature conversion
temp = MeasurementConverter.convert(32, 'F', 'C')
print(f"Temperature: {MeasurementConverter.format_result(temp)}")
# Output: Temperature: 32 F = 0 C
```
## ðĄ Advanced Usage
### ð Batch Conversion
```python
# Convert multiple values at once
conversions = [
{'value': 1, 'from_unit': 'km', 'to_unit': 'm'},
{'value': 2.5, 'from_unit': 'kg', 'to_unit': 'lb'},
{'value': 30, 'from_unit': 'C', 'to_unit': 'F'}
]
results = MeasurementConverter.batch_convert(conversions)
for result in results:
print(MeasurementConverter.format_result(result))
```
### ð Unit Validation
```python
# Validate units with suggestions
validation = MeasurementConverter.validate_unit('kmh')
if not validation.is_valid:
print(f"Did you mean: {', '.join(validation.suggestions)}?")
```
### ð Formatting Options
```python
# Format results with different options
result = MeasurementConverter.convert(1, 'km', 'm')
formatted = MeasurementConverter.format_result(result, format_type='long')
print(formatted)
# Output: 1 kilometre is equal to 1000 metres
```
## ð Supported Units
### Length
- Meters (m)
- Kilometers (km)
- Centimeters (cm)
- Millimeters (mm)
- Miles (mile)
- Yards (yard)
- Feet (foot)
- Inches (inch)
- Nautical Miles (nm)
- Micrometers (Ξm)
- Picometers (pm)
### Weight
- Kilograms (kg)
- Grams (g)
- Milligrams (mg)
- Pounds (lb)
- Ounces (oz)
- Tons (ton)
- Stones (stone)
- Grains (grain)
### Volume
- Liters (l)
- Milliliters (ml)
- Gallons (gal)
- Quarts (qt)
- Cups (cup)
- Fluid Ounces (floz)
- Tablespoons (tbsp)
- Teaspoons (tsp)
### Temperature
- Celsius (C)
- Fahrenheit (F)
- Kelvin (K)
### Area
- Square Meters (m2)
- Square Kilometers (km2)
- Hectares (ha)
- Acres (acre)
- Square Feet (sqft)
- Square Inches (sqin)
## ð Type Definitions
```python
from dataclasses import dataclass
from typing import Optional, List
@dataclass
class ConversionResult:
from_value: float
from_unit: str
to_value: float
to_unit: str
formula: str
precision: int
@dataclass
class ValidationResult:
is_valid: bool
errors: Optional[List[str]] = None
suggestions: Optional[List[str]] = None
```
## ð Error Handling
```python
from measurement_converter import MeasurementConverter
from measurement_converter.errors import InvalidUnitError, ConversionError
try:
result = MeasurementConverter.convert(100, 'invalid', 'm')
except InvalidUnitError as e:
print(f"Invalid unit: {e}")
except ConversionError as e:
print(f"Conversion error: {e}")
```
## ð Best Practices
1. Always validate units before conversion
2. Use proper unit symbols from the supported units list
3. Handle errors appropriately
4. Consider precision requirements for your specific use case
5. Use batch conversions for multiple operations
6. Cache common conversion results if needed
## ð ïļ Development
```bash
# Install dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run tests with coverage
pytest --cov=measurement_converter
# Run type checking
mypy src/measurement_converter
```
## ðĪ 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
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": "https://github.com/OrenGrinker/measurementConverter",
"name": "measurement-converter",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "Oren Grinker",
"author_email": "orengr4@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f5/53/44cb9a0afb6d0ad4ebef77564542cd43be4e5bc56cbc723a272aef2d2d9f/measurement_converter-1.0.1.tar.gz",
"platform": null,
"description": "# Measurement Converter\n\n\n\n\n\nA powerful Python library for handling various unit conversions with high precision and type safety. Perfect for applications requiring measurement conversions, scientific calculations, and engineering tools.\n\n## \ud83c\udf1f Key Features\n\n- \ud83d\udcd0 **Multiple Measurement Types**: Support for length, weight, volume, temperature, and more\n- \ud83c\udfaf **High Precision Calculations**: Configurable precision for all conversions\n- \ud83d\udd0d **Type Hints**: Full typing support for better development experience\n- \ud83c\udf10 **Locale Support**: Format results according to different locales\n- \u26a1 **Batch Conversions**: Convert multiple values at once\n- \ud83e\uddee **Formula Tracking**: See the conversion formulas used\n- \ud83d\udee0\ufe0f **Extensible**: Easy to customize and extend\n\n## \ud83d\udce6 Installation\n\n```bash\npip install measurement_converter\n```\n\n## \ud83d\ude80 Quick Start\n\n```python\nfrom measurement_converter import MeasurementConverter\nfrom measurement_converter.types import ConversionResult\n\n# Simple length conversion\nresult = MeasurementConverter.convert(100, 'km', 'm')\nprint(f\"Result: {MeasurementConverter.format_result(result)}\")\n# Output: Result: 100 km = 100000 m\n\n# Temperature conversion\ntemp = MeasurementConverter.convert(32, 'F', 'C')\nprint(f\"Temperature: {MeasurementConverter.format_result(temp)}\")\n# Output: Temperature: 32 F = 0 C\n```\n\n## \ud83d\udca1 Advanced Usage\n\n### \ud83d\udd04 Batch Conversion\n\n```python\n# Convert multiple values at once\nconversions = [\n {'value': 1, 'from_unit': 'km', 'to_unit': 'm'},\n {'value': 2.5, 'from_unit': 'kg', 'to_unit': 'lb'},\n {'value': 30, 'from_unit': 'C', 'to_unit': 'F'}\n]\n\nresults = MeasurementConverter.batch_convert(conversions)\nfor result in results:\n print(MeasurementConverter.format_result(result))\n```\n\n### \ud83d\udd0d Unit Validation\n\n```python\n# Validate units with suggestions\nvalidation = MeasurementConverter.validate_unit('kmh')\nif not validation.is_valid:\n print(f\"Did you mean: {', '.join(validation.suggestions)}?\")\n```\n\n### \ud83c\udf10 Formatting Options\n\n```python\n# Format results with different options\nresult = MeasurementConverter.convert(1, 'km', 'm')\nformatted = MeasurementConverter.format_result(result, format_type='long')\nprint(formatted)\n# Output: 1 kilometre is equal to 1000 metres\n```\n\n## \ud83d\udccb Supported Units\n\n### Length\n- Meters (m)\n- Kilometers (km)\n- Centimeters (cm)\n- Millimeters (mm)\n- Miles (mile)\n- Yards (yard)\n- Feet (foot)\n- Inches (inch)\n- Nautical Miles (nm)\n- Micrometers (\u03bcm)\n- Picometers (pm)\n\n### Weight\n- Kilograms (kg)\n- Grams (g)\n- Milligrams (mg)\n- Pounds (lb)\n- Ounces (oz)\n- Tons (ton)\n- Stones (stone)\n- Grains (grain)\n\n### Volume\n- Liters (l)\n- Milliliters (ml)\n- Gallons (gal)\n- Quarts (qt)\n- Cups (cup)\n- Fluid Ounces (floz)\n- Tablespoons (tbsp)\n- Teaspoons (tsp)\n\n### Temperature\n- Celsius (C)\n- Fahrenheit (F)\n- Kelvin (K)\n\n### Area\n- Square Meters (m2)\n- Square Kilometers (km2)\n- Hectares (ha)\n- Acres (acre)\n- Square Feet (sqft)\n- Square Inches (sqin)\n\n## \ud83d\udccb Type Definitions\n\n```python\nfrom dataclasses import dataclass\nfrom typing import Optional, List\n\n@dataclass\nclass ConversionResult:\n from_value: float\n from_unit: str\n to_value: float\n to_unit: str\n formula: str\n precision: int\n\n@dataclass\nclass ValidationResult:\n is_valid: bool\n errors: Optional[List[str]] = None\n suggestions: Optional[List[str]] = None\n```\n\n## \ud83d\udd0d Error Handling\n\n```python\nfrom measurement_converter import MeasurementConverter\nfrom measurement_converter.errors import InvalidUnitError, ConversionError\n\ntry:\n result = MeasurementConverter.convert(100, 'invalid', 'm')\nexcept InvalidUnitError as e:\n print(f\"Invalid unit: {e}\")\nexcept ConversionError as e:\n print(f\"Conversion error: {e}\")\n```\n\n## \ud83d\ude80 Best Practices\n\n1. Always validate units before conversion\n2. Use proper unit symbols from the supported units list\n3. Handle errors appropriately\n4. Consider precision requirements for your specific use case\n5. Use batch conversions for multiple operations\n6. Cache common conversion results if needed\n\n## \ud83d\udee0\ufe0f Development\n\n```bash\n# Install dependencies\npip install -e \".[dev]\"\n\n# Run tests\npytest\n\n# Run tests with coverage\npytest --cov=measurement_converter\n\n# Run type checking\nmypy src/measurement_converter\n```\n\n## \ud83e\udd1d Contributing\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## \ud83d\udcdd License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n",
"bugtrack_url": null,
"license": null,
"summary": "A powerful Python library for unit conversions",
"version": "1.0.1",
"project_urls": {
"Bug Tracker": "https://github.com/OrenGrinker/measurementConverter/issues",
"Homepage": "https://github.com/OrenGrinker/measurementConverter"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5050a4cfced130b7768dbd082402c5c5a1284c4a85889d5b226a093c0f2d403d",
"md5": "4d6330ff9d385fa487d1b7a9a7ae488c",
"sha256": "df2a210c69a90812cce6d9d5abf72f277bc19284c49575bbb23fab761eff4925"
},
"downloads": -1,
"filename": "measurement_converter-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4d6330ff9d385fa487d1b7a9a7ae488c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 8401,
"upload_time": "2024-12-03T20:50:18",
"upload_time_iso_8601": "2024-12-03T20:50:18.686727Z",
"url": "https://files.pythonhosted.org/packages/50/50/a4cfced130b7768dbd082402c5c5a1284c4a85889d5b226a093c0f2d403d/measurement_converter-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f55344cb9a0afb6d0ad4ebef77564542cd43be4e5bc56cbc723a272aef2d2d9f",
"md5": "33781094a40887310fe00c444cec2686",
"sha256": "9da07c72c4e2dec54ee08e3b9e348e24088586aee768f9f843306970a5102de7"
},
"downloads": -1,
"filename": "measurement_converter-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "33781094a40887310fe00c444cec2686",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 9597,
"upload_time": "2024-12-03T20:50:20",
"upload_time_iso_8601": "2024-12-03T20:50:20.779406Z",
"url": "https://files.pythonhosted.org/packages/f5/53/44cb9a0afb6d0ad4ebef77564542cd43be4e5bc56cbc723a272aef2d2d9f/measurement_converter-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-03 20:50:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "OrenGrinker",
"github_project": "measurementConverter",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "measurement-converter"
}