unit-simple


Nameunit-simple JSON
Version 1.0.19 PyPI version JSON
download
home_pageNone
SummaryA simple measurement unit API to handle basic unit conversions.
upload_time2024-05-01 13:04:40
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
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)

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

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

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



## Standard usage

The Simple Unit Python implementation standard usage refers to method and classes defined in the Simple Unit specification.

Usage of transformed units:

```py
import unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "unit-simple",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "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/89/7b/91738fe4d9fa43a4622a6d7db4048007bf7daeb74c1f913e162d0e7d7a84/unit_simple-1.0.19.tar.gz",
    "platform": null,
    "description": "# Simple Unit (Python implementation)\n\n[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/unit_simple/badges/version.svg)](https://anaconda.org/cosmoloj/unit_simple)\n[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/unit_simple/badges/latest_release_date.svg)](https://anaconda.org/cosmoloj/unit_simple)\n[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/unit_simple/badges/latest_release_relative_date.svg)](https://anaconda.org/cosmoloj/unit_simple)\n[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/unit_simple/badges/platforms.svg)](https://anaconda.org/cosmoloj/unit_simple)\n[![Anaconda-Server Badge](https://anaconda.org/cosmoloj/unit_simple/badges/license.svg)](https://anaconda.org/cosmoloj/unit_simple)\n\n[![PyPI repository Badge](https://badge.fury.io/py/unit_simple.svg)](https://badge.fury.io/py/unit_simple)\n\n* [Standard usage](#standard-usage)\n* [Operator overloading usage](#operator-overloading-usage)\n\n\n\n## Standard usage\n\nThe Simple Unit Python implementation standard usage refers to method and classes defined in the Simple Unit specification.\n\nUsage of transformed units:\n\n```py\nimport unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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 unit_simple.unit_simple 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",
    "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.19",
    "project_urls": {
        "Documentation": "http://cosmoloj.com/mkdocs/unit_simple/1.0.19",
        "Homepage": "https://github.com/SamuelAndresPascal/cosmoloj-py/tree/unit_simple-1.0.19/unit_simple",
        "Specification": "http://cosmoloj.com/su"
    },
    "split_keywords": [
        "units",
        " converter",
        " unit converter",
        " measure",
        " units of measurement"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "af5eff79f33c50504ed09bc034c6f678ae225ad701205ad42231e0ba30e72d49",
                "md5": "0b56a11756dd27ead4aef30d9f48abe1",
                "sha256": "26af7fdf537b537c46cd9678b88a8d3bcd444b9abe475ec49a6aaf4d61605974"
            },
            "downloads": -1,
            "filename": "unit_simple-1.0.19-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0b56a11756dd27ead4aef30d9f48abe1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 6557,
            "upload_time": "2024-05-01T13:04:39",
            "upload_time_iso_8601": "2024-05-01T13:04:39.539144Z",
            "url": "https://files.pythonhosted.org/packages/af/5e/ff79f33c50504ed09bc034c6f678ae225ad701205ad42231e0ba30e72d49/unit_simple-1.0.19-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "897b91738fe4d9fa43a4622a6d7db4048007bf7daeb74c1f913e162d0e7d7a84",
                "md5": "c42eb78d0ab61eecdeb6db32a35f1d7b",
                "sha256": "853bdc375a344a97f6cf35f52fe796c6cd123f04fb9477e23a61d62a49837a98"
            },
            "downloads": -1,
            "filename": "unit_simple-1.0.19.tar.gz",
            "has_sig": false,
            "md5_digest": "c42eb78d0ab61eecdeb6db32a35f1d7b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 7581,
            "upload_time": "2024-05-01T13:04:40",
            "upload_time_iso_8601": "2024-05-01T13:04:40.950671Z",
            "url": "https://files.pythonhosted.org/packages/89/7b/91738fe4d9fa43a4622a6d7db4048007bf7daeb74c1f913e162d0e7d7a84/unit_simple-1.0.19.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-01 13:04:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SamuelAndresPascal",
    "github_project": "cosmoloj-py",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "lcname": "unit-simple"
}
        
Elapsed time: 0.29144s