Socket
Socket
Sign inDemoInstall

cornsnake

Package Overview
Dependencies
0
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cornsnake

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


Maintainers
1

Readme

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

ModuleDescriptionDocumentation
configGlobally 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_colorDefines color constants and a function for colorizing text output for terminal.util_color docs
util_dateFunctions 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_dependenciesFunctions 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_dirWorking with directories, files, and file paths.util_dir docs
util_fileFile operations including copying, reading, and writing text to files.util_file docs
util_gitFunctions 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_inputFunctions for handling user input with various formats and validations.util_input docs
util_jsonFunctions 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_listFunctions 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_logFunctions for logging exceptions and setting up logging configurations.util_log docs
util_markdown_tableGenerating Markdown content. Functions like adding row separators, generating Markdown images, and generating italicized text are included.util_markdown_table docs
util_networkMaking a POST request using the urllib library.util_network docs
util_objectFunctions 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_osFunctions 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_pdfFunctions for extracting text from a PDF file and checking if a file is a PDF.util_pdf docs
util_pickFunctions 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_printA 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_procRunning processes and opening Windows Explorer at a specified directory.util_proc docs
util_progressFunctions for tracking progress and updating a progress bar.util_progress docs
util_robust_deleteFunctions for recursively deleting directories and their contents.util_robust_delete docs
util_stringCheck 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_textDefines text constant variables - including for line endings.util_text docs
util_tomlReading TOML (ini) files and updating the global config in memory (from config.py).util_toml docs
util_validateFunctions for checking and validating configuration settings in the config.py file.util_validate docs
util_waitFunction 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_dirFunction for creating a zip archive from a directory. The create_zip function creates a zip archive of a specified directory.zip_dir docs

References

Keywords

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc