Apathetic Python Utils βοΈ
Grab bag of helpers for Apathetic projects.
When stdlib is almost enough.
Apathetic Python Utils provides a lightweight, dependency-free collection of utility functions designed for CLI tools. It includes helpers for file loading, path manipulation, system detection, text processing, type checking, pattern matching, and more.
Features
- πͺΆ Zero dependencies β Uses only Pythonβs standard library (except apathetic-logging for logging)
- π File loading β Load TOML and JSONC files with comment support
- π€οΈ Path utilities β Cross-platform path normalization and glob handling
- π Pattern matching β Portable glob pattern matching with recursive
**support - π§© Module detection β Detect Python packages from file paths
- π§ͺ System detection β Detect CI environments, pytest execution, and runtime modes
- βοΈ Runtime utilities β Build and test utilities for stitched scripts and zipapps
- π§ Subprocess utilities β Capture and forward subprocess output
- π Text processing β Pluralization and error message cleanup utilities
- π§ Type utilities β Safe isinstance checks for TypedDicts and generics
- π§ͺ Testing utilities β Helpers for testing mixins and patching functions
- π― CLI-friendly β Designed with command-line applications in mind
- π§© Apathetic Tools integration β Works seamlessly with serger and other Apathetic Tools
Quick Example
from apathetic_utils import load_jsonc, load_toml, is_ci, detect_runtime_mode, capture_output
from pathlib import Path
import sys
# Load configuration files
config = load_jsonc(Path("config.jsonc"))
pyproject = load_toml(Path("pyproject.toml"))
# Detect environment
if is_ci():
print("Running in CI")
# Detect runtime mode (package, stitched, zipapp, frozen)
mode = detect_runtime_mode("my_package")
print(f"Running in {mode} mode")
# Capture output from CLI commands
with capture_output() as cap:
# Run some command that prints to stdout/stderr
print("Hello, world!")
print("Error message", file=sys.stderr)
print(f"Captured: {cap.merged.getvalue()}")
Requirements
- Python 3.10+
No other dependencies required β this library uses only Pythonβs standard library.
Installation
Install via poetry or pip:
# Using poetry
poetry add apathetic-utils
# Using pip
pip install apathetic-utils
For alternative installation methods, see the Installation Guide.
Documentation
- Installation Guide β How to install and set up
- Quick Start β Get up and running in minutes
- API Reference β Complete API documentation
- Examples β Advanced usage examples
- Contributing β How to contribute
License
Youβre free to use, copy, and modify the library under the standard MIT terms.
The additional rider simply requests that this project not be used to train or fine-tune AI/ML systems until the author deems fair compensation frameworks exist.
Normal use, packaging, and redistribution for human developers are unaffected.
Resources
- π Roadmap
- π Release Notes
- π Issue Tracker
- π¬ Discord