An object-oriented Python interface to udunits
Project description
gimli.units
An object-oriented Python interface to udunits2 built with cython.
NOTE: gimli.units includes a vendored version of udunits2 so that you do not have to install the udunits2 library separately.
Installation
pip install gimli.units
or
conda install gimli.units -c conda-forge
From Source
pip install git+https://github.com/mcflugen/gimli.git
Note: gimli.units
requires the libudunits
library. You will need to
have this installed before building gimli.units
. You can do this
using conda
,
conda install udunits2 -c conda-forge
or by building udunits2
from source (we use a
vendored version of udunits2
,
which can be found in the extern
folder of this repository).
Usage
Primarily, gimli.units is a Python module with an API that reflects that of the udunits2 library. gimli, however, also comes with a command-line interface.
API
You primarily will access gimli through gimli.units,
>>> from gimli.units import units
units is an instance of the default UnitSystem class, which contains all of the units contained in a given unit system. If you like, you can create your own unit system but, typically, the default should be fine.
units is a dict-like object whose keys are strings representing units and values are instances of those units. For example,
>>> units["m"]
Unit('meter')
>>> units["m/s"]
Unit('meter-second^-1')
>>> units["kg m-3"]
Unit('meter^-3-kilogram')
>>> units["N m"]
Unit('joule')
Every Unit instance has a to method, which returns a unit converter for converting values from one unit to another,
>>> lbs = units["lb"]
>>> kgs = units["kg"]
>>> kgs_to_lbs = kgs.to(lbs)
>>> kgs_to_lbs(1.0)
2.2046226218487757
You can also construct units that are a combination of other units.
>>> ft_per_s = units["ft / s"]
>>> m_per_s = units["m s-1"]
>>> ft_per_s.to(m_per_s)([1.0, 2.0])
array([0.3048, 0.6096])
Command-line interface
From the command line you can use gimli to convert values from one unit to another.
gimli --from=miles --to=ft
5280.000000
Values to convert can be passed through the files (use a dash for stdin).
echo "1.0" | gimli --from=cal --to=joule -
4.186800
When reading from a file, gimli tries to preserve the format of the input file,
cat values.csv
1.0, 2.0, 3.0
4.0, 5.0, 6.0
gimli --from=knot --to=m/s values.txt
0.514444, 1.028889, 1.543333
2.057778, 2.572222, 3.086667
Notice of Vendored Libraries
gimli.units
includes two third-party libraries, expat
and udunits
,
which are "vendored" as part of our codebase. This means that these
libraries are embedded directly within gimli.units
, rather than being
external dependencies.
Reasons for Vendoring
udunits
: A library for units of physical quantities, vendored to provide robust unit conversion and management, ensuring compatibility and consistency in unit operations.expat
: An XML parser library written in C, vendored to ensure consistent and reliable XML parsing across various platforms and environments without requiring separate installation of the library.expat
is a dependency ofudunits
.
Implications for Users
- No Additional Installations: Users do not need to install these libraries separately; they are fully integrated into our package.
- Package Size: The inclusion of these libraries increases the size of our package. We have taken care to ensure that this does not significantly impact the installation and usage experience.
- Compatibility: Vendoring these libraries helps us manage compatibility and reliability issues, as we use specific versions tested to work with our package.
Licensing
udunits
License: License Information for udunits- Our use of these vendored libraries complies with their respective licenses. Users of our package are also subject to these terms.
expat
License: License Information for expat
Updates and Security
- We actively monitor and incorporate updates, including security patches, for these vendored libraries. Should there be any significant updates or security concerns, we aim to address these in a timely manner.
Further Information
- For more information on
udunits
, refer to udunits' website. - For more details about
expat
, please visit expat's website.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for gimli.units-0.3.2-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 101a2c600cc04ab8344ff4e779b47315f25ede49bc569e6dddc2bd62974a8671 |
|
MD5 | e1da39ef563b3a6ef8c03737cfdac2b2 |
|
BLAKE2b-256 | 8e424999c0bf3af24b5f3a544ba7ee83f38c77e53714c597a868e6175768753a |
Hashes for gimli.units-0.3.2-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68ec7ff0af530264c17e7b2abdf981a73c9522e421bffbb06929c6b425987be2 |
|
MD5 | 4c52a86109be5fa79c6da7755eedbb4a |
|
BLAKE2b-256 | 1fec64a1cea5c494b93990dca267757bdd7a024a1eb890f69395f2db11afd05d |
Hashes for gimli.units-0.3.2-cp312-cp312-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 755a32a476a4364d0d8aa486bda275b3d7cd4aaa70a32aee8708c3598d3780e1 |
|
MD5 | e28b526d3e08ebf038706ebcafb1aa76 |
|
BLAKE2b-256 | 5fa65e78723a110648f149bb9645bef755580fcebeea7b95d09e47c6ec235bb0 |
Hashes for gimli.units-0.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 663ea6a4c5c80536cf3f7a26823b2512e99d4cbbdb6a3d910e4e5a965d3a5e45 |
|
MD5 | f0b132dc039bcdbecb31ab1f8074525a |
|
BLAKE2b-256 | 418e8f91e7af6e84a3baba829ff47fa41f7bd18d2adcefc847fe563eb025aba6 |
Hashes for gimli.units-0.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64be0714e3d3cfb04c01c992f7be6b6b54ab20058fd9645c86d72422c7a6280e |
|
MD5 | f5a268a84bbabdf7b82452c41e87204f |
|
BLAKE2b-256 | 3dc5f4e623e4ce3009831d6521309041c8be15fde220b9c956d8482d1517f1c5 |
Hashes for gimli.units-0.3.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc16798b682d90802105a8fce3fc206770616285c816d8dabc3707c9c3fa81e3 |
|
MD5 | 631553bf2dc449d839da798884ee4d39 |
|
BLAKE2b-256 | 1021c902c5f7aa731ac6ba909bd997493d109097638f65e216e902e323b7601e |
Hashes for gimli.units-0.3.2-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29dea343e3bf3a8da8854a1622ba08f359d3c9a9972a71c2712efec4ae505c65 |
|
MD5 | 17b67988a92b7975284f9afd93188a60 |
|
BLAKE2b-256 | 3e1fd4b8264b3adb0d458c9cb4c40f7909a5a3bd1424c50c0c6f49f274a97aa5 |
Hashes for gimli.units-0.3.2-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8357570db59f5807bff1850c8295e0dd3bb778a5c227ff5b58eb698fac259d0 |
|
MD5 | 06fd8e55e32c7dd2c31dfc8f83a1bd93 |
|
BLAKE2b-256 | 8666b7595fd7a4aa8ca66d77fe836dedc15fa18936d495432a8d9eb190cf63f1 |
Hashes for gimli.units-0.3.2-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c33297416cc06766e19a8ca3b62d16738814283301b2235421237ee0b84553f |
|
MD5 | d08888e6c038838f14c8ebff7a46cb91 |
|
BLAKE2b-256 | 494afeedaaa5d13ab7069341ec694cbb87ad5f3243ff64f8c668917b4a91a6d1 |
Hashes for gimli.units-0.3.2-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4bd74cb8c1f6ceab048dbea0d689c2781d0026b8cc7e842dec9e179fbc4ea28 |
|
MD5 | 643efe97a0761e5f999f6b4c58896b2a |
|
BLAKE2b-256 | c6fc111b1b716b616c27c62b42ed3293a70440005fa8f840eca9ab4e3e3d24df |
Hashes for gimli.units-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64fde3b92adb3a54ec0b71f08907ec235937c78acd666fa2fc1d2143310a85f8 |
|
MD5 | a7fdaf302875fe6e4b01837b493f1d2f |
|
BLAKE2b-256 | 29e2c27a123405c0d8dbbf57988c668c0d0a62c6b63ef0770031bbe685585003 |
Hashes for gimli.units-0.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50da62bc1ed8658e246166bae5ebe964cf3a8fbed283bb907e0038d983a88ba7 |
|
MD5 | 0a9512df97637259f60d29958103b379 |
|
BLAKE2b-256 | 7bd3a6bdf54f66baf87483dd2c375cfe003dfcddff5252091980796b659d371e |
Hashes for gimli.units-0.3.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e6ef9d4da68c62364794c2088b7503c4ef0b4dc54d35d69e88d30f6e2392c1e |
|
MD5 | cfe4dcd5334cc2913bdde27df6730e72 |
|
BLAKE2b-256 | fc0c33e7c18f0a1f772b2299d982da6081dbfb8a2e531aa091aacd2a4daedd4d |
Hashes for gimli.units-0.3.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a0454c9e6babcea45f72fcfc0a332474c93e267fa72e3222b02c4b08fad127e |
|
MD5 | 2caf09c516d6df70139b8161b2f6da86 |
|
BLAKE2b-256 | 7820b5688aeb6dad55a449447233d7c9b3c5e0af34901ca85ce0d5f3c5db9d0e |
Hashes for gimli.units-0.3.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4404afa000867a484642683590987d4ed5bb4718ea30be04c5cddf0a55e6f425 |
|
MD5 | a6a84dd27d2a06fd09af06258e5a5a65 |
|
BLAKE2b-256 | 1e98ac1b9987d9ece270195e18e1dc79a2250dcc62376c3d50c42da06b4f268e |
Hashes for gimli.units-0.3.2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29a3f37b2c6359888cca61fca7da387fb12d1b16c4b86fbbeab4b0dedcff86f6 |
|
MD5 | 7d0382d8fca69fdbfe2e44c18f1ea1c4 |
|
BLAKE2b-256 | 19dfe1817957e64f793bffdfdaa514087d71986dc381ec3390090539157d2ddc |
Hashes for gimli.units-0.3.2-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b24ec215c07c8e8bf726c0b368622f5eed7b1c62b72774b5e6fdd0e650fea08e |
|
MD5 | ddfd30af585c96c7d261cefc3953be9c |
|
BLAKE2b-256 | 0dbda878f8094f24ce5a6a1f8ce06a73ac5be8ac124064d346316df138747313 |
Hashes for gimli.units-0.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76c5b13c90875d8646e87167fc6e7fb1fa61ee98f7ecd023fbc22614cd6ee515 |
|
MD5 | 36a8344c17c4229628ed792f320b8e6d |
|
BLAKE2b-256 | 825f136913bf7da08a3f42db4309541e6792f1106565fce13337d351dd224230 |
Hashes for gimli.units-0.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb5a3111a164022a6c9b074b4c3a03f2f4878e7f65b907f5ff14cf95f3755dbd |
|
MD5 | 2da324405ee4c9ed05e916dcec685e68 |
|
BLAKE2b-256 | e493c4443ef49b82a93e6c3d4a3adce5e825f0ad2e1ebbfee6fe5d1e25ef8279 |
Hashes for gimli.units-0.3.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e97467e278e5b54207b9790fe37b91ea88a23417905499655e5c16242ae4de68 |
|
MD5 | 7526406573a2faafd5aa63c5ab527304 |
|
BLAKE2b-256 | 46722ce68963f9e3b560a08bafa9481b30b2c73fa4e2d67923d2f147fc8c97a5 |
Hashes for gimli.units-0.3.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d43b8d02645a37a8f529abe1c0e8f29854537c57e2cb251c7dcbf6c6dfc3d8fc |
|
MD5 | ec0d1847d90c6e66e09729ca7a409537 |
|
BLAKE2b-256 | 1c912b9e43a29b3b661caba959e31fd41aec40e3f43c6f1cb21e5c30acbfec80 |