CSV file validation.
Project description
CSV Schema Definition and Validation
Install
pip install csv-schema
Usage
usage: csv-schema [-h] [--version] {validate-config,validate-csv,generate-config} ...
CSV Schema
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
Commands:
{validate-config,validate-csv,generate-config}
validate-config Validates the CSV schema JSON configuration file.
validate-csv Validates a CSV file against a schema.
generate-config Generate a CSV schema JSON configuration file.
Definition
The CSV file schema definition is defined in a JSON file in the following format.
File Definition:
{
"name": null,
"description": null,
"filename": {
"regex": null
},
"columns": []
}
Property | Description |
---|---|
name | The name of the schema. |
description | The description of the schema. |
filename | Properties for the name of the CSV filename to validate. |
columns | List of column definitions. |
filename
{
"regex": null
}
Property | Description |
---|---|
regex | Regular expression to validate the name of the CSV file being validated. |
Column Definitions:
string
{
"type": "string",
"name": null,
"required": true,
"null_or_empty": false,
"regex": null,
"min": null,
"max": null
}
Property | Description |
---|---|
type | The column type. |
name | The name of the column. |
required | Whether or not the column is required in the file. |
null_or_empty | Whether or not the value can be null (missing) or an empty string. |
regex | Regular expression to validate the column value. |
min | The minimum length of the string. null for no limit. |
max | The maximum length of the string. null for no limit. |
integer
{
"type": "integer",
"name": null,
"required": true,
"null_or_empty": false,
"regex": null,
"min": null,
"max": null
}
Property | Description |
---|---|
type | The column type. |
name | The name of the column. |
required | Whether or not the column is required in the file. |
null_or_empty | Whether or not the value can be null (missing) or an empty string. |
regex | Regular expression to validate the column value. |
min | The minimum value. null for no limit. |
max | The maximum value. null for no limit. |
decimal
{
"type": "decimal",
"name": null,
"required": true,
"null_or_empty": false,
"regex": null,
"min": null,
"max": null,
"precision": 2
}
Property | Description |
---|---|
type | The column type. |
name | The name of the column. |
required | Whether or not the column is required in the file. |
null_or_empty | Whether or not the value can be null (missing) or an empty string. |
regex | Regular expression to validate the column value. |
min | The minimum value. null for no limit. |
max | The maximum value. null for no limit. |
precision | The decimal point precision. |
enum
{
"type": "enum",
"name": null,
"required": true,
"null_or_empty": false,
"values": []
}
Property | Description |
---|---|
type | The column type. |
name | The name of the column. |
required | Whether or not the column is required in the file. |
null_or_empty | Whether or not the value can be null (missing) or an empty string. |
values | Fixed set of constants. |
Development
Setup
pipenv --three
pipenv shell
make pip_install
make build
make install_local
See Makefile for all commands.
Update README Definitions
The schema definition is auto generated by running scripts/generate_md_help.py
.
Copy/paste the output into the README.md file.
Testing
- Create and activate a virtual environment:
- Run the tests:
make test
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
csv-schema-1.1.tar.gz
(11.9 kB
view details)
Built Distribution
File details
Details for the file csv-schema-1.1.tar.gz
.
File metadata
- Download URL: csv-schema-1.1.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 551f350b648cc8fc630f6bd27f56bf373960eb9e9c0a6656eb76b56c3d05f6c0 |
|
MD5 | ce420f79f2ff7de15b8febe8fd25349a |
|
BLAKE2b-256 | d35923dcb5a51da0693d05f0c68c60026ef6caa6daf1b4ac855ef15f99058036 |
File details
Details for the file csv_schema-1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: csv_schema-1.1-py2.py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ac885c84fce607155e76d309c7e2033a91137a05e0fdf5d481288e698be7e3a |
|
MD5 | 40273ff6d442d8a06b8ff02386c15b0f |
|
BLAKE2b-256 | 6f09f7595eea9db7bec3634159f5c67eb8c401c71dd1432936b89d2f57aa35cd |