Skip to main content

Wrap common Python utilities for working with files, git, ZIP, lists, processes, dates and times.

Project description

cornsnake

A small library wrapping common Python utilities for working with files, git, ZIP, lists, processes, dates and times.

Functions that I find myself writing time and again, on various OSS and personal projects - so collecting in one place, in case it is of use!

For more details, see the documentation.

MIT License Supported Python Versions cornsnake

PyPI Releases PyPI - Downloads

ko-fi

Install

python -m pip install --upgrade cornsnake

Dependencies

  • Python 3.11 or higher

  • Optional: (only if using util_pdf.py)

pip install PyMuPDF
  • fitz is for PDF parsing (installed as PyMuPDF)

Usage

Functions are organised in modules, providing logical groups like util_file or util_print.

To use a particular module, simply import it from cornsnake:

from cornsnake import util_file, util_print

Then, the modules are available to use:

lines = util_file.read_lines_from_file("my-file.txt")
util_print.print_result(f"Read {len(lines)} lines")

To see what functions are available, see the Documentation or source code.

For examples see the unit tests and e2e tests.

Modules

Module Description Documentation
config Globally accessible config object. Can be configured by for example reading from command line arguments or TOML file (via tomllib), and then writing to the properties in-memory. See util_toml.py for an example of reading from an ini file (TOML format). config docs
decorators Decorators for your Python code, including a timer to help instrument your functions. decorators docs
util_base64 Base64 encode/decode utility functions. util_base64 docs
util_color Defines color constants and a function for colorizing text output for terminal. util_color docs
util_date Functions for date manipulation. It includes functions to parse, format, add days to, and validate dates in the yyyy-mm-dd format. util_date docs
util_dependencies Functions for checking the versions of Python and Git. It ensures that the major and minor versions of these dependencies meet the required criteria. util_dependencies docs
util_dict Functions for working with Python dictionaries (dict or {}). util_dict docs
util_dir Working with directories, files, and file paths. util_dir docs
util_env Utility functions for environment detection. util_env docs
util_file File operations including copying, reading, and writing text to files. util_file docs
util_git Functions for interacting with a Git repository. It includes functions for executing Git commands, checking out branches, handling commits, and managing Git configuration settings. util_git docs
util_input Functions for handling user input with various formats and validations. util_input docs
util_json Functions for reading from and writing to a JSON file. The read_from_json_file function reads JSON data from a file, and the write_to_json_file function writes JSON data to a file. util_json docs
util_list Functions for manipulating lists of data. Functions include chunking lists, excluding elements from one list that are present in another, finding the intersection of two lists, and various other list operations. util_list docs
util_log Functions for logging exceptions and setting up logging configurations. util_log docs
util_markdown_table Generating Markdown content. Functions like adding row separators, generating Markdown images, and generating italicized text are included. util_markdown_table docs
util_network Making a POST request using the urllib library. util_network docs
util_object Functions for working with object attributes. The get_attributes function retrieves all non-private attributes of an object. The get_attribute_value function returns the value of a specific attribute of an object. util_object docs
util_os Functions for checking the operating system and logging OS information. The functions determine if the OS is Windows, Mac, or Unix, and log relevant OS details. util_os docs
util_pdf Functions for extracting text from a PDF file and checking if a file is a PDF. util_pdf docs
util_pick Functions for randomly selecting text. The pick_one_random function chooses a random text from a list. The pick_one_by_prompt function prompts the user to pick a text from a list. util_pick docs
util_print A Single entry point for printing - so can add custom printing with color and logging. Functions for printing with different colors, logging messages, printing sections, and handling warnings. util_print docs
util_proc Running processes and opening Windows Explorer at a specified directory. util_proc docs
util_progress Functions for tracking progress and updating a progress bar. util_progress docs
util_robust_delete Functions for recursively deleting directories and their contents. util_robust_delete docs
util_string Check if a text string is empty. The is_empty function checks if a text string is None or contains only whitespace or a hyphen. util_string docs
util_text Defines text constant variables - including for line endings. util_text docs
util_time Functions for timing operations. The start_timer function starts a timer, end_timer ends the timer and calculates elapsed time, and describe_elapsed_seconds describes the elapsed time in seconds. util_time docs
util_toml Reading TOML (ini) files and updating the global config in memory (from config.py). util_toml docs
util_validate Functions for checking and validating configuration settings in the config.py file. util_validate docs
util_wait Function for waiting for a specified number of seconds. The wait_seconds function pauses the program execution for the specified number of seconds. util_wait docs
util_yaml Utility functions for YAML-like data structures. util_yaml docs
util_zip Alias for zip_dir util_zip docs
zip_dir Function for creating a zip archive from a directory. The create_zip function creates a zip archive of a specified directory. zip_dir docs

References

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cornsnake-0.1.2.tar.gz (37.2 kB view details)

Uploaded Source

Built Distribution

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

cornsnake-0.1.2-py3-none-any.whl (45.3 kB view details)

Uploaded Python 3

File details

Details for the file cornsnake-0.1.2.tar.gz.

File metadata

  • Download URL: cornsnake-0.1.2.tar.gz
  • Upload date:
  • Size: 37.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for cornsnake-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1cb80ff6caf0c217f0d719a8fa358609f62d402ad50941b3e5c059aa2d8d430e
MD5 265700fcb11fa2de0b1f9685667076c4
BLAKE2b-256 bad9b30476f089d2753797b775df7caaf993fc73ce8d94c9afa5ebf0735ce3b0

See more details on using hashes here.

File details

Details for the file cornsnake-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: cornsnake-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 45.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for cornsnake-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1eb5f76717906760a820b23934bdc52f5722ad7c01ce666f08c6785cc9e8b343
MD5 265af1c778fed3ab6f0711b24ee40b50
BLAKE2b-256 47b43eb4699a901b7a034d91e14550bd1b5fdffe43c38308a872adbf0e149b42

See more details on using hashes here.

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