Easy engineering notation
Project description
Purpose
To easily work with human-readable engineering notation. I wrote this as a quick tool for my own use. I found that I was writing the same functionality into multiple packages and would like a quick pip-installable package to take care of this manipulation for me. The package should be easily extended for other use cases. The package is unit-less, so only operates on numeric values. Unit detection may be added in future versions.
Installation
Install using pip or uv:
pip install engineering_notation
uv add engineering_notation
Usage
There are multiple ways of initializing a number to a particular value, but a string is the preferred method:
>>> from engineering_notation import EngNumber
>>> EngNumber('10k')
10k
>>> EngNumber('10000')
10k
>>> EngNumber(10000)
10k
>>> EngNumber(10000.0)
10k
>>> EngNumber(1e4)
10k
Where decimals are involved, we use a default precision of 2 digits:
>>> EngNumber('4.99k')
4.99k
>>> EngNumber('4.9k')
4.90k
This behavior can truncate your results in some cases, and cause your number to round. To specify more or less digits, simply specify the precision in the declaration:
>>> EngNumber('4.999k')
5k
>>> EngNumber('4.999k', precision=3)
4.999k
Most operations that you would perform on numeric values are valid, although all operations are not implemented:
>>> EngNumber('2.2k') * 2
4.40k
>>> 2 * EngNumber('2.2k')
4.40k
>>> EngNumber(1.2) > EngNumber('3.3k')
False
>>> EngNumber(1.2) <= EngNumber('3.3k')
True
>>> EngNumber('3.3k') == EngNumber(3300)
True
All of the above operations are also possible on the EngUnit() class as well. The only difference is
that units must match for addition/subtraction/comparison operations. Although multiplication and division
operations will work numerically, they may not always be strictly correct. This is because EngUnit is not
intended to replace a computer algebra system!
>>> EngUnit('2s') / EngUnit('4rotations')
0.5s/rotations
Additionally, since there are 'reserved' letters for sizing the number, you must be careful with your units!
>>> EngUnit('2mm')
2mm # <<< this value equivalent to "0.002m"
>>> EngUnit('2meter')
2meter # <<< this value is equivalent to "0.002eter", the "m" was used to scale the unit!
>>> EngUnit('2', unit='meter') # <<< this will work better
Contributions
Contributions are welcome. Feel free to make feature requests in the issues.
Running Tests
If you are developing, you probably want to perform a local editable installation:
uv run -m pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file engineering_notation-0.13.1.tar.gz.
File metadata
- Download URL: engineering_notation-0.13.1.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f326966a2aa88675c025f0b46a601afc3c76936fa8eaedc2337b1cb634e5f5a3
|
|
| MD5 |
7aa647913fdae8af52cdff80f7bae2db
|
|
| BLAKE2b-256 |
93fcd61e177bfe089e0f224d414c775f46c719e24cfd257d4e1845718fa2e44b
|
File details
Details for the file engineering_notation-0.13.1-py3-none-any.whl.
File metadata
- Download URL: engineering_notation-0.13.1-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e106f6570935b2d60cf84a4a80ddfd31de7f4d4be6862d95ffa1ee0c54c83afb
|
|
| MD5 |
f4d93f874178c8c776b03c837b704064
|
|
| BLAKE2b-256 |
5f36d2e3c529f2720afa343b62ce94629da1c52a2ff9506e6df2b86e069952a5
|