Skip to main content
Version_status Documentation license

What is bookkeep?

bookkeep is a python package for keeping track of units of measure and measurment bounds. The package mainly features the SmartBook, a dictionary subclass that incorporates pint Quantity objects for managing units of measure.

Installation

Get the latest version of bookkeep from https://pypi.python.org/pypi/bookkeep/

If you have an installation of Python with pip, simple install it with:

$ pip install bookkeep

To get the git version, run:

$ git clone git://github.com/yoelcortes/bookkeep

Documentation

bookkeep’s documentation is available on the web:

http://bookkeep.readthedocs.io/

Getting started

SmartBook objects are dictionaries that provide an easy way to keep track of units of measure and enforce bounds.

Create a SmartBook object with units, bounds, a source description, and arguments to initialize the dictionary:

>>> sb = SmartBook(units={'T': 'K', 'Duty': 'kJ/hr'},
...                bounds={'T': (0, 1000)},
...                source='Operating conditions',
...                T=350)
>>> sb
{'T': 350 (K)}

The units attribute becomes a UnitManager object with a reference to all dictionaries (clients) it controls. These include the SmartBook and its bounds.

>>> sb.units
UnitManager:
{'T': 'degC',
 'Duty': 'kJ/hr'}
>>> sb.units.clients
[{'T': 350 (K)}, {'T': (0, 1000)}]

Change units:

>>> sb.units['T'] = 'degC'
>>> sb
{'T': 76.85 (degC)}
>>> sb.bounds
{'T': array([ -273.15, 726.85])}

Add items:

>>> sb['P'] = 101325
>>> sb
{'T': 76.85 (degC),
 'P': 101325}

Add units:

>>> sb.units['P'] = 'Pa'
>>> sb
{'T': 76.85 (degC),
 'P': 101325 (Pa)}

A BookkeepWarning is issued when a value is set out of bounds:

>>> sb['T'] = -300
__main__:1: BookkeepWarning: @Operating conditions: T (-300 degC) is out of bounds (-273.15 to 726.85 degC).

Nested SmartBook objects are easy to read, and can be made using the same units and bounds.

Create new SmartBook objects:

>>> sb1 = SmartBook(sb.units, sb.bounds,
...                 T=25, P=500)
>>> sb2 = SmartBook(sb.units, sb.bounds,
...                 T=50, Duty=50)
>>> sb1
{'T': 25 (degC),
 'P': 500 (Pa)}
>>> sb2
{'T': 50 (degC),
 'Duty': 50 (kJ/hr)})

Create nested SmartBook:

>>> nsb = SmartBook(sb1=sb1, sb2=sb2)
{'sb1':
    {'T': 25 (degC),
     'P': 500 (Pa)},
 'sb2':
    {'T': 50 (degC),
     'Duty': 50 (kg/hr)}}

Pint Quantity objects are also compatible, so long as the corresponding Quantity class is set as the Quantity attribute.

Set a Quantity object:

>>> Q_ = SmartBook.Quantity
>>> sb1.bounds['T'] = Q_((0, 1000), 'K')
>>> sb1['T'] = Q_(100, 'K')
>>> sb1
{'T': -173.15 degC,
 'P': 500 (Pa)}

Setting a Quantity object out of bounds will issue a warning:

>>> sb1['T'] = Q_(-1, 'K')
 __main__:1: BookkeepWarning: T (-274.15 degC) is out of bounds (-273.15 to 726.85 degC).

Trying to set a Quantity object with wrong dimensions will raise an error:

>>> Q_ = SmartBook.Quantity
>>> sb1['T'] = Q_(100, 'meter')
DimensionalityError: Cannot convert from 'meter' ([length]) to 'degC' ([temperature])

Latest source code

The latest development version of bookeep’s sources can be obtained at:

https://github.com/yoelcortes/bookkeep

Bug reports

To report bugs, please use the bookkeep’s Bug Tracker at:

https://github.com/yoelcortes/bookkeep

License information

See LICENSE.txt for information on the terms & conditions for usage of this software, and a DISCLAIMER OF ALL WARRANTIES.

Although not required by the bookkeep license, if it is convenient for you, please cite bookkeep if used in your work. Please also consider contributing any changes you make back, and benefit the community.

Citation

To cite bookkeep in publications use:

Yoel Cortes-Pena (2018). bookkeep: An easy way to track quantities
https://github.com/yoelcortes/bookkeep

Metadata

Release files for bookkeep 0.5.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bookkeep 0.5.7
File Size Uploaded
bookkeep-0.5.7.tar.gz 8.1 kB Details

Release files / bookkeep-0.5.7.tar.gz

Download URL bookkeep-0.5.7.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dfc4f6cc5ed51abd58adad14294a67b544dbdbfa8a6030af3019fe8154030820
BLAKE2b-256 checksum
How to use checksums
1c4ee2fa00ae7b105ac23df2294ee74513f912007ce05a93cb83ce819fcc6323
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release history Release notifications | RSS feed

This release

0.5.7 This release

1 release file

0.5.6

1 release file

0.5.5

1 release file

0.5.4

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5

1 release file

0.4.9

1 release file

0.4.8

1 release file

0.4.7

1 release file

0.4.6

1 release file

0.4.5

1 release file

0.4.4

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.9

1 release file

0.3.8

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page