Skip to main content

Unit Converter Library

Project description

What is unitflex? 📦

unitflex is a Python library for converting values between various measurement units such as length, mass, temperature, and data. It provides a clean and extensible interface to convert units with ease and even lets you customize the formatting of the result.

Supported Converters 🧪

  • Length (unitflex.length) Supports: mm, cm, m, km, in, ft, yard, mile, nm, um, etc.

  • Mass (unitflex.mass) Supports: mg, g, kg, lb, ton, carat, etc.

  • Temperature (unitflex.temper) Supports: celsius, fahrenheit, kelvin, rankine, reaumur Short names: c, f, k, r, re Symbols supported: "°c", "°f", "°r", "°re", etc.

  • Data (unitflex.data) Supports: bit, byte, kb, mb, gb, tb, pb, mbps, gbps, etc.

Parameters Explained 🔧

Each convert() function accepts up to six parameters. The first three are required, the rest are optional for customizing the output.

  1. value (required)

The numeric value to convert. Can be an int or float. Example: 100, 3.14

  1. fromUnit (required)

A string representing the source unit. Case-insensitive. Supports short and long forms. Example: "cm", "meter", "kilobyte", "°f"

  1. toUnit (required)

A string representing the target unit. Same rules as fromUnit. Example: "km", "yard", "megabit"

  1. precision (optional, default = 2)

Number of decimal places to round the result. Must be a non-negative integer. Use 0 for whole number output. Example: precision=3 → 12.345

  1. format (optional, default = "tag")

Controls how the result is formatted: "raw" → returns only the number as a int/float: "123.45" raw format is used if the conversion result will be subjected to math operations.

"tag" → returns number with unit: "123.45 cm"

"verbose" → full expression: "5 meter = 500 cm"

  1. delim (optional)

Adds a thousands separator to large numbers for readability:

True → underscore separator: 1_000_000 (default separator) default separator is good to use with raw format, because it is intended to produce int/float conversion results that can be used for further calculations.

"," → comma separator: 1,000,000

"." → dot separator: 1.000.000

False → no separator

Notes 📌

  • Units are case-insensitive.
  • Flexible naming (e.g., "kg", "kilogram", "Kilograms" all work).
  • Safe rounding with fallback if result is an integer.
  • Delimiters help with large numbers.

Another Information 🔍

This module is not yet available on PyPI, Unitflex can be cloned directly from this repository for immediate use. Once installed, users can import and use the length, mass, temper and data classes from the unitflex package. Each class provides a convert() method that accepts the value to be converted, the source unit, the target unit, the number of decimal digits, and the preferred output style.

The folder structure of this project is organized for clarity and scalability. The main package, unitflex, contains individual modules for each category of conversion (such as length.py, mass.py, data.py and temperature.py). In addition, there are directories for usage examples and test scripts, which help demonstrate the library's capabilities and ensure consistent performance through future updates.

upcoming features planned for unitflex include conversion of area, volume, time or even conversion with scientific units such as electric current, thermodynamic, amont of substance, luminous intensity, hz etc. While external contributions are currently limited as the library is in its early development stage, feedback and suggestions are more than welcome and encouraged.

Unitflex is released under the MIT License, which allows you to freely use, modify, and distribute the library as long as the original license is included. For more information about usage, structure, and licensing, please refer to the LICENSE file included in this repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unitflex-0.1.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unitflex-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file unitflex-0.1.0.tar.gz.

File metadata

  • Download URL: unitflex-0.1.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for unitflex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cc741c9d3a84b34301910f2a6a4e3bee78ff3dcd37041c2f8757d2652ee2221f
MD5 6fa2460e03bfb4c975b35c4a3c591c1a
BLAKE2b-256 d63de3b96fd93692d85e5bc71b12009cd60c5893589c7a40ba7f1c61340ec78e

See more details on using hashes here.

File details

Details for the file unitflex-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: unitflex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for unitflex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c43a801127c220b7da70546f61b56965437a1c8bba2612a9d2793a9145e9c6e7
MD5 554a7fa7d213c38fd65d1697772e4349
BLAKE2b-256 09db2f8d46393f771ef3dd6ba4f1d0ff6f1e7f7a258fc9bc06710a6a3a6a8b68

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page