This is a collection of my commonly used functions that I figured would be nice to have in a library.
pip install justsdk
or visit #history for legacy versions.
Get started by importing the package:
import justsdk
*from color_print.py
Print colored messages to the console with optional timestamps.
Simple as that, expected output: [MESSAGE_TYPE] YOUR_MESSAGE_HERE
-
Most of the time, you’ll use the convenience functions::
justsdk.print_success( message="YOUR_MESSAGE_HERE", newline_before=False, # Add a newline before [MESSAGE_TYPE] newline_after=False, # Add a newline after [MESSAGE_TYPE] file=None, # Print to a specific file (default: sys.stdout) show_timestamp=False )
-
Available functions:
print_success()
— Greenprint_warning()
— Yellowprint_error()
— Redprint_info()
— Magentaprint_debug()
— Cyan
-
Else, you can have more control by creating an instance:
from justsdk import ColorPrinter printer = ColorPrinter( file=None, use_color=True, show_timestamp=False, # Show timestamp in each message (based on your timezone) quiet=False ) printer.success("YOUR_MESSAGE_HERE")
*from file_utils.py
Handy functions for reading, writing, and pretty-printing files in JSON/YAML formats (and others treated as plain text)
-
Read a single file (auto-detects JSON/YAML/text):
justsdk.read_file( file_path="YOUR_FILE_PATH_HERE", encoding="utf-8", use_orjson=True )
-
Returns the parsed data (
dict
/list
for JSON/YAML,str
for text). -
Optional arguments:
encoding="utf-8"
— File encodinguse_orjson=True
— Useorjson
for JSON files (just faster & better)
-
Write data to a file (auto-detects JSON/YAML/text):
justsdk.write_file( data={"a": 1, "b": 2}, file_path="YOUR_OUTPUT.json", indent=2, # Indentation level (JSON only) sort_keys=True, # Sort dictionary keys use_orjson=True, encoding="utf-8", ensure_ascii=False, atomic=False # Atomic write (safu for critical data) )
-
Creates parent directories if needed.
-
Returns
True
on success, elseFalse
. -
Raises
ValueError
ifdata
isNone
.
-
Print data in JSON or YAML format (optionally colorized):
justsdk.print_data( data={"a": 1, "b": 2}, data_type="json", # or "yaml", "yml" indent=2, sort_keys=False, use_orjson=True, colorize=False )
-
If
colorize=True
, usespygments
for syntax highlighting.
-
Read multiple files at once:
justsdk.read_files(["a.json", "b.yaml"]) # Returns: {Path("a.json"): {...}, Path("b.yaml"): {...}}
dict
mapping paths to parsed data
-
Write multiple files at once:
justsdk.write_files({ "a.json": {"x": 1}, "b.yaml": {"y": 2} }) # Returns: {Path("a.json"): True, Path("b.yaml"): True}
dict
mapping paths to ops status (True
/False
)
This project is under the MIT License — see the LICENSE file for details.