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.13.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.13-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hb9imsutils-0.2.13.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.13.tar.gz
Algorithm Hash digest
SHA256 a1a50d34ad63838453bc124a49a171c982cbf681d7637c6b8ffd9f57f7a8a94c
MD5 e28ea987fd0d648e42966bf530e3b591
BLAKE2b-256 e972c4ae94e43e9b0885adbf9f61d3c33db10f6b07d47098949a43938501be6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hb9imsutils-0.2.13.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.13-py3-none-any.whl.

File metadata

  • Download URL: hb9imsutils-0.2.13-py3-none-any.whl
  • Upload date:
  • Size: 10.5 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.13-py3-none-any.whl
Algorithm Hash digest
SHA256 6c1aa09bb05b28bc77bc2c4d11f09a4ac8125f7ef008b9d8b92942b5aa17d6e3
MD5 e99775552a0f7dc2704b7bdddd5e9be3
BLAKE2b-256 2ecd7001bd921565f4b291d0942e1b7cc12ebd4cb1931aa8c65cb7752e11cce4

See more details on using hashes here.

Provenance

The following attestation bundles were made for hb9imsutils-0.2.13-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