metrum
A collection of unit of measure.
metrum is a Python library that provides a simple and intuitive way to work
with units of measurement in your code. It helps improve code readability and
ensures consistency by converting all quantities to a standard set of reference
units (SI units).
Installation
You can install metrum using pip:
pip install metrum
Usage
Using metrum is straightforward. Import the units you need and use them in
your calculations.
from metrum.units import cm, g, usc_in
height = 180 * cm # cm = 0.01 * m, so height is 1.8 (meters)
weight = 250 * g # g = 0.001 * kg, so weight is 0.25 (kilograms)
width = 10 * usc_in # usc_in = 0.0254 * m, so width is 0.254 (meters)
print(f"Height: {height} m")
print(f"Weight: {weight} kg")
print(f"Width: {width} m")
This makes your code more explicit and easier to understand, as the units are clearly stated. All conversions are handled automatically, bringing the values to the base SI units.
Reference Units
The library converts all units to a consistent set of reference units. The base units are the 7 SI base units, and the rest are SI derived units.
| Quantity | Unit | Var. Name |
|---|---|---|
| Time | second | s |
| Length | metre | m |
| Mass | kilogram | kg |
| Electric current | ampere | A |
| Temperature | kelvin | K |
| Amount of substance | mole | mol |
| Luminous intensity | candela | cd |
| ... and many more derived units ... |
For each base unit, metrum also provides prefixed versions (pico, nano,
micro, milli, centi, deci, deca, hetto, kilo, mega, giga, tera).
Special Units
Besides the SI units, metrum also supports a variety of special units,
including:
- Time:
min,h,d - Length:
au(astronomical unit), US Customary units (usc_in,usc_ft,usc_mi, etc.) - Mass:
t(tonne),Da(dalton), US Customary units (usc_oz,usc_lb, etc.) - and many more.
For a complete list of all available units, see the metrum.units module documentation page.
Contributing
Contributions are welcome! If you have a unit of measure you'd like to see added or want to improve the library in any other way, please feel free to open an issue or submit a pull request on our GitHub repository.
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Author
- Marcello Del Buono - m.delbuono@google.com
Project Links
Release files for metrum 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| metrum-0.1.0.tar.gz | 2.8 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| metrum-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.8 MB
Release files / metrum-0.1.0.tar.gz
| Download URL | metrum-0.1.0.tar.gz |
|---|---|
| Size | 2.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71d240fd9ec3113f13aede3f9e815d39f10627c1a2f7a56960ab87375d554499
|
|
BLAKE2b-256 checksum How to use checksums |
0031b72323cfa08b827e8cf18112d3735de8897a7639cb443736d3c3323e8259
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / metrum-0.1.0-py3-none-any.whl
| Download URL | metrum-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8be9cf5e0971983a4c54191c9f5081c689179568b274cf9cb65d73815936502e
|
|
BLAKE2b-256 checksum How to use checksums |
13ada6ec3af6810bbb09a66d6bee499f32da2f95fa67cda8126ec01b50afa75c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|