Skip to content

eesuhn/justsdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPI

justsdk

cat

This is a collection of my commonly used functions that I figured would be nice to have in a library.

Installation

pip install justsdk

or visit #history for legacy versions.

Usage

Get started by importing the package:

import justsdk

1. Colored Print

*from color_print.py

Print colored messages to the console with optional timestamps.
Simple as that, expected output: [MESSAGE_TYPE] YOUR_MESSAGE_HERE

screenshot

1.1. Convenience Functions

  • 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() — Green
    • print_warning() — Yellow
    • print_error() — Red
    • print_info() — Magenta
    • print_debug() — Cyan

1.2. Initiating ColorPrinter Object

  • 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")

2. File Utilities

*from file_utils.py

Handy functions for reading, writing, and pretty-printing files in JSON/YAML formats (and others treated as plain text)

2.1. Reading Files

  • 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 encoding
    • use_orjson=True — Use orjson for JSON files (just faster & better)

2.2. Writing Files

  • 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, else False.

  • Raises ValueError if data is None.

2.3. Pretty-Print Data

  • 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, uses pygments for syntax highlighting.

2.4. Batch Operations

  • 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)

License

This project is under the MIT License — see the LICENSE file for details.

About

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages