| Name | dimensioned-values JSON |
| Version |
0.1.1
JSON |
| download |
| home_page | None |
| Summary | A small package for using units in Python. Allows for computation with dimensioned qauntities and allows you to convert between different units. Do anything you would do with regular floats or integers in Python except now with units. I think you'll find this implementation more elegant then most other unit packages. |
| upload_time | 2024-08-16 23:18:33 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.8 |
| license | None |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# Unit/Dimensioned Quantities Module
## Overview
The **unitvalue** Module is a Python library designed to handle various unit conversions. It allows for the creation of `UnitValue` objects, which can represent values with different units and convert between them.
## Features
- Create `UnitValue` objects with specified units and values.
- Convert between different units within the same dimension (e.g., meters to kilometers).
- Support for different measurement systems (e.g., metric and imperial).
- Arithmetic operations with unit handling (addition, subtraction, multiplication, division).
- Error handling for unsupported units and invalid operations.
## Installation
```Powershell
pip install dimensioned-values
```
## Usage
### Creating a UnitValue
To create a `UnitValue` object, use the `create_dimensioned_quantity` function:
```python
from unitvalue import create_dimensioned_quantity
# Create a UnitValue object with a specified unit and value
distance = create_dimensioned_quantity('meter', 100)
# Or initialize instance yourself
distance = UnitValue("METRIC", "DISTANCE", "m", 100)
```
### Converting Units
You can convert the unit of a `UnitValue` object using the `to` method:
```python
# Convert the distance to kilometers
distance.to(unit='kilometer')
print(distance) # Output: 0.1 kilometer
# Convert to base metric unit (Useful for Scinetifc calculations)
distance.convert_base_metric()
print(distance)
```
### Arithmetic Operations
`UnitValue` objects support arithmetic operations, maintaining unit consistency (The units do not even need to be in the same system or magnitude for you to perform arithmetic on them as the module will handle this). It is important to knwo all arithmetic operations return a value in the base metric units:
```python
from unitvalue import create_dimensioned_quantity
length1 = create_dimensioned_quantity('meter', 50)
length2 = create_dimensioned_quantity('meter', 30)
# Addition
total_length = length1 + length2
print(total_length) # Output: 80 m
# Subtraction
remaining_length = length1 - length2
print(remaining_length) # Output: 20 m
# Multiplication by a scalar
double_length = length1 * 2
print(double_length) # Output: 100 m
# Division by a scalar
half_length = length1 / 2
print(half_length) # Output: 25 m
# Multiplication between UnitValue Objects
area = lenght1 * length2
print(area) # Output: 150 m^2
# Divivsion between UnitValue Objects
l = area / length2
print(l) # Output: 50 m
# UnitValue object to the power
volume = lenght1**3
print(volume) # Output: 125000 m^3
```
### Accessing Unit Information
You can access the unit, measurement type, and system of a `UnitValue` object using properties:
```python
print(distance.get_unit) # Output: 'kilometer'
print(distance.get_measurement_type) # Output: 'LENGTH'
print(distance.get_system) # Output: 'METRIC'
```
You can access the vlaue of the dimensioned quantity using the property or the method:
```python
print(distance.value)
print(distance())
```
## Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository.
## License
This project is licensed under the MIT License.
Raw data
{
"_id": null,
"home_page": null,
"name": "dimensioned-values",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Brody Howard <brody.howard@mail.utoronto.ca>",
"download_url": "https://files.pythonhosted.org/packages/e0/fd/b5fdc27d5ceac770855cec74e59ef14e0bd8c7ee510532b5ecb990f60714/dimensioned_values-0.1.1.tar.gz",
"platform": null,
"description": "# Unit/Dimensioned Quantities Module\r\n\r\n## Overview\r\n\r\nThe **unitvalue** Module is a Python library designed to handle various unit conversions. It allows for the creation of `UnitValue` objects, which can represent values with different units and convert between them.\r\n\r\n## Features\r\n\r\n- Create `UnitValue` objects with specified units and values.\r\n- Convert between different units within the same dimension (e.g., meters to kilometers).\r\n- Support for different measurement systems (e.g., metric and imperial).\r\n- Arithmetic operations with unit handling (addition, subtraction, multiplication, division).\r\n- Error handling for unsupported units and invalid operations.\r\n\r\n## Installation\r\n\r\n```Powershell\r\npip install dimensioned-values\r\n```\r\n\r\n## Usage\r\n\r\n### Creating a UnitValue\r\n\r\nTo create a `UnitValue` object, use the `create_dimensioned_quantity` function:\r\n\r\n```python\r\nfrom unitvalue import create_dimensioned_quantity\r\n\r\n# Create a UnitValue object with a specified unit and value\r\ndistance = create_dimensioned_quantity('meter', 100)\r\n# Or initialize instance yourself\r\ndistance = UnitValue(\"METRIC\", \"DISTANCE\", \"m\", 100)\r\n```\r\n\r\n### Converting Units\r\n\r\nYou can convert the unit of a `UnitValue` object using the `to` method:\r\n\r\n```python\r\n# Convert the distance to kilometers\r\ndistance.to(unit='kilometer')\r\nprint(distance) # Output: 0.1 kilometer\r\n\r\n# Convert to base metric unit (Useful for Scinetifc calculations)\r\ndistance.convert_base_metric()\r\nprint(distance)\r\n```\r\n\r\n### Arithmetic Operations\r\n\r\n`UnitValue` objects support arithmetic operations, maintaining unit consistency (The units do not even need to be in the same system or magnitude for you to perform arithmetic on them as the module will handle this). It is important to knwo all arithmetic operations return a value in the base metric units:\r\n\r\n```python\r\nfrom unitvalue import create_dimensioned_quantity\r\n\r\nlength1 = create_dimensioned_quantity('meter', 50)\r\nlength2 = create_dimensioned_quantity('meter', 30)\r\n\r\n# Addition\r\ntotal_length = length1 + length2\r\nprint(total_length) # Output: 80 m\r\n\r\n# Subtraction\r\nremaining_length = length1 - length2\r\nprint(remaining_length) # Output: 20 m\r\n\r\n# Multiplication by a scalar\r\ndouble_length = length1 * 2\r\nprint(double_length) # Output: 100 m\r\n\r\n# Division by a scalar\r\nhalf_length = length1 / 2\r\nprint(half_length) # Output: 25 m\r\n\r\n# Multiplication between UnitValue Objects\r\narea = lenght1 * length2\r\nprint(area) # Output: 150 m^2\r\n\r\n# Divivsion between UnitValue Objects\r\nl = area / length2\r\nprint(l) # Output: 50 m\r\n\r\n# UnitValue object to the power\r\nvolume = lenght1**3\r\nprint(volume) # Output: 125000 m^3\r\n```\r\n\r\n### Accessing Unit Information\r\n\r\nYou can access the unit, measurement type, and system of a `UnitValue` object using properties:\r\n\r\n```python\r\nprint(distance.get_unit) # Output: 'kilometer'\r\nprint(distance.get_measurement_type) # Output: 'LENGTH'\r\nprint(distance.get_system) # Output: 'METRIC'\r\n```\r\n\r\nYou can access the vlaue of the dimensioned quantity using the property or the method:\r\n\r\n```python\r\nprint(distance.value)\r\nprint(distance())\r\n```\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License.\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A small package for using units in Python. Allows for computation with dimensioned qauntities and allows you to convert between different units. Do anything you would do with regular floats or integers in Python except now with units. I think you'll find this implementation more elegant then most other unit packages.",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/BroRocket/unitvalue/",
"Issues": "https://github.com/BroRocket/unitvalue/issues"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4ae7963d737f5ef3d1765e736be2fd910011070db134904dbd74904288d2d8df",
"md5": "34596220b7de85c9da67308193f3156c",
"sha256": "e3ea34064a072e5b3a9385db2cc7f00ce8a77b436dfa62fe241611646091828c"
},
"downloads": -1,
"filename": "dimensioned_values-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "34596220b7de85c9da67308193f3156c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 9793,
"upload_time": "2024-08-16T23:18:32",
"upload_time_iso_8601": "2024-08-16T23:18:32.040346Z",
"url": "https://files.pythonhosted.org/packages/4a/e7/963d737f5ef3d1765e736be2fd910011070db134904dbd74904288d2d8df/dimensioned_values-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e0fdb5fdc27d5ceac770855cec74e59ef14e0bd8c7ee510532b5ecb990f60714",
"md5": "b9e83aa70c1b3035c46ad8f777b8e5aa",
"sha256": "c78dcfb265705e23e6549048b10fdb43a543dd8721a5fffc1ca720d3ceb5f3f0"
},
"downloads": -1,
"filename": "dimensioned_values-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "b9e83aa70c1b3035c46ad8f777b8e5aa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9195,
"upload_time": "2024-08-16T23:18:33",
"upload_time_iso_8601": "2024-08-16T23:18:33.830960Z",
"url": "https://files.pythonhosted.org/packages/e0/fd/b5fdc27d5ceac770855cec74e59ef14e0bd8c7ee510532b5ecb990f60714/dimensioned_values-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-16 23:18:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "BroRocket",
"github_project": "unitvalue",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "dimensioned-values"
}