Skip to main content

trickkiste

trickkiste is a collection of convenience functionality I use quite often that are too small to give them their own project on the one side but prone to changes due to changes to the Python ecosystem to just copy&paste them and leave them as they are.

So they are here now, enjoy.

Beware: most of this is not part of any standard library for a reason. That reason might be there are better built in solutions which are harder (but more flexible) to use or I just didn't find them back then. In most cases you're advised to build them your own (to avoid dependencies and bugs).

Content

Here is an overview of what's in here, see the docstings for a better description (some even have a doctest!):

misc

  • throw(BaseException): functional raise for closed expressions

  • md5from(Path): convenient wrapper returning an MD5 file checksum

  • cwd(Path): path changing context manager

  • process_output(cmd): short form for 'run a command and return it's output as one string'

  • asyncify: decorator turning a sync method or function into an async one

  • async_chain: like chain but async

  • async_filter: like filter but async

  • date_str(timestamp, [datefmt]): convenience wrapper for strftime

  • def date_from(timestamp: float | str): : convenience wrapper for strptime

  • dur_str(seconds, [fixed]): short human readable representation of a duration

  • age_str(now, age, [fixed]): like dur_str but with an age context

  • parse_age(string: str): inverse of age_str

  • smart_split(string: str, delimiter: str = ","): like split but parenthesis aware!

  • multi_replace(string: str, *substitutions: tuple[str, str]): short form for chainging replace

  • compact_dict(mapping, [maxlen], [delim]): create a short one-string map

  • def split_params(string: str): inverse of compact_dict

logging

  • apply_common_logging_cli_args(ArgumentParser): enrich a given parser to recognize default stuff like --verbose, etc.
  • setup_logging: sets up a rich enhanced logger with useful stuff like call stack and posix thread id
  • logging filters: internally used by setup_logging but can be re-used of course
    • markup_escape_filter: escapes (accidental) markup elements in the message
    • thread_id_filter: adds the (posix) thread id
    • callstack_filter: adds a short call stack
    • logger_name_filter: adds the logger name (rich edition)
    • logger_funcname_filter: adds the function name (rich edition)
    • logger_levelname_filter: adds the level name (rich edition)

Textual stuff / TuiBaseApp

  • TuiBaseApp: like textual.App but with convenience stuff mostly regarding logging
  • RichLogHandler: a logging handler for a textual widget
  • LockingRichLog: locks your log view scroll position until you scroll to the bottom
  • HeatBar: a colorful heat bar widget for things like CPU monitoring

Textual stuff / tui_widgets

  • Splitter: a one-cell bar, dragging it resizes the widget next to it
  • collapsible_log: a log in a Collapsible with a FoldingSplitter above, shown only while unfolded
  • StatusBar: a bottom line with the number of async tasks (all of them, grouped, on hover) and a tool's name and version
  • copy_text, desktop_clipboard: text to the terminal's (OSC 52) and the desktop's clipboard (wl-copy, xclip or xsel)
  • AlertingRichLogHandler, with_alerts: warnings and errors in a log pane on a red-ish background, reported to the app as LogAlert
  • clean_line: a foreign process' output line without control codes
  • SPINNER, scanner: a spinner and a K.I.T.T. light over a label
  • ConfirmScreen: a yes/no dialog
  • tool_frame, FramedApp: a tool's frame - a Header with the clock and a feedback button at its right end, the StatusBar; the app places the button, opens FeedbackScreen with its FEEDBACK_WAYS and copies a right-clicked link (HEADER_CSS, FEEDBACK_CSS); Ctrl-Z suspends it, also under uv run / uvx (the whole process group gets SIGSTOP after the terminal is restored, fg resumes it)
  • package_version: v<version> when installed, else local checkout

std_suppress

std_suppress (with it's own shell entry point suppress) can be prefixed to a command and acts like adding >/dev/null 2>&1 but will print the output if the command needs 'longer than expected' something bad happens (i.e. nonzero exit). Use it in scripts where you don't need the output to spam your log but you still want to know if something unusual happend.

License

See License.md.

Contribution

Initialize

git clone https://github.com/frans-fuerst/trickkiste --recurse-submodules
cd trickkiste
uv run pre-commit install

Manually run checks and fixes

Depending on your workflow / IDE you might want to stay in charge over what's being executed in order to check and fix code validity. For a number of scenarios there is a bunch of scripts located in the dev submodule which just wrap manual calls to what would be done by pre-commit. Some actually run pre-commit for consistency, some don't in order to stay flexible regarding command line arguments, e.g. for unit-testing using pytest.

run all checks which would be executed on commit, but on unstaged stuff, too

dev/check-validity

do this in a loop (convenience wrapper around inotifywait)

dev/watchandcheck

run all checks separately

dev/check-python-doctests
dev/check-python-formatting
dev/check-python-linting
dev/check-python-systemtests
dev/check-python-typing
dev/check-python-unittests
dev/check-shellscripts
dev/check-yaml-linting

apply fixes for automatically fixable stuff

dev/fix-python-formatting
dev/fix-python-linting

Version bump and publishing

uv version --bump <patch|minor|major>
uv lock --upgrade
uv build

# do manual tests here

git commit -m"Bump version [..]"
git push
uv publish --token <TOKEN>

Metadata

Release files for trickkiste 0.3.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trickkiste 0.3.12
File Size Uploaded Provenance Actions
trickkiste-0.3.12.tar.gz 88.4 kB Without provenance Details for trickkiste-0.3.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for trickkiste 0.3.12
File Interpreter ABI Platform Actions
trickkiste-0.3.12-py3-none-any.whl Python 3 none any Details for trickkiste-0.3.12-py3-none-any.whl

Total release size: 125.5 kB

Release files / trickkiste-0.3.12.tar.gz

Download URL trickkiste-0.3.12.tar.gz
Size 88.4 kB
Tags Source
SHA-256 checksum
How to use checksums
988775fef5d063dacf37e5817014e64502d2d9d34241b28a2a9ebeec4d39c266
BLAKE2b-256 checksum
How to use checksums
113c92e7bb1551b85a780ef8c364159e3a4eaa3036359aa54a1323119f44b098
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / trickkiste-0.3.12-py3-none-any.whl

Download URL trickkiste-0.3.12-py3-none-any.whl
Size 37.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6cee3fb3e80e5efc93aed58051724ecfd6cbd1364335c1e59db998d80c1ef01d
BLAKE2b-256 checksum
How to use checksums
c42e8d351b03facd848b401d80a4c05b30a069a6351d3c5ac9e10f145ff26ec7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for trickkiste 0.3.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.12 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page