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
pip install measurement_converter
🚀 Quick Start
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
# 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
# Validate units with suggestions
validation = MeasurementConverter.validate_unit('kmh')
if not validation.is_valid:
print(f"Did you mean: {', '.join(validation.suggestions)}?")
🌐 Formatting Options
# 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
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
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
- Always validate units before conversion
- Use proper unit symbols from the supported units list
- Handle errors appropriately
- Consider precision requirements for your specific use case
- Use batch conversions for multiple operations
- Cache common conversion results if needed
🛠️ Development
# 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
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for measurement-converter 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| measurement_converter-1.0.1.tar.gz | 9.6 kB | Without provenance | Details for measurement_converter-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| measurement_converter-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for measurement_converter-1.0.1-py3-none-any.whl |
Total release size: 18.0 kB
Release files / measurement_converter-1.0.1.tar.gz
| Download URL | measurement_converter-1.0.1.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9da07c72c4e2dec54ee08e3b9e348e24088586aee768f9f843306970a5102de7
|
|
BLAKE2b-256 checksum How to use checksums |
f55344cb9a0afb6d0ad4ebef77564542cd43be4e5bc56cbc723a272aef2d2d9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.5
|
Release files / measurement_converter-1.0.1-py3-none-any.whl
| Download URL | measurement_converter-1.0.1-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df2a210c69a90812cce6d9d5abf72f277bc19284c49575bbb23fab761eff4925
|
|
BLAKE2b-256 checksum How to use checksums |
5050a4cfced130b7768dbd082402c5c5a1284c4a85889d5b226a093c0f2d403d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.5
|
Security for measurement-converter 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.