A small and performance-oriented CSV header verifier / linter with no external Python package dependencies. Just simple.
CSVheader(validator: dict, default: dict = None, ordered = 0, case = 0):
ordered
: set1
if the header need to ordered as the same as your validator. SetO
otherwise.case
: set0
if for ignoring the letter case.1
otherwise.validator
: A dictionary with a keyheader
. Theheader
should be a list that will represent your csv header (rule)
CSVheader.verify_header(file) # Uses all config combinations (ordered, case) used at instantiation;
CSVheader.simple_verify_header(file,size = None, restrict: bool = True) # Simple leads to only check if the validator elements exists at CSV header; If size is defined, the verifier will check if the header have the length equal to size; restrict will invalidate headers with smaller lengths than your validator;
CSVheader.simple_verify_optional_header(file,size = None, restrict: bool = False, options=[]) # It is similiar to simple_verify_header() but, have set optional header columns. If the header have the same validator elements and at least one optional element, the verifier will return true (passed);
from validCSV import CSVheader
validHydroNodes = CSVheader(validator={'header': ["id","name","type","block","watersystem","tia","min_alt","max_alt"]})
if validHydroNodes.verify_header(files[filename]):
# Do something
print("Test 1 Passed!")
validQualityStations = CSVheader(validator={'header': ["id","snirh","latitude","longitude"]})
if validQualityStations.simple_verify_header(files[filename]):
# Do something
print("Test 2 Passed!")
validQualityData = CSVheader(validator={'header': ["date"]})
if validQualityData.simple_verify_optional_header(files[filename], options=['id','snirh']):
# Do something
print("Test 3 Passed!")
pip3 install validCSV
git clone https://github.com/bmalbusca/validCSV.git
cd validCSV
python3 setup.py bdist_wheel
pip3 install -e .
python >= 3.0.0
pip3 install twine
pip3 install check-manifest
pip3 install setuptools
python3 setup.py sdist
check-manifest --create
Pypi url - https://pypi.org/project/validCSV/
python3 setup.py sdist bdist_wheel
twine upload dist/*