An object-oriented Python interface to udunits
Project description
gimli.units
An object-oriented Python interface to udunits2 built with cython.
Requirements
udunits2 is the unit conversion C library that gimli wraps using cython. The easiest way to install udunits2 is through Anaconda (see the Install section), or yum (as udunits2-devel on ubuntu-based Linux). It can, however, also be compiled and installed from source. You can get the source code either as a .tar.gz or from GitHub.
All other requirements are available using either pip or conda. To see a full listing of the requirements, have a look at the project's requirements.in file.
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 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.
To get a specific unit from the system, do so by passing a unit string to the Units class. For example,
>>> units.Unit("m")
Unit('meter')
>>> units.Unit("m/s")
Unit('meter-second^-1')
>>> units.Unit("kg m-3")
Unit('meter^-3-kilogram')
>>> units.Unit("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.Unit("lb")
>>> kgs = units.Unit("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.Unit("ft / s")
>>> m_per_s = units.Unit("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.1-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d76c293c4498b335e754196d01985c25bb6e465d3b1b540fe9a90dcdfc5e960 |
|
MD5 | 5b82cedb5db42f337e246415ccd25316 |
|
BLAKE2b-256 | e8f57dac11c504c766adf86532cae8d3565b533bbc982a8655a0b57c9862a325 |
Hashes for gimli.units-0.3.1-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79d1ab1788df386420cc2ab9ec13306977223f16c42cef73341b88e2073e414f |
|
MD5 | de99b92de30585b1b886f67f7e7ff767 |
|
BLAKE2b-256 | 746b1fddeb396ee6b91f35207d4059ba12255699bd7468dd011a902443e49efb |
Hashes for gimli.units-0.3.1-cp312-cp312-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e42c5fe07963283dafe73fdb1f90d5813331151fbf10d86f8bf8377bdc1d262 |
|
MD5 | 86fe78aabd67d3e635892c3fa497d2bc |
|
BLAKE2b-256 | d2823da358ca8071dd37101b7c2c54b803e71ab676c07ae42c7a64e66b8bd65e |
Hashes for gimli.units-0.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07c71a9b34b1ab43011e700fe142f8b6dd536647bfabb79f42e33d2801352620 |
|
MD5 | 4365f90ebe13e2e69bfc90c99a4e8d4a |
|
BLAKE2b-256 | 36827417f290e0a22adac069632552868f97e7bfd8ff92d5261f809ab1c9e58b |
Hashes for gimli.units-0.3.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1a7792afeda90bafeec8d0b9b5542237361a7489c909a9184ef09fb817d4192 |
|
MD5 | 8c1dd577b18093c51729739425bce27d |
|
BLAKE2b-256 | 38ce9be6e8ad8e56925b3f40a87c7ae1683c4bada5717d78592111bd4bf922eb |
Hashes for gimli.units-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81971c6122f6f5b981fc597aa2c0d79a9a80494c5701936b4232b08b9c9bc123 |
|
MD5 | 15634b5f6ff224fbf211f94ee7764fed |
|
BLAKE2b-256 | 34e82c1763bbae6532735b25c44ac3e357bcdf789e2fa08fc3f23ed6a0f9ea75 |
Hashes for gimli.units-0.3.1-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3966bd80ce354c683a46ad9e04a1f185c714d9ba64cc0f4e42f6f68bccbcb79f |
|
MD5 | 3bd9bbb875c8d43b5416a7d42b1556fb |
|
BLAKE2b-256 | 73b63b01e964c142075ddebfad81da92f7641510b051ab5dee4ac747eabc9d0a |
Hashes for gimli.units-0.3.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5cd3ddd408a23d8859cafc95827e00179b08bb02ccf29b028a26474ff374cd8 |
|
MD5 | 3caac79f0ef2d70170d0e5401af5c234 |
|
BLAKE2b-256 | 8b3206986a66c8e17d74e95832e1c4c3822769957bbceb817825cad272c7f89f |
Hashes for gimli.units-0.3.1-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa7f7f219a5c02e8544a311a46f50f49912a9ca11a8b97c5a58edb07a54acf8b |
|
MD5 | fab3e5f6821d161a716c8577cb228a57 |
|
BLAKE2b-256 | e8be6753393526b7b3234a073a468887d0167d64982185427c9fb317079caee5 |
Hashes for gimli.units-0.3.1-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f341fffa5c57e1765359dadcb65acacdcf416284de112eef0ddb85002b6e5ee0 |
|
MD5 | aea0e8b2c7789798e916a6379b205adb |
|
BLAKE2b-256 | 7c4a6d1db5afb8ea1ea062e074d0e2149d389fb113c4c2e417780b96bf591928 |
Hashes for gimli.units-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2e8898d6776f70287730ce38637153901664d4d27fb85ae90af2def3e46d966 |
|
MD5 | d4ca938080729984f0faf0e551a88af8 |
|
BLAKE2b-256 | b0c13d67642545b21d1f7740876a1a2f0d1d6fd136e7e6a8a07e72e331940058 |
Hashes for gimli.units-0.3.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8465449c8f5eaaab087d29fdae855d97217f1b24b8a338c9bbd27c51959d2f7b |
|
MD5 | 50e958fa426fed85298f9df9fd999ae1 |
|
BLAKE2b-256 | 95a23125fe2b6a43302b5b4580e5b898c41d8b1813c27ceb9bf66a5185f535a0 |
Hashes for gimli.units-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d876598a1957efcf3bdd0483c0fbc55d60d8136fd64f2be9d45ff3a2a0a0a321 |
|
MD5 | 931397a2880c46ccdfe79f57a682ffea |
|
BLAKE2b-256 | 345847797ddce4208df7483678e4574de78e1dfa78a0fc9b07d17597f283b1d5 |
Hashes for gimli.units-0.3.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7061e82334bc748ee756d1181810a93b17f1a0345a9af2e993f8643abf2451a4 |
|
MD5 | fc31cfa67d7a8c9e00d9fc8cdd5c3655 |
|
BLAKE2b-256 | fd30765d65955aa6cb20125b6fbd8774c89a0268b59ef9db93d4b519f29cce36 |
Hashes for gimli.units-0.3.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c41337ba5d672fbc53711a3797459168a2e0f0df29cd265d27b01ac853b1839 |
|
MD5 | 7bc38290d4697d13ee11161469731312 |
|
BLAKE2b-256 | 1442bd48b2af302535b79336b085db66a2260a40109920abdd434852c7bc94c3 |
Hashes for gimli.units-0.3.1-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c92c02f09d3c82f58c21595acfcb33ac4f04522c437d7d7cf276f525ac05cdcc |
|
MD5 | e6ad6d9836fc2fbf52973e23ef3d6909 |
|
BLAKE2b-256 | 3b479a203cf90143fad14236e6fa44fc494679668eaa0280df9ce27f6b3f383e |
Hashes for gimli.units-0.3.1-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b1edaf22c2cc06a836dd68b19322c04cb0e459bccfffeb8c59aaf9c18f0ccb7 |
|
MD5 | 09586dc7aafe3c678e1182ad31a3bac2 |
|
BLAKE2b-256 | 829a37d288728e76942f9bc5d10d0765f9e11f23e7dfec6eadfe9b626a11f81e |
Hashes for gimli.units-0.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aca6f70688566960380e8a4a8a7c9544f3781f563e9c1ba66940cebecc4f75d7 |
|
MD5 | 698232a140bf3c67889105d3fb036cc4 |
|
BLAKE2b-256 | 20dd05f945d87246e801ba9d091d77a045824b63277b9056918abe9aef954ab3 |
Hashes for gimli.units-0.3.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38bbf3a0900f814daa109a71d42401e2d748727d4e7ade14f3619edf15eb07b5 |
|
MD5 | b5442c6ec20668764eb0db56ae1154ed |
|
BLAKE2b-256 | 65ce6beafc96aaac8a7841de4b54a8cba71edfbd63a82fafb6a98ae85f54689c |
Hashes for gimli.units-0.3.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6e36b719e7c76cc745b8f364f5d5f30f1ab30d2c25eeb0138c23a365f1ed7de |
|
MD5 | d979f4ad95d580d05d54e0ca464a1bfa |
|
BLAKE2b-256 | 107576fa8e5aaf4cd5a6eef46be42987be9fb075ffe4c78afbf24756a8e7f2b4 |
Hashes for gimli.units-0.3.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 869cf8652f97fa5215026349dbf84e52c3dc8ff12e5e2e3eb1c5cf4e90ffa07d |
|
MD5 | 72e38f3972ab9713a4fe0768d309477a |
|
BLAKE2b-256 | e72577e04150616373cf5a6237589d476a51498eb499fa57f9912dcadd82fc52 |