Skip to main content

a few somewhat useful objects and functions

Project description

EpicStuff

A few somewhat useful (Epic) python objects/functions (Stuff)

Installation

pip install epicstuff

Dict

Lets you access a dictionary's keys as attributes

JDict version

Points to a target instead of converting it into a (new) Dict object. Useful for when your "target" is say, a CommentedMap and you don't want to loose the comments.

  • Example:
from epicstuff import Dict

d = Dict({})

d.x = 1

BoxDict version

Simpler (less features) than Box (and faster i think) but with more features (recursive conversion and creation on access) than jdict (and without some of the "extra" stuff)

  • Example:
from epicstuff import Dict

d = Dict({"a": 1, "b": {"c": 2, "d": 3}}, _convert=None)

print(d.b.c)  # 2

Rich Trace

Easily install terminal-wide rich.traceback and use helpers to ensure pretty tracebacks with async functions.

  • Example:
from epicstuff import run_install_trace
  • or:
from epicstuff import rich_trace

@rich_trace
async def some_func():
	raise Exception
some_func()
  • or:
@rich_trace(_return=0)
async def some_func():
	raise Exception
some_func()
  • or:
with rich_trace():
	raise Exception

Bar

Makes using nested progress bars from rich.progress easier

  • Example:

basically replaces

from rich.progress import Progress

with Progress() as progress:
	task = progress.add_task("task", total=100)
	for i in range(100):
		sub_task = progress.add_task("subtask", total=100)
		for j in range(100):
			time.sleep(0.01)  # some task

			progress.update(sub_task, advance=1)

		progress.remove_task(sub_task)
		progress.update(task, advance=1)

with

from epicstuff import Bar

with Bar() as bar:
	for i in bar(range(100)):
		for j in bar(range(100), transient=True):
			time.sleep(0.01)  # some task

with minor extra features (fancier default bar)

Timer

a simple timer to time execution of code a code segment

  • Example:
from epicstuff import timer

with timer():
	pass  # some code

# outputs: Time elapsed: 0.0 seconds
# message can be changed by passing a string with {} to timer

s

An autoformatting string. Removes extra indent and leading/trailing newlines.

  • Example:
from epicstuff import s

string = s('''
	line 1
		line 2
			line 3
''') + 'line 4'

print(s)
# line 1
# 	line 2
# 		line 3
# line 4

Permissify

make function ignore extra arguments instead of raising an error.

  • Example:
from epicstuff import perm

def tmp(a, b=2): ...

perm(tmp)(1, 2, b=3, c=5)  # this will run without raising TypeError

Stuff

extra functions:

  • open: overwriting open with Path.open and encoding='utf8' (also accepts str)
  • wrap: just a renamed functools.partial
  • rmap: map but recursive for lists and dicts
    • takes list or dict and 2 functions, will apply function 1 to all keys and function 2 to all values
  • Tee: Text stream that writes to multiple underlying streams. (Example: redirect stdout to terminal and a file)
  • Pointer: an object you can kinda use like a pointer. (Example number = Pointer(5), number._t = 6)

TODO:

  • when doing bar in bar with the second bar being transient, make so that the dots continue from where the previous bar left off
  • implement auto transient for bar in bar
  • add and implement simple=False for .Bar.track()

Stuff:

  • Note to self:
    • "self install" using pip install -U -e .
    • upload by running python -m build then twine upload --skip-existing dist/*

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

epicstuff-1.0.1.tar.gz (30.6 kB view details)

Uploaded Source

Built Distribution

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

epicstuff-1.0.1-py3-none-any.whl (33.7 kB view details)

Uploaded Python 3

File details

Details for the file epicstuff-1.0.1.tar.gz.

File metadata

  • Download URL: epicstuff-1.0.1.tar.gz
  • Upload date:
  • Size: 30.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for epicstuff-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6dd2c7081e0812ee42139cea4a1c001a9a9eaf2e9c512f9930594a47afebd34a
MD5 c2ee30e64e666ce013ecd58c2f0cc7c7
BLAKE2b-256 30cd5011b3e03e356fcaed9f9500d6a98176331b3455cb9fd57baeb753cf75f7

See more details on using hashes here.

File details

Details for the file epicstuff-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: epicstuff-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 33.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for epicstuff-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46a06e1b7688e80cd22f499ac497d3fa2aef1c42ae667d4c5d37f6596468d075
MD5 8add25ca2528d6587c1fa95ce8b63927
BLAKE2b-256 d763d98cc71c4dce4400ce242a7aed488f1b05a2581a303bd9733a92b634fe5e

See more details on using hashes here.

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