Skip to main content

boozelib

VERSION: 0.7.0

A Python module containing a couple of tools to calculate the blood alcohol content of people.

It's at home at GitHub: https://github.com/brutus/boozelib/.

As a side note: I created this library mainly to have a very simple module to try different Python testing and packaging best practice. This is in no way a serious medical approach and also accepts a rather big level of abstraction. Depending on your use case, this might be okay; but I would not deem it fit for serious health and / or legal stuff 😉 🍻

Install

You can install it from PyPi, it is known as boozelib and has no dependencies:

pip install --user boozelib

Usage

The two main functions are:

  • get_blood_alcohol_content(age, weight, height, sex, volume, percent)

    Return the blood alcohol contents raise (per mill) for a person after a drink.

    Given a drink containing volume (ml) of percent (vol/vol) alcohol, for a person with age (years), weight (kg) and height (cm) — using a formular for "female body types" if sex is true.

  • get_blood_alcohol_degradation(age, weight, height, sex, minutes=1, degradation=None)

    Return the alcohol degradation (per mill) for a person over minutes.

    For a person with age (years), weight (kg) and height (cm), using the formular for "female body types" if sex is true, over the given minutes. If degradation is not set, ALCOHOL_DEGRADATION is used as default.

This uses some constants and one variable you might want to review:

  • ALCOHOL_DEGRADATION: the default value for alcohol degradation; meaning the amount of alcohol (in gram) your body is degrading per minute, per kilogram body weight. This is usually a value between 0.0017 and 0.0025 (about 0.1—0.2 per thousand per hour).

Examples

Return the blood alcohol contents raise (per mill) for a person after a drink:

from boozelib import get_blood_alcohol_content

get_blood_alcohol_content(
	age=32, weight=48, height=162, sex=True, volume=500, percent=4.9
)
# ⇒ 0.5480779730398769

And to calculate alcohol degradation:

from boozelib import get_blood_alcohol_degradation

get_blood_alcohol_degradation(
	age=32, weight=48, height=162, sex=True, minutes=60
)
# ⇒ 0.20133476560648536

You can change the default for alcohol degradation globally via setting boozelib.ALCOHOL_DEGRADATION. Or change the value for alcohol degradation per call:

get_blood_alcohol_degradation(
	age=32, weight=48, height=162, sex=True, minutes=60, degradation=0.002
)
# ⇒ 0.16106781248518828

Documentation

See the source or the documentation for more information and the used formulas.

Development Setup

Poetry is used to manage a virtual environment for the development setup.

A Makefile is provided, that collects some common tasks. You have to run the following once, to setup your environment:

make setup

Testing

nox is used as a test runner (with ward as the framework). If you have the development environment activated, you can just run:

make tests

If something fails, please get in touch.

Thanks and Contributions

  • Big hugs to Mathilda for hanging around and helping me figuring out all that math and biology stuff.

If you find bugs, issues or anything else, please use the issue tracker on GitHub. Issues and PRs are welcome ❤️

Release files for boozelib 0.7.0

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

Source distribution (sdist)

Source distribution for boozelib 0.7.0
File Size Uploaded
boozelib-0.7.0.tar.gz 17.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for boozelib 0.7.0
File Interpreter ABI Platform
boozelib-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.9 kB

Release files / boozelib-0.7.0.tar.gz

Download URL boozelib-0.7.0.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ec07a54fef6d12e1c56de6891d8e5278b8731adfd46449c724c2fa53d870916a
BLAKE2b-256 checksum
How to use checksums
ac145d9989d6df4f00b0ccd54cd469c863288324c9267ece0874e45292ecfeaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.7.9 Linux/5.8.18-100.fc31.x86_64

Release files / boozelib-0.7.0-py3-none-any.whl

Download URL boozelib-0.7.0-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3ff9bfe598e5d07aa49ceccbb0c451b75c4d2927c49dff5afdc3baffb4fa5ae
BLAKE2b-256 checksum
How to use checksums
34f7ec42f50ec4e0c5afab314abb901fd1402cdd9f18000c47955659c335cdcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.7.9 Linux/5.8.18-100.fc31.x86_64

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4

1 release file

0.3

1 release file

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