Simple Python Scripting Helpers
Project description
kisspy - Simple Python Scripting Helpers
This is a collection of simple helper methods and classes that I have found useful for data processing
Usage
The package offers simple methods that I found I was reusing frequently.
Converters
Numeric Converter
from kisspy import toNumeric, returnTxt,raiseValExc
def rtnMsg(*args):
return "Can't Convert '{}' To A Number".format(args[0])
alphaVal = "55"
numVal = toNumeric(alphaVal)
print(isinstance(numVal, int))
alphaVal = "88 ft"
numVal = toNumeric(alphaVal)
print(numVal)
numVal = toNumeric(alphaVal, onFail=returnTxt)
print(numVal)
numVal = toNumeric(alphaVal, onFail=rtnMsg)
print(numVal)
numVal = toNumeric(alphaVal, onFail=raiseValExc)
>> True
>> None
>> 88 ft
>> Can't Convert '88 ft' To A Number
>> Traceback (most recent call last):
>> File "C:\Files\code\python\projects\kisspy\examples\converters.py", line 26, in <module>
>> numVal = toNumeric(alphaVal, onFail=raiseValExc)
>> File "C:\Files\code\python\projects\kisspy\kisspy\converters\numericConverter.py", line 32, in toNumeric
>> return onFail(val,verr)
>> File "C:\Files\code\python\projects\kisspy\kisspy\converters\numericConverter.py", line 5, in raiseValExc
>> raise args[1]
>> File "C:\Files\code\python\projects\kisspy\kisspy\converters\numericConverter.py", line 27, in toNumeric
>> val = float(val)
>> ValueError: could not convert string to float: '88 ft'
>> The Value '88 ft' Could Not Be Converted To A Numeric Value
Spreadsheet Converters
from kisspy.converters.excelHelpers import fromExcelCol, toExcelCol
col = "C"
print(fromExcelCol(col))
col = "AF"
print(fromExcelCol(col))
num = 2
print(toExcelCol(num))
num = 33
print(toExcelCol(num))
>> 3
>> 32
>> B
>> AG
The elements in decorators and metaclasses modules speak for themselves.
There are a number of Python "extensions" that do stuff you would have wanted anyways:
Unique Appending To Lists:
from kisspy import appendUnique
vl = [2, 4, 6, 8]
if appendUnique(vl, 4):
print("Added 4 Again: {}".format(vl))
if appendUnique(vl, 10):
print("Added 10: {}".format(vl))
>> Added 10: [2, 4, 6, 8, 10]
Asserting One Record: Returns the one record, with options:
from kisspy import assertOne
from kisspy.exceptions import TooManyRecordsException, ZeroRecordsException
def thrwZeroRecordsEx(*args, **kwargs):
raise ZeroRecordsException()
vl = [2, 4, 6, 8]
print(assertOne([]))
print(assertOne([44]))
try:
oneValue = assertOne(vl)
except TooManyRecordsException as err:
print(err.toStrWithTyp())
try:
print(assertOne([], onZeroRcds=thrwZeroRecordsEx))
except ZeroRecordsException as err:
print(err.toStrWithTyp())
>> None
>> 44
>> TooManyRecordsException: 4 Records Returned, 1 Were Expected
>> ZeroRecordsException: Zero (0) Records Returned, > 0 Were Expected
Nested Dicts:
from kisspy import setValueOfPath, getValueOfPath
vd = {"animals": {"dog": {"whippet": "fast", "lab": "slower"}}}
wv = getValueOfPath(vd, keyPath="animals/dog/lab")
print(wv)
cv = getValueOfPath(vd, keyPath="animals/cat/tabby")
print(cv)
setValueOfPath(vd, "animals/dog/golden", "silly")
print(vd)
>> slower
>> None
>> {'animals': {'dog': {'whippet': 'fast', 'lab': 'slower', 'golden': 'silly'}}}
Installation
Using In Projects
Installation:
pip install kisspy-python
Cloning For Development
Set up a virtual environment. Once an environment is set up, run the command below to:
- validate the environment variable
- activate the environment (if not already activated)
- install all of the necessary packages into the local environment
pip install -U -r requirements/dev.txt
The dev.txt file includes:
- BLACK, a code formatter, see notes at the bottom of this file for details
Dependancies
This library depends on the following projects:
- unidecode
Tests
To run tests:
python -m unittest discover -s tests/
Code Formatting
Code formatting is done using BLACK. BLACK allows almost no customization to how code is formatted with the exception of line length, which has been set to 119 characters.
Use the following to bulk format files:
black . -l 144
Creating A New Release
Please do the following when making a new release, most are documented above:
- Run tests
- Code format
- Be sure to update the change log and _metadata.json with version and notes
- git add, commit, and push changes
- run the following code to generate a wheel:
python -m build
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
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
File details
Details for the file kisspy_python-1.2.0.tar.gz.
File metadata
- Download URL: kisspy_python-1.2.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2672f4b4299ff9dc9eed47e25b82727daa80b27ccbaf6855da9bb518bb4ef28
|
|
| MD5 |
b8e08ec51f82c4fba50a35946886614c
|
|
| BLAKE2b-256 |
82baac163259b2a1f06f5dff9fd3e1f858262c1d90fbc174de4bc02b722f82ef
|
Provenance
The following attestation bundles were made for kisspy_python-1.2.0.tar.gz:
Publisher:
publish.yml on joemarchionna/kisspy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kisspy_python-1.2.0.tar.gz -
Subject digest:
e2672f4b4299ff9dc9eed47e25b82727daa80b27ccbaf6855da9bb518bb4ef28 - Sigstore transparency entry: 1463180379
- Sigstore integration time:
-
Permalink:
joemarchionna/kisspy@f8c726c743a1cde53ea8693e21039e289e6d72bc -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/joemarchionna
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f8c726c743a1cde53ea8693e21039e289e6d72bc -
Trigger Event:
release
-
Statement type:
File details
Details for the file kisspy_python-1.2.0-py3-none-any.whl.
File metadata
- Download URL: kisspy_python-1.2.0-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b25b8b04921e1fd67c964421fdf047f6b1ebf0a4d9d94c6667d122b6dcf4a2ab
|
|
| MD5 |
7b18d7fa8b54b9e9ad0b4941a777fc53
|
|
| BLAKE2b-256 |
313aeec95a555f7e6f96b3351b229b2282e502f079b0158d04d840a800c405b9
|
Provenance
The following attestation bundles were made for kisspy_python-1.2.0-py3-none-any.whl:
Publisher:
publish.yml on joemarchionna/kisspy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kisspy_python-1.2.0-py3-none-any.whl -
Subject digest:
b25b8b04921e1fd67c964421fdf047f6b1ebf0a4d9d94c6667d122b6dcf4a2ab - Sigstore transparency entry: 1463180411
- Sigstore integration time:
-
Permalink:
joemarchionna/kisspy@f8c726c743a1cde53ea8693e21039e289e6d72bc -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/joemarchionna
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f8c726c743a1cde53ea8693e21039e289e6d72bc -
Trigger Event:
release
-
Statement type: