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 managerCountLinesMmap- use memory-mapped files and count "\n"CustomMakeTranslation- Replace substrings based on a dictionary of mappingsDeepGet- safe deep get for a dictionaryDeepMergeandDeepMergeInPlace- Recursively merges source dict into destination dictDeepSet- 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 stringsGetFunctionName- return the name of a calling function as a stringGetIterable- 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 cloneJsonObjSerializer- JSON serializer with better support for objectsLoadFileIfJson- 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 subfoldersRemoveFalsy- remove "empty" items from a collectionRemovePrefix- remove a prefix from a stringRemoveSuffix- remove a suffix from a stringRmtreeExcept- recursively delete a directory tree while excluding specific files based on glob-style patternsRunProcess- 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 exceptionset_logging- configures logging based on a log level string or verbosity countsha256sum- calculate a sha256 hash of a fileshakeysum- calculate shakey hash of a fileSizeHumanFormat- nice human-readable file sizesstr2boolandstr2boolorextra- 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-2.0.0.tar.gz
(18.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
mmguero-2.0.0-py3-none-any.whl
(19.1 kB
view details)
File details
Details for the file mmguero-2.0.0.tar.gz.
File metadata
- Download URL: mmguero-2.0.0.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47bab039ea0e9594ed752bbe8686c94a6d1eca3cd3e59a25679540e53b17c5f2
|
|
| MD5 |
9b5d69118cfb1c71ae76ad1c0d8f4951
|
|
| BLAKE2b-256 |
4c456cbbe875a4ce47d78fc9f8b285adffc0ef32ea1a2301500e71c9665b5e8b
|
File details
Details for the file mmguero-2.0.0-py3-none-any.whl.
File metadata
- Download URL: mmguero-2.0.0-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dd5578cf91c351808d2dcf0d4cbfcf14ead87fe1983b054574d8afc5e729c03
|
|
| MD5 |
b41a13297b0f9ae943ec9f03efb0bafd
|
|
| BLAKE2b-256 |
fc51a3c1ac1bb80f1b426e48f80941bd7a01d95f1340fc0d51694f3dce7033d2
|