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).

Open issue: inoperable in classes, use @timed

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.12.tar.gz (11.6 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.12-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hb9imsutils-0.2.12.tar.gz
  • Upload date:
  • Size: 11.6 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.12.tar.gz
Algorithm Hash digest
SHA256 a8e7425bc04e1c51de48d262a81d22d1e4e1e3fc0932cdab0d0cbbc7e9e33c7d
MD5 63d902579f7291a006bb546e108efd2d
BLAKE2b-256 45987942461359b33cd4d7aefaacea7b15eef4e2c04e44371b90450d814d6015

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: hb9imsutils-0.2.12-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.12-py3-none-any.whl
Algorithm Hash digest
SHA256 cdf4348812fabf4655f11820c37cb7f9efc6f8cb2acfdb05a5d99ec246a660b7
MD5 b4cf194fa2df2e5b5d88c0cd24f0f4e3
BLAKE2b-256 bd9358a8448d6961f6ab1e36d01b1e4316ccd7088dacbc1b727a6df535dc427c

See more details on using hashes here.

Provenance

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