Name | unit-simple JSON |
Version |
1.0.24
JSON |
| download |
home_page | None |
Summary | A simple measurement unit API to handle basic unit conversions. |
upload_time | 2024-07-23 19:47:53 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.7 |
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> |
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/unit_simple.yml/badge.svg)](https://github.com/SamuelAndresPascal/cosmoloj-py/actions)
[![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)
* [Documentation](#documentation)
## 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 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 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 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 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 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 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 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 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 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 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/unit_simple/latest/)
[Trunk](https://cosmoloj.com/mkdocs/unit_simple/master/)
Raw data
{
"_id": null,
"home_page": null,
"name": "unit-simple",
"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/de/62/cf73bddb64381c612b390c22676ec20618c2c36ca99bb1e81fb428349d8b/unit_simple-1.0.24.tar.gz",
"platform": null,
"description": "# Simple Unit (Python implementation)\n\n[![example workflow](https://github.com/SamuelAndresPascal/cosmoloj-py/actions/workflows/unit_simple.yml/badge.svg)](https://github.com/SamuelAndresPascal/cosmoloj-py/actions)\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* [Documentation](#documentation)\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 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 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 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 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 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 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 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 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 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 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/unit_simple/latest/)\n\n[Trunk](https://cosmoloj.com/mkdocs/unit_simple/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.24",
"project_urls": {
"Documentation": "http://cosmoloj.com/mkdocs/unit_simple/1.0.24",
"Homepage": "https://github.com/SamuelAndresPascal/cosmoloj-py/tree/unit_simple-1.0.24/unit_simple",
"Specification": "http://cosmoloj.com/su"
},
"split_keywords": [
"units",
" converter",
" unit converter",
" measure",
" units of measurement"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "538e8e40426894e6342342dc9526de7393ea7d735dc85e0986c848eb74e9a59b",
"md5": "baf0c1995cc9df9aa7c73a90cce944db",
"sha256": "a257c15a44c31ab87712230f30ab2f55c3a8ce000e43b26800eedc910f037803"
},
"downloads": -1,
"filename": "unit_simple-1.0.24-py3-none-any.whl",
"has_sig": false,
"md5_digest": "baf0c1995cc9df9aa7c73a90cce944db",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 7860,
"upload_time": "2024-07-23T19:47:50",
"upload_time_iso_8601": "2024-07-23T19:47:50.867414Z",
"url": "https://files.pythonhosted.org/packages/53/8e/8e40426894e6342342dc9526de7393ea7d735dc85e0986c848eb74e9a59b/unit_simple-1.0.24-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "de62cf73bddb64381c612b390c22676ec20618c2c36ca99bb1e81fb428349d8b",
"md5": "6d34aae10815665dfcf146016acfd8e0",
"sha256": "9fc7bf0cf147defa5930ec4e9190d06b31e6b099ccef770e64cd7fc281d1f4ac"
},
"downloads": -1,
"filename": "unit_simple-1.0.24.tar.gz",
"has_sig": false,
"md5_digest": "6d34aae10815665dfcf146016acfd8e0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 9724,
"upload_time": "2024-07-23T19:47:53",
"upload_time_iso_8601": "2024-07-23T19:47:53.211112Z",
"url": "https://files.pythonhosted.org/packages/de/62/cf73bddb64381c612b390c22676ec20618c2c36ca99bb1e81fb428349d8b/unit_simple-1.0.24.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-23 19:47:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SamuelAndresPascal",
"github_project": "cosmoloj-py",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "unit-simple"
}