🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

bumbag

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bumbag

A package for Python utility functions.

5.2.1
PyPI
Maintainers
1

The BumBag logo.

pypi docs ci status coverage license

About

BumBag is a collection of Python utility functions:

Installation

bumbag is available on PyPI for Python 3.8+:

pip install bumbag

Examples

Measure elapsed wall-clock time and compute total elapsed time with stopwatch:

>>> import bumbag
>>> import time
>>> with bumbag.stopwatch(1) as sw1:
...     time.sleep(1)
...
2023-01-01 12:00:00 -> 2023-01-01 12:00:01 = 1.00124s - 1
>>> with bumbag.stopwatch(2) as sw2:
...     time.sleep(1)
...
2023-01-01 12:01:00 -> 2023-01-01 12:01:01 = 1.00168s - 2
>>> sw1 + sw2
2.00291s - total elapsed time

Easily flatten an irregular list:

>>> import bumbag
>>> irregular_list = [
...     ["one", 2],
...     3,
...     [(4, "five")],
...     [[["six"]]],
...     "seven",
...     [],
... ]
>>> list(bumbag.flatten(irregular_list, 8, [9, ("ten",)]))
['one', 2, 3, 4, 'five', 'six', 'seven', 8, 9, 'ten']

Use highlight_string_differences to see differences between two strings easily:

>>> import bumbag
>>> print(bumbag.highlight_string_differences("hello", "hall"))
hello
 |  |
hall

Quickly compare two Python sets with two_set_summary:

>>> import bumbag
>>> x = {"a", "c", "b", "g", "h"}
>>> y = {"c", "d", "e", "f", "g"}
>>> summary = bumbag.two_set_summary(x, y)
>>> print(summary["report"])
    x (n=5): {'a', 'b', 'c', ...}
    y (n=5): {'c', 'd', 'e', ...}
x | y (n=8): {'a', 'b', 'c', ...}
x & y (n=2): {'c', 'g'}
x - y (n=3): {'a', 'b', 'h'}
y - x (n=3): {'d', 'e', 'f'}
x ^ y (n=6): {'a', 'b', 'd', ...}
jaccard = 0.25
overlap = 0.4
dice = 0.4
disjoint?: False
x == y: False
x <= y: False
x <  y: False
y <= x: False
y <  x: False

Contributing to BumBag

Your contribution is greatly appreciated! See the following links to help you get started:

License

bumbag was created by the BumBag Developers. It is licensed under the terms of the BSD 3-Clause license.

Keywords

utility functions

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts