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
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
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_dir Working with directories, files, and file paths. util_dir 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_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
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


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.0.67.tar.gz (32.9 kB view details)

Uploaded Source

Built Distribution

cornsnake-0.0.67-py3-none-any.whl (39.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cornsnake-0.0.67.tar.gz
Algorithm Hash digest
SHA256 a2d2a2b963e2366ee7846ec0b2310f0b91169c585e737d42e784bcf7679d3a4a
MD5 ff51eff5d91a8077db1116fbd8683d77
BLAKE2b-256 e85b88bbe328ba9c4e0d090d925c98123e47d785a1f5c797151deb33c0cf2ab5

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cornsnake-0.0.67-py3-none-any.whl
Algorithm Hash digest
SHA256 d729f02b47fc6922fb662e8114f1ea6fd94947b66107516514b7c4accbf40527
MD5 e82e14577b26a93fae39aefafaec39b1
BLAKE2b-256 f781e998b6fb017ca080b7f7fc3732602c0d684948175baac3ee9ab8799e935e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page