Skip to main content

Collection of handy utils written in Python 3

Project description

chaos-utils

GitHub Actions Workflow Status PyPI - Version PyPI - Version Ask DeepWiki

A small collection of utility helpers written in Python 3, used across ak1ra-lab projects.

Installation

pip install chaos-utils

Modules

dict_utils — Dictionary helpers

Symbol Description
deep_merge(d1, d2, *, deepcopy_first=True) Recursively merge two dicts. Keys in d2 take precedence; nested mappings are merged rather than replaced. Uses an iterative stack to avoid recursion limits.

text_utils — Text and file helpers

Symbol Description
detect_encoding(filepath, num_bytes=8192) Detect the character encoding of a file. Tries UTF-8 first, then falls back to chardet with adaptive sampling for low-confidence results.
iter_filepath_lines(filepath) Iterate over the lines of a text file with automatic encoding detection.
read_json(filepath) Read and parse a JSON file, returning a dict or list.
save_json(filepath, data, sort_keys=True) Serialize data to a JSON file with optional key sorting.
read_toml(filepath) Read and parse a TOML file, returning a dict.
b64decode(data) Decode a Base64-encoded string and return the decoded text.

gitignore.gitignore-aware filesystem helpers

Symbol Description
load_directory_gitignore_specs(directory) Recursively load all .gitignore files under directory and return a mapping of directory → GitIgnoreSpec.
should_path_ignore(path, specs) Return True if path matches any applicable .gitignore rule or lives inside a .git directory.
path_walk(directory) os.walk-style generator that yields (dirpath, dirs, files) as Path objects.
path_walk_respect_gitignore(directory) Like path_walk but skips entries that match .gitignore rules.
iter_files_with_respect_gitignore(directory) Yield every non-ignored file Path under directory.
iter_dirs_with_respect_gitignore(directory) Yield every non-ignored directory Path under directory.

logging — Logging helpers

Symbol Description
JsonFormatter logging.Formatter subclass that serialises each record — including any extra= fields — as a single-line JSON string.
setup_logger(name, ...) Create a logger with a RotatingFileHandler and an optional StreamHandler. Log files are placed under the XDG state directory ($XDG_STATE_HOME/<app>/log).
setup_json_logger(name, ...) Like setup_logger but attaches JsonFormatter to produce structured JSON logs.

tarfile — Zstd-compressed tar archives

Symbol Description
TarFileZstd tarfile.TarFile subclass with "zst" open method for reading and writing .tar.zst archives via pyzstd.
ZstdTarReader(name, ...) Convenience context manager that opens a .tar.zst archive for reading and ensures it is properly closed.

dingtalk — DingTalk robot notifications

Symbol Description
DingTalkBot(access_token, secret) DingTalk group robot client with HMAC-SHA256 signature authentication.
DingTalkBot.send_text(content, ...) Send a plain-text message, optionally @-mentioning members.
DingTalkBot.send_markdown(title, text, ...) Send a Markdown-formatted message.

wechat — WeChat Work notifications

Symbol Description
WechatWorkApp(corpid, corpsecret, agentid) WeChat Work application client (corp API). Supports send_text, send_markdown, send_image, send_news, send_news_multiple, send_file, and upload_media.
WechatWorkBot(key) WeChat Work webhook bot client. Supports send_text, send_markdown, send_image, send_news, send_news_multiple, and send_file.

telegram — Telegram bot notifications

Symbol Description
TelegramBot(token, default_chat_id, timeout) Telegram Bot API client.
TelegramBot.send_message(text, ...) Send a text message with optional parse_mode, inline keyboard, and silent delivery.
TelegramBot.send(text, **kwargs) Convenience alias for send_message.

License

MIT

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

chaos_utils-0.4.1.tar.gz (62.3 kB view details)

Uploaded Source

Built Distribution

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

chaos_utils-0.4.1-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file chaos_utils-0.4.1.tar.gz.

File metadata

  • Download URL: chaos_utils-0.4.1.tar.gz
  • Upload date:
  • Size: 62.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for chaos_utils-0.4.1.tar.gz
Algorithm Hash digest
SHA256 c076c79a44563c3b1c0f7d01e387b92357d5685cbdab3a4724c1538c133284e5
MD5 db938aa3742d51d2e9102e680fcbe3f8
BLAKE2b-256 c63d18721025b018e46b878c8a0964cb8437f8f5d12356480decc622e5da92e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for chaos_utils-0.4.1.tar.gz:

Publisher: publish-to-pypi.yaml on ak1ra-lab/chaos-utils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chaos_utils-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: chaos_utils-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for chaos_utils-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5b4ce49a4b175ccf02e148efa6fe4515be42ead8022ccb1efc6d3fead11bd768
MD5 46b46da08ebacb631707b1df84314403
BLAKE2b-256 2607efd316f3561a776567e2e4233bdebfadb180a56de2f91d0ea0cdb5af2010

See more details on using hashes here.

Provenance

The following attestation bundles were made for chaos_utils-0.4.1-py3-none-any.whl:

Publisher: publish-to-pypi.yaml on ak1ra-lab/chaos-utils

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