# UnitsPythonPackage
### Python package built with focus on simplicity, ease of use & readability.
Check out SPECIAL_UNITS in python_units/constants.py if you are missing some constants.
If your unit is missing, open a PR with your constant, the appropriate prefix and SI-unit added.
## Installation
Install with:
```
pip install units_python
```
If you have already installed this package, but want the latest version use:
```
pip install units_python --upgrade
```
## How to use:
In these examples, we have a physics problem to solve.
We will solve it using python_units to keep track of our units:
### **Physics Example 1**:
How many soccer balls (diameter of 22 cm) can fit inside a 5 x 5 x 2.7 meter room?
[See the example code here](https://github.com/Apros7/python-units/blob/main/Examples/physics_example1.py)
### **Physics Example 2**:
A runner has been running 96 km in 8 hours.
1) What are their average page?
2) If the runner continues at this pace, how far will they go in 46.2 minutes?
[See the example code here](https://github.com/Apros7/python-units/blob/main/Examples/physics_example2.py)
## Value Object parameters:
The v object parameters are:
- value: string of value and desired unit split by a space
- ten_exponent (optional): float of the ten_exponent i.e: 1.8 * 10 ** 8 m would be v("1.8 m", 8).
## Relevant methods:
- .copy() -> Value Object: returns copy of value
- .round(digits) -> None: round value to number of digits (returns nothing)
- .sqrt(n=1) -> Value Object: takes n-squareroot of value (returns changed value)
- .raw_value() -> Float: returns the value of the object
- .unit.get() -> String: returns the unit
- .to(str) -> String: input string with desired unit: "km/h", "tons", "hours". Returns string with value and unit
- .change_unit(str) -> None: change unit of value to str e.g. if it was not done corectly
- .raw() -> Value Object: the string representation has ten exponents. This gives the value without any ten exponents.
- .abs() -> Value Object: returns new value object with the objects value being the absolute value
[See this for an example of how to use some of the functions]
## Custom functions:
We supply certain relevant functions:
- sqrt(value, n=1): take n-squareroot of value
```
import units_python as up
from units_python import v
my_value = v("9 m^2")
my_value_sqrt = up.sqrt(my_value)
print(my_value_sqrt) # outputs "3 m"
```
- nsqrt(value, n): take n-squareroot of value
```
other_value = v("21 m^3")
my_value_3sqrt = up.nsqrt(my_value, 3)
print(my_value_sqrt) # outputs "3 m"
```
- round(value, digits): round value number
```
third_value = v("3.1415926535 m")
third_value_rounded = up.round(third_value, 4)
print(third_value_rounded) # outputs "3.1416 m"
```
## What units can I use?
You can find all avaliable units in **python_units.constant.UNITS** & **python_units.constant.SPECIAL_UNITS**.
You can find all avaliable prefixes in **python_units.constant.PREFIXES**.
You can combine prefixes and units in whatever way you like. You can also combine multiple units: 'ton/liter', 'kg*liter/hour' etc.
## What you, at this time, cannot do:
- exp
- value ** value (value ** constant works!)
Raw data
{
"_id": null,
"home_page": "https://github.com/Apros7/python-units",
"name": "units-python",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "units,physics,math",
"author": "Lucas Vilsen",
"author_email": "lucas.vilsen@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/c6/c2/ca87aeabe40ee62ed4ecb4537fb02e2c2f21708a43af21d5686780c0bde8/units_python-0.6.6.tar.gz",
"platform": null,
"description": "# UnitsPythonPackage\n### Python package built with focus on simplicity, ease of use & readability.\nCheck out SPECIAL_UNITS in python_units/constants.py if you are missing some constants.\n\nIf your unit is missing, open a PR with your constant, the appropriate prefix and SI-unit added.\n## Installation\nInstall with: \n```\npip install units_python\n```\nIf you have already installed this package, but want the latest version use:\n```\npip install units_python --upgrade\n```\n## How to use:\n\nIn these examples, we have a physics problem to solve. \n\nWe will solve it using python_units to keep track of our units:\n\n### **Physics Example 1**:\nHow many soccer balls (diameter of 22 cm) can fit inside a 5 x 5 x 2.7 meter room?\n\n\n[See the example code here](https://github.com/Apros7/python-units/blob/main/Examples/physics_example1.py)\n\n### **Physics Example 2**:\nA runner has been running 96 km in 8 hours. \n1) What are their average page?\n2) If the runner continues at this pace, how far will they go in 46.2 minutes?\n\n\n[See the example code here](https://github.com/Apros7/python-units/blob/main/Examples/physics_example2.py)\n\n## Value Object parameters:\nThe v object parameters are:\n- value: string of value and desired unit split by a space\n- ten_exponent (optional): float of the ten_exponent i.e: 1.8 * 10 ** 8 m would be v(\"1.8 m\", 8). \n\n## Relevant methods:\n- .copy() -> Value Object: returns copy of value\n- .round(digits) -> None: round value to number of digits (returns nothing)\n- .sqrt(n=1) -> Value Object: takes n-squareroot of value (returns changed value)\n- .raw_value() -> Float: returns the value of the object\n- .unit.get() -> String: returns the unit\n- .to(str) -> String: input string with desired unit: \"km/h\", \"tons\", \"hours\". Returns string with value and unit\n- .change_unit(str) -> None: change unit of value to str e.g. if it was not done corectly\n- .raw() -> Value Object: the string representation has ten exponents. This gives the value without any ten exponents.\n- .abs() -> Value Object: returns new value object with the objects value being the absolute value\n\n\n[See this for an example of how to use some of the functions]\n\n## Custom functions:\nWe supply certain relevant functions:\n- sqrt(value, n=1): take n-squareroot of value\n```\nimport units_python as up\nfrom units_python import v\n\nmy_value = v(\"9 m^2\")\nmy_value_sqrt = up.sqrt(my_value)\nprint(my_value_sqrt) # outputs \"3 m\"\n```\n- nsqrt(value, n): take n-squareroot of value\n```\nother_value = v(\"21 m^3\")\nmy_value_3sqrt = up.nsqrt(my_value, 3)\nprint(my_value_sqrt) # outputs \"3 m\"\n```\n- round(value, digits): round value number\n```\nthird_value = v(\"3.1415926535 m\")\nthird_value_rounded = up.round(third_value, 4)\nprint(third_value_rounded) # outputs \"3.1416 m\"\n```\n## What units can I use?\nYou can find all avaliable units in **python_units.constant.UNITS** & **python_units.constant.SPECIAL_UNITS**.\n\nYou can find all avaliable prefixes in **python_units.constant.PREFIXES**.\n\nYou can combine prefixes and units in whatever way you like. You can also combine multiple units: 'ton/liter', 'kg*liter/hour' etc.\n\n## What you, at this time, cannot do:\n- exp\n- value ** value (value ** constant works!)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Package for automatically managing units when doing calculations in python.",
"version": "0.6.6",
"project_urls": {
"Download": "https://github.com/Apros7/python-units/archive/refs/tags/v0.6.1.tar.gz",
"Homepage": "https://github.com/Apros7/python-units"
},
"split_keywords": [
"units",
"physics",
"math"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c6c2ca87aeabe40ee62ed4ecb4537fb02e2c2f21708a43af21d5686780c0bde8",
"md5": "499ac4bda354430bf6a473068f800e59",
"sha256": "fee8ce712565ca511a2c165390732bee35652568c8440bc0669e38e3375fcb7c"
},
"downloads": -1,
"filename": "units_python-0.6.6.tar.gz",
"has_sig": false,
"md5_digest": "499ac4bda354430bf6a473068f800e59",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9318,
"upload_time": "2023-09-06T10:36:14",
"upload_time_iso_8601": "2023-09-06T10:36:14.063988Z",
"url": "https://files.pythonhosted.org/packages/c6/c2/ca87aeabe40ee62ed4ecb4537fb02e2c2f21708a43af21d5686780c0bde8/units_python-0.6.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-06 10:36:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Apros7",
"github_project": "python-units",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "units-python"
}