Skip to main content

A collection of handwritten utilities

Project description

hb9imsutils

This python package is a small collection of tools accumulated over some time.

currently WIP... (when I need to update it; I'm not that active :C)

Most important docs:

Progress bars

I mostly recommend making a wrapped iterator using the ProgressBar class, even though you don't need it to be an iterator.

The ETA is calculated with the assumption that your code takes the about same time for each iteration

Inspired by TQDM (but in any way or form worse)

How to use

You initiate a progress bar with:

ProgressBar(an iterable object or None, expected iterations, redraw interval (in seconds, default 0.033))

Then you can either call the ProgressBar or iterate over it.

# recommended:
for i in ProgressBar(something_that_yields, how_often_you_expect_it_to_yield):
	DoSomethingWithYourDataThatTakesSomeTime(i)

# possible, not recommended:
pb = ProgressBar(None, how_often_you_expect_to_call_it)
for i in something_you_know_pretty_well_how_long_it_should_take:
	DoSomethingWithYourDataThatTakesSomeTime(i)

Unitprint

Ok, I'll admit. unitprint is the main feature of my library but wasn't even my idea. Props to this go to the IT admin where I interned and implemented his idea. I improved the concept a little (like f.ex. using a dict with the $log_{1000}$ / $log_{1024}$ values instead of elif matching them to fixed values).

Originally, the only unitprint function was fixed size; if you still want it padded correctly, add the _block suffix. (so unitprint_block unitprint2_block)(note that they share their syntax with the non-padded version).

unitprint2 is base 2, so it formats $2^{18}$ bytes 256.000 KiB instead of 262.144 kB.

The base 10 version of unitprint, you can specify a power, so $10^{-6}m^2$ can be printed as 1.000 mm^2. For that, use the optional power parameter. (Please specify the power=n parameter directly. It makes it WAY more readable)

In order to avoid mibibytes (miB), the unitprint2 function ceils the value to be printed. If you need a decimal with bytes please mail me why. I am genuinely interested on why one would need fractional bytes/bits! (No, bits do not count. I'd set the unit as a bit.)

How to use

It is as simple as unitprint(float_to_format, symbol_if_any, power_if_any) or unitprint2(positive_float_to_format, symbol_if_any, power_if_any)

PTimer

Yes, that one is inspired by IPythons %%timeit. I thought it was cool and wanted to use it in scripts, not just the console. It is an extension of the @timed decorator (but I upgraded it to a class because some implementation was easier).

FUN FACT: If you want a short summary (or long idc) every n samples xor every t seconds, you can call the decorator with parameters print_rate=n xor redraw_interval=t

How to use

@PTimer
def some_func(whatever):
	something = magic(whatever)
	return wizardry * np.sum(something)

Namespaces

Just a container for data. Rarely useful. A dozen lines of uncommented code. Great fun.

n = Namespace(a=1)
n.b = "None"
n.c += len(n.b) + n.a

print(n)

How to use

Create it. Assign to it. Read from it. Delete from it. wow

You can even put namespaces (while True: into namespaces)

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

hb9imsutils-0.2.15.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hb9imsutils-0.2.15-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file hb9imsutils-0.2.15.tar.gz.

File metadata

  • Download URL: hb9imsutils-0.2.15.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hb9imsutils-0.2.15.tar.gz
Algorithm Hash digest
SHA256 4a70e8a16ce5dfaa830ef1185829c271e38e6dbe7ecd2a4af26e14e9248e46e0
MD5 03d433b56539bacb2e96da094ca5f43a
BLAKE2b-256 62bef4d6551f902d414455c4c3742dde6b42ef0af990b73e22b2a7fab340f87d

See more details on using hashes here.

Provenance

The following attestation bundles were made for hb9imsutils-0.2.15.tar.gz:

Publisher: workflow.yml on HB9IMS/hb9imsutils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hb9imsutils-0.2.15-py3-none-any.whl.

File metadata

  • Download URL: hb9imsutils-0.2.15-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hb9imsutils-0.2.15-py3-none-any.whl
Algorithm Hash digest
SHA256 e803e3033c2e319c192fe5a82be2148207f7aa8fa5c5c05f19b2a239e53d8370
MD5 b793a64a9f55c5380a6a2b35eeb41de9
BLAKE2b-256 2e6bd31ab7b7deee9be2b9510274130f6091f882fa8cf1bded6d04168b609623

See more details on using hashes here.

Provenance

The following attestation bundles were made for hb9imsutils-0.2.15-py3-none-any.whl:

Publisher: workflow.yml on HB9IMS/hb9imsutils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page