Skip to content
PyCSVSchema is an implementation of CSV Schema in Python.
Python Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
pycsvschema
tests
.deepsource.toml
.gitignore
.travis.yml
LICENSE
README.md
README_pypi.rst
build.sh
pyproject.toml
release.sh
requirements.txt
setup.cfg
setup.py
test.sh

README.md

PyCSVSchema

PyCSVSchema is an implementation of CSV Schema in Python.

This project is at Alpha version and still under heavy development.

Example

>>> from pycsvschema.checker import Validator
>>> # demo.csv:
... # id,name,value
... # 1,Ann,"5"
... # 2,Ben,"10"
... # 3,Tom,"14"
>>> schema = {
...     'fields': [
...         {
...             'name': 'value',
...             'type': 'number',
...             'multipleOf': 5
...         }
...     ]
... }
>>> v = Validator(csvfile='demo.csv', schema=schema)
>>> v.validate()

Traceback (most recent call last):
...
<ValidationError: 'Value 14.0 is not multiple of 5'; column name: value; row number: 3>

Note that the validator does not check if the CSV format fits the dialect defined in schema correctly. For example, if wrong delimiter present in schema, validator might read the whole line as one cell.

Installation

pip install pycsvschema

Requirements

Python 3.5 or above

TODO

  • Documentation and Examples
  • Optional header
  • Decide whether to rely on Python's built-in int and float function to convert values
  • Tests
You can’t perform that action at this time.