simpleunit


Namesimpleunit JSON
Version 1.0.27 PyPI version JSON
download
home_pageNone
SummaryA simple measurement unit API to handle basic unit conversions.
upload_time2024-08-30 23:11:45
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseThis is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to <https://unlicense.org>
keywords units converter unit converter measure units of measurement
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Simple Unit (Python implementation)

[![example workflow](https://github.com/SamuelAndresPascal/cosmoloj-py/actions/workflows/simpleunit.yml/badge.svg)](https://github.com/SamuelAndresPascal/cosmoloj-py/actions)

[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/simpleunit/badges/version.svg)](https://anaconda.org/cosmoloj/simpleunit)
[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/simpleunit/badges/latest_release_date.svg)](https://anaconda.org/cosmoloj/simpleunit)
[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/simpleunit/badges/latest_release_relative_date.svg)](https://anaconda.org/cosmoloj/simpleunit)
[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/simpleunit/badges/platforms.svg)](https://anaconda.org/cosmoloj/simpleunit)
[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/simpleunit/badges/license.svg)](https://anaconda.org/cosmoloj/simpleunit)

[![PyPI repository Badge](https://badge.fury.io/py/simpleunit.svg)](https://badge.fury.io/py/simpleunit)

* [Standard usage](#standard-usage)
* [Operator overloading usage](#operator-overloading-usage)
* [Documentation](#documentation)

This package is the Python Reference Implementation (RI) of the Simple Unit specification. Nevertheless, it also
contains some extensions to the specification standard.

## Standard usage

The standard usage refers to methods and classes defined in the Simple Unit specification.

Usage of transformed units:

```py
import simpleunit as su

m = su.FundamentalUnit()
km = m.scale_multiply(1000)
cm = m.scale_divide(100)
cmToKm = cm.get_converter_to(km)

cmToKm.convert(3) # 0.00003
cmToKm.inverse().convert(0.00003) # 3
```

Usage of derived units:

```py
import simpleunit as su

m = su.FundamentalUnit()
km = m.scale_multiply(1000)

km2 = su.DerivedUnit(km.factor(2))
cm = m.scale_divide(100)
cm2 = su.DerivedUnit(cm.factor(2))
km2Tocm2 = km2.get_converter_to(cm2)

km2Tocm2.convert(3) # 30000000000
km2Tocm2.inverse().convert(30000000000) # 3
```

Usage of derived units combining dimensions:

```py
import simpleunit as su

m = su.FundamentalUnit()
kg = su.FundamentalUnit()
g = kg.scale_divide(1000)
ton = kg.scale_multiply(1000)
gPerM2 = su.DerivedUnit(g, m.factor(-2))
km = m.scale_multiply(1000)
tonPerKm2 = su.DerivedUnit(ton, km.factor(-2))
cm = m.scale_divide(100)
tonPerCm2 = su.DerivedUnit(ton, cm.factor(-2))
gPerM2ToTonPerKm2 = gPerM2.get_converter_to(tonPerKm2)
gPerM2ToTonPerCm2 = gPerM2.get_converter_to(tonPerCm2)

gPerM2ToTonPerKm2.convert(1) # 1
gPerM2ToTonPerKm2.inverse().convert(3) # 3
gPerM2ToTonPerCm2.convert(1) # 1e-4
gPerM2ToTonPerCm2.convert(3) # 3e-10
gPerM2ToTonPerCm2.offset() # 0.0
gPerM2ToTonPerCm2.scale() # 1e-10
gPerM2ToTonPerCm2.inverse().offset() # -0.0
gPerM2ToTonPerCm2.inverse().convert(3e-10) # 3
```

Usage of temperatures (affine and linear conversions):

```py
import simpleunit as su

k = su.FundamentalUnit()
c = k.shift(273.15)
kToC = k.get_converter_to(c)

kToC.convert(0) # -273.15
kToC.inverse().convert(0) # 273.15

# combined with other units, temperatures only keep their linear conversion part
m = su.FundamentalUnit()
cPerM = su.DerivedUnit(c, m.factor(-1))
kPerM = su.DerivedUnit(k, m.factor(-1))
kPerMToCPerM = kPerM.get_converter_to(cPerM)

kPerMToCPerM.convert(3) # 3
kPerMToCPerM.inverse().convert(3) # 3
```

Usage of non-decimal conversions:

```py
import simpleunit as su

m = su.FundamentalUnit()
km = m.scale_multiply(1000.)

s = su.FundamentalUnit()
h = s.scale_multiply(3600.)

ms = su.DerivedUnit(m, s.factor(-1))
kmh = su.DerivedUnit(km, h.factor(-1))

msToKmh = ms.get_converter_to(kmh)

msToKmh.convert(100.) # 360
msToKmh.inverse().convert(18.) # 5
```

## Operator overloading usage

The Simple Unit Python implementation provides an extension of the base specification to overloads some language operators.

Usage of transformed units:

```py
import simpleunit as su

m = su.FundamentalUnit()
km = m * 1000
cm = m / 100
cmToKm = cm >> km

cmToKm(3) # 0.00003
(~cmToKm)(0.00003) # 3
```

Usage of derived Units:

```py
import simpleunit as su

m = su.FundamentalUnit()
km = m * 1000

km2 = km ** 2
cm = m / 100
cm2 = cm ** 2
km2Tocm2 = km2 >> cm2

km2Tocm2(3) # 30000000000
(~km2Tocm2)(30000000000) # 3
```

Usage of derived units combining dimensions:

```py
import simpleunit as su

m = su.FundamentalUnit()
kg = su.FundamentalUnit()
g = kg / 1000
ton = kg * 1000
gPerM2 = g / m ** 2
km = m * 1000
tonPerKm2 = ton * ~km ** 2
cm = m / 100
tonPerCm2 = ton / cm ** 2
gPerM2ToTonPerKm2 = gPerM2 >> tonPerKm2
gPerM2ToTonPerCm2 = tonPerCm2 << gPerM2

gPerM2ToTonPerKm2(1) # 1
(~gPerM2ToTonPerKm2)(3) # 3
gPerM2ToTonPerCm2(1) # 1e-10
gPerM2ToTonPerCm2(3) # 3e-10
gPerM2ToTonPerCm2.offset() # 0.0
gPerM2ToTonPerCm2.scale() # 1e-10
(~gPerM2ToTonPerCm2).offset() # -0.0
(~gPerM2ToTonPerCm2)(3e-10) # 3
```

Usage of temperatures (affine and linear conversions):

```py
import simpleunit as su

k = su.FundamentalUnit()
c = k + 273.15
kToC = k >> c

kToC(0) # -273.15
(~kToC)(0) # 273.15

# combined with other units, temperatures only keep their linear conversion part
m = su.FundamentalUnit()
cPerM = c / m
kPerM = k / m
kPerMToCPerM = kPerM >> cPerM

kPerMToCPerM(3) # 3
(~kPerMToCPerM)(3) # 3
```

Usage of non-decimal conversions:

```py
import simpleunit as su

m = su.FundamentalUnit()
km = m * 1000.

s = su.FundamentalUnit()
h = s * 3600.

ms = m / s
kmh = km / h

msToKmh = ms >> kmh

msToKmh(100.) # 360
(~msToKmh)(18.) # 5
```

## Documentation

[Latest release](https://cosmoloj.com/mkdocs/simpleunit/latest/)

[Trunk](https://cosmoloj.com/mkdocs/simpleunit/master/)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "simpleunit",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "units, converter, unit converter, measure, units of measurement",
    "author": null,
    "author_email": "Samuel Andr\u00e9s <samuel.andres@yahoo.fr>",
    "download_url": "https://files.pythonhosted.org/packages/50/72/d8cd24e04f943e438dc4bbcab40ff5030caf917748e36bf9a770c6850940/simpleunit-1.0.27.tar.gz",
    "platform": null,
    "description": "# Simple Unit (Python implementation)\n\n[![example workflow](https://github.com/SamuelAndresPascal/cosmoloj-py/actions/workflows/simpleunit.yml/badge.svg)](https://github.com/SamuelAndresPascal/cosmoloj-py/actions)\n\n[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/simpleunit/badges/version.svg)](https://anaconda.org/cosmoloj/simpleunit)\n[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/simpleunit/badges/latest_release_date.svg)](https://anaconda.org/cosmoloj/simpleunit)\n[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/simpleunit/badges/latest_release_relative_date.svg)](https://anaconda.org/cosmoloj/simpleunit)\n[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/simpleunit/badges/platforms.svg)](https://anaconda.org/cosmoloj/simpleunit)\n[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/simpleunit/badges/license.svg)](https://anaconda.org/cosmoloj/simpleunit)\n\n[![PyPI repository Badge](https://badge.fury.io/py/simpleunit.svg)](https://badge.fury.io/py/simpleunit)\n\n* [Standard usage](#standard-usage)\n* [Operator overloading usage](#operator-overloading-usage)\n* [Documentation](#documentation)\n\nThis package is the Python Reference Implementation (RI) of the Simple Unit specification. Nevertheless, it also\ncontains some extensions to the specification standard.\n\n## Standard usage\n\nThe standard usage refers to methods and classes defined in the Simple Unit specification.\n\nUsage of transformed units:\n\n```py\nimport simpleunit as su\n\nm = su.FundamentalUnit()\nkm = m.scale_multiply(1000)\ncm = m.scale_divide(100)\ncmToKm = cm.get_converter_to(km)\n\ncmToKm.convert(3) # 0.00003\ncmToKm.inverse().convert(0.00003) # 3\n```\n\nUsage of derived units:\n\n```py\nimport simpleunit as su\n\nm = su.FundamentalUnit()\nkm = m.scale_multiply(1000)\n\nkm2 = su.DerivedUnit(km.factor(2))\ncm = m.scale_divide(100)\ncm2 = su.DerivedUnit(cm.factor(2))\nkm2Tocm2 = km2.get_converter_to(cm2)\n\nkm2Tocm2.convert(3) # 30000000000\nkm2Tocm2.inverse().convert(30000000000) # 3\n```\n\nUsage of derived units combining dimensions:\n\n```py\nimport simpleunit as su\n\nm = su.FundamentalUnit()\nkg = su.FundamentalUnit()\ng = kg.scale_divide(1000)\nton = kg.scale_multiply(1000)\ngPerM2 = su.DerivedUnit(g, m.factor(-2))\nkm = m.scale_multiply(1000)\ntonPerKm2 = su.DerivedUnit(ton, km.factor(-2))\ncm = m.scale_divide(100)\ntonPerCm2 = su.DerivedUnit(ton, cm.factor(-2))\ngPerM2ToTonPerKm2 = gPerM2.get_converter_to(tonPerKm2)\ngPerM2ToTonPerCm2 = gPerM2.get_converter_to(tonPerCm2)\n\ngPerM2ToTonPerKm2.convert(1) # 1\ngPerM2ToTonPerKm2.inverse().convert(3) # 3\ngPerM2ToTonPerCm2.convert(1) # 1e-4\ngPerM2ToTonPerCm2.convert(3) # 3e-10\ngPerM2ToTonPerCm2.offset() # 0.0\ngPerM2ToTonPerCm2.scale() # 1e-10\ngPerM2ToTonPerCm2.inverse().offset() # -0.0\ngPerM2ToTonPerCm2.inverse().convert(3e-10) # 3\n```\n\nUsage of temperatures (affine and linear conversions):\n\n```py\nimport simpleunit as su\n\nk = su.FundamentalUnit()\nc = k.shift(273.15)\nkToC = k.get_converter_to(c)\n\nkToC.convert(0) # -273.15\nkToC.inverse().convert(0) # 273.15\n\n# combined with other units, temperatures only keep their linear conversion part\nm = su.FundamentalUnit()\ncPerM = su.DerivedUnit(c, m.factor(-1))\nkPerM = su.DerivedUnit(k, m.factor(-1))\nkPerMToCPerM = kPerM.get_converter_to(cPerM)\n\nkPerMToCPerM.convert(3) # 3\nkPerMToCPerM.inverse().convert(3) # 3\n```\n\nUsage of non-decimal conversions:\n\n```py\nimport simpleunit as su\n\nm = su.FundamentalUnit()\nkm = m.scale_multiply(1000.)\n\ns = su.FundamentalUnit()\nh = s.scale_multiply(3600.)\n\nms = su.DerivedUnit(m, s.factor(-1))\nkmh = su.DerivedUnit(km, h.factor(-1))\n\nmsToKmh = ms.get_converter_to(kmh)\n\nmsToKmh.convert(100.) # 360\nmsToKmh.inverse().convert(18.) # 5\n```\n\n## Operator overloading usage\n\nThe Simple Unit Python implementation provides an extension of the base specification to overloads some language operators.\n\nUsage of transformed units:\n\n```py\nimport simpleunit as su\n\nm = su.FundamentalUnit()\nkm = m * 1000\ncm = m / 100\ncmToKm = cm >> km\n\ncmToKm(3) # 0.00003\n(~cmToKm)(0.00003) # 3\n```\n\nUsage of derived Units:\n\n```py\nimport simpleunit as su\n\nm = su.FundamentalUnit()\nkm = m * 1000\n\nkm2 = km ** 2\ncm = m / 100\ncm2 = cm ** 2\nkm2Tocm2 = km2 >> cm2\n\nkm2Tocm2(3) # 30000000000\n(~km2Tocm2)(30000000000) # 3\n```\n\nUsage of derived units combining dimensions:\n\n```py\nimport simpleunit as su\n\nm = su.FundamentalUnit()\nkg = su.FundamentalUnit()\ng = kg / 1000\nton = kg * 1000\ngPerM2 = g / m ** 2\nkm = m * 1000\ntonPerKm2 = ton * ~km ** 2\ncm = m / 100\ntonPerCm2 = ton / cm ** 2\ngPerM2ToTonPerKm2 = gPerM2 >> tonPerKm2\ngPerM2ToTonPerCm2 = tonPerCm2 << gPerM2\n\ngPerM2ToTonPerKm2(1) # 1\n(~gPerM2ToTonPerKm2)(3) # 3\ngPerM2ToTonPerCm2(1) # 1e-10\ngPerM2ToTonPerCm2(3) # 3e-10\ngPerM2ToTonPerCm2.offset() # 0.0\ngPerM2ToTonPerCm2.scale() # 1e-10\n(~gPerM2ToTonPerCm2).offset() # -0.0\n(~gPerM2ToTonPerCm2)(3e-10) # 3\n```\n\nUsage of temperatures (affine and linear conversions):\n\n```py\nimport simpleunit as su\n\nk = su.FundamentalUnit()\nc = k + 273.15\nkToC = k >> c\n\nkToC(0) # -273.15\n(~kToC)(0) # 273.15\n\n# combined with other units, temperatures only keep their linear conversion part\nm = su.FundamentalUnit()\ncPerM = c / m\nkPerM = k / m\nkPerMToCPerM = kPerM >> cPerM\n\nkPerMToCPerM(3) # 3\n(~kPerMToCPerM)(3) # 3\n```\n\nUsage of non-decimal conversions:\n\n```py\nimport simpleunit as su\n\nm = su.FundamentalUnit()\nkm = m * 1000.\n\ns = su.FundamentalUnit()\nh = s * 3600.\n\nms = m / s\nkmh = km / h\n\nmsToKmh = ms >> kmh\n\nmsToKmh(100.) # 360\n(~msToKmh)(18.) # 5\n```\n\n## Documentation\n\n[Latest release](https://cosmoloj.com/mkdocs/simpleunit/latest/)\n\n[Trunk](https://cosmoloj.com/mkdocs/simpleunit/master/)\n",
    "bugtrack_url": null,
    "license": "This is free and unencumbered software released into the public domain.  Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.  In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  For more information, please refer to <https://unlicense.org> ",
    "summary": "A simple measurement unit API to handle basic unit conversions.",
    "version": "1.0.27",
    "project_urls": {
        "Documentation": "http://cosmoloj.com/mkdocs/simpleunit/1.0.27",
        "Homepage": "https://github.com/SamuelAndresPascal/cosmoloj-py/tree/simpleunit_1.0.27/simpleunit",
        "Specification": "http://cosmoloj.com/su"
    },
    "split_keywords": [
        "units",
        " converter",
        " unit converter",
        " measure",
        " units of measurement"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6dc55018bb9ab7354f2b1eb00a61c58871e7f22418228202532e9a3e1a4c38b1",
                "md5": "df2b72270edcc7c26c3ec1c0e779ab30",
                "sha256": "bc836b20d706f3e35d1b25e5f7516bed52e00eefa2265df16d61e5f579218392"
            },
            "downloads": -1,
            "filename": "simpleunit-1.0.27-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "df2b72270edcc7c26c3ec1c0e779ab30",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7918,
            "upload_time": "2024-08-30T23:11:43",
            "upload_time_iso_8601": "2024-08-30T23:11:43.959155Z",
            "url": "https://files.pythonhosted.org/packages/6d/c5/5018bb9ab7354f2b1eb00a61c58871e7f22418228202532e9a3e1a4c38b1/simpleunit-1.0.27-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5072d8cd24e04f943e438dc4bbcab40ff5030caf917748e36bf9a770c6850940",
                "md5": "b1eb9a518676a5074ce7cd23dcb5d7c1",
                "sha256": "0a2006c5c876986cabd880c50c84d85a48ec449ec90c39353d066aa8e97ae89a"
            },
            "downloads": -1,
            "filename": "simpleunit-1.0.27.tar.gz",
            "has_sig": false,
            "md5_digest": "b1eb9a518676a5074ce7cd23dcb5d7c1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9830,
            "upload_time": "2024-08-30T23:11:45",
            "upload_time_iso_8601": "2024-08-30T23:11:45.876160Z",
            "url": "https://files.pythonhosted.org/packages/50/72/d8cd24e04f943e438dc4bbcab40ff5030caf917748e36bf9a770c6850940/simpleunit-1.0.27.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-30 23:11:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SamuelAndresPascal",
    "github_project": "cosmoloj-py",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "simpleunit"
}
        
Elapsed time: 1.34725s