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

Uploaded Python 3

File details

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

File metadata

  • Download URL: hb9imsutils-0.2.14.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.14.tar.gz
Algorithm Hash digest
SHA256 a0e54524d97a0f42613363cb6f975acba93c7c26602439c84c3b802f5450c6fa
MD5 9bf9ceaa9a757ed4fa6b8c6a27490ae2
BLAKE2b-256 9394e9eab500dc12acb605269650b796281a968075b784d5f5e45a053f0dd632

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: hb9imsutils-0.2.14-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.14-py3-none-any.whl
Algorithm Hash digest
SHA256 804f9e76cf54ee9a5cfb98a2ce8590015856592460134b4a0a99d141cac18397
MD5 51ab08ecf26809485a6e13134e53aeed
BLAKE2b-256 198fc5592705e37fbdc9c05044551e126e92f1040093c026437c1f358d6db06a

See more details on using hashes here.

Provenance

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