Seth Grover's useful Python helpers
Project description
mmguero
mmguero is my personal collection of miscellaneous helper functions for Python.
Contents
AggressiveUrlEncode
- urlencode each character of a stringAppendToFile
- append strings to a text fileAskForPassword
- get interactive password (without echoing)AskForString
- get interactive user responseAtomicInt
- atomic integer class and context managerBase64DecodeIfPrefixed
- decode a string as base64 only if it starts withbase64:
, otherwise just returnCaselessDictionary
- dictionary that enables case insensitive searching while preserving case sensitivity when keys are listedCheckOutputInput
- run command with arguments and return its exit code, stdout, and stderrChooseMultiple
- select multiple options from a list of optionsChooseOne
- select a single option from a list of optionsChownRecursive
- "chown -R" a file or directoryClearScreen
- attempt to clear the screen withclear
(*NIX) orcls
(Windows)ContainsWhitespace
- check if any character in a string is whitespaceContextLockedOrderedDict
- an OrderedDict that locks itself and unlocks itself as a context managerCustomMakeTranslation
- Replace substrings based on a dictionary of mappingsDeepGet
- safe deep get for a dictionaryDeepSet
- convenience routine for setting-getting a value into a dictionaryDictSearch
- recursive dictionary key searchDisplayMessage
- display a message to the userDisplayProgramBox
- "stream" the contents of a file descriptor into a program boxDoDynamicImport
- attempt dynamic imports, prompting for install via pip if possibleDownloadToFile
- download a URL to a local fileeprint
- print to stderrEscapeAnsi
- remove ANSI escape sequencesEVP_BytesToKey
- create key compatible with openssl encFileContents
- read the contents of a file, optionally falling back to binaryFlatten
- flatten a collection, but don't split stringsGetIterable
- return an iterable for an iterable (as-is) or a scalar (as a single element in a tuple)GetPrimaryIP
- return the primary IP (the one with a default route) on the local boxGitClone
- create a local git cloneLoadFileIfJson
- does this file contain valid json? if so, load and return itLoadStrIfJson
- is this string valid json? if so, load and return itPopLine
- "pop" lines from the beginning of a text filepushd
- chdir to directory as context manager, returning automaticallyRemoveEmptyFolders
- recursively remove empty subfoldersRemovePrefix
- remove a prefix from a stringRemoveSuffix
- remove a suffix from a stringRunProcess
- run command with arguments and return its exit code, stdout, and stderrRunSubProcess
- execute a shell process returning its exit code and outputSameFileOrDir
- return true if os.path.samefile, also False on exceptionsha256sum
- calculate a sha256 hash of a fileSizeHumanFormat
- nice human-readable file sizesstr2bool
andstr2boolorextra
- convenient boolean argument parsingTablify
- print a list of lists into a nice tableTemporaryFilename
- a context manager returning a temporary filename which is deleted upon leaving the contextTestSocket
- test if a remote port is openTouch
- open a file and close it, updating its access timeval2bool
- convenient boolean argument parsingWhich
- determine if a program/script exists and is executable in the system pathYesOrNo
- get interactive user response to Y/N question
Installation
Using pip
, to install the latest release from PyPI:
python3 -m pip install -U mmguero
Or to install directly from GitHub:
python3 -m pip install -U 'git+https://github.com/mmguero/python-mmguero'
Authors
- Seth Grover - Initial work - mmguero
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
mmguero-1.3.0.tar.gz
(13.9 kB
view details)
Built Distribution
mmguero-1.3.0-py3-none-any.whl
(15.0 kB
view details)
File details
Details for the file mmguero-1.3.0.tar.gz
.
File metadata
- Download URL: mmguero-1.3.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e491ffa4a1536019714148825df4b6997304bccab47b9debc2479351ec5e7d77 |
|
MD5 | df2612f3dc3ea85f63e325dc78be742f |
|
BLAKE2b-256 | afcf3b66ae3ae0403c3e56c50d614405f1ed24522874708db686b495cf522940 |
File details
Details for the file mmguero-1.3.0-py3-none-any.whl
.
File metadata
- Download URL: mmguero-1.3.0-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 167f44dfe406087b370b745b08685b463f17046a2ee1ead6d81a34e610793d45 |
|
MD5 | bad9e4582b81d4474f8f0f9cbd4203af |
|
BLAKE2b-256 | 1553d444e4060b3c042d26bfe7623321fe1cdeb50366a3aaad00e86cf3a0297e |