csv-validation 0.0.6__tar.gz → 0.0.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,7 +83,7 @@ dependencies = [
83
83
 
84
84
  [[package]]
85
85
  name = "csv_validation"
86
- version = "0.0.6"
86
+ version = "0.0.8"
87
87
  dependencies = [
88
88
  "csv",
89
89
  "flate2",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "csv_validation"
3
- version = "0.0.6"
3
+ version = "0.0.8"
4
4
  edition = "2021"
5
5
 
6
6
  # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 CSV Validation Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,194 @@
1
+ Metadata-Version: 2.4
2
+ Name: csv_validation
3
+ Version: 0.0.8
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
10
+
11
+ # CSV Validation
12
+
13
+ Blazing fast format validations for your CSV files
14
+
15
+ This is a Python lib with a Rust core that will allow you to validate huge CSV files (GBs) in seconds (or in few minutes for really huge files) using a minimal amount of memory.
16
+
17
+ ## Features
18
+
19
+ - ✨ Validate both plain and gzipped CSV files
20
+ - 🔍 Multiple validation types supported:
21
+ - Regular expressions
22
+ - Minimum/Maximum value checks
23
+ - Value set validation (allowed values)
24
+ - Column name and order validation
25
+ - 🐍 Python bindings included
26
+ - 📝 Detailed validation summaries with sample invalid values
27
+ - 🚀 High performance with optimizations like regex pre-compilation
28
+ - 📊 Support for large CSV files
29
+
30
+ ## Installation
31
+
32
+ ### Python
33
+
34
+ ```bash
35
+ pip install csv_validation
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ### Python
41
+
42
+ #### You can provide a file with the validation rules
43
+ ```python
44
+ from csv_validation import CSVValidator
45
+
46
+ validator = CSVValidator.from_file("validation_rules.yaml")
47
+ is_valid = validator.validate("data.csv")
48
+ ```
49
+
50
+ #### You can also create a validator from a string
51
+ ```python
52
+ validation_rules = """
53
+ columns:
54
+ - name: Name
55
+ regex: ^[A-Za-z\s]{2,50}$
56
+ - name: Age
57
+ format: positive_integer
58
+ max: 120
59
+ """
60
+
61
+ validator = CSVValidator.from_string(validation_rules)
62
+ is_valid = validator.validate("data.csv")
63
+ ```
64
+
65
+ ### Validation Definition Format
66
+
67
+ Create a small, easy to read YAML file with your validation rules. Example:
68
+
69
+ ```yaml
70
+ columns:
71
+ - name: Name
72
+ regex: ^[A-Za-z\s]{2,50}$ # Letters and spaces, 2-50 characters
73
+ - name: Family Name
74
+ regex: ^[A-Za-z\s'-]{2,50}$ # Letters, spaces, hyphens and apostrophes
75
+ - name: Age
76
+ format: positive_integer # Using predefined format instead of custom regex
77
+ max: 120
78
+ - name: Salary
79
+ format: integer # Allows negative integers too
80
+ min: 20000
81
+ - name: Email
82
+ regex: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ # Standard email format
83
+ - name: Phone
84
+ regex: ^\+?[0-9]{10,15}$ # International phone format with optional +
85
+ - name: Status
86
+ values: [active, inactive, pending, suspended] # Only these values are allowed
87
+ - name: Gender
88
+ values: [M, F, NB, O] # M: Male, F: Female, NB: Non-Binary, O: Other
89
+ ```
90
+
91
+ ## Validation Types
92
+
93
+ 1. **Regular Expression** (`regex`)
94
+ - Validate fields against custom regex patterns
95
+
96
+ 2. **Format** (`format`)
97
+ - Predefined formats for common validations
98
+ - Available formats:
99
+ - `integer`: Validates any integer number (positive or negative)
100
+ - `positive_integer`: Validates positive integer numbers
101
+ - `non_empty`: Validates that field contains at least one character
102
+ - More formats will be added in next versions
103
+
104
+ 3. **Minimum Value** (`min`)
105
+ - Check if numeric fields are greater than or equal to a specified value
106
+
107
+ 4. **Maximum Value** (`max`)
108
+ - Check if numeric fields are less than or equal to a specified value
109
+
110
+ 5. **Value Set** (`values`)
111
+ - Ensure fields only contain values from a predefined set
112
+
113
+ ## Global Validations
114
+
115
+ ### empty_not_ok
116
+
117
+ Empty values (empty string '') are considered correct and accepted by default.
118
+ However, if your data must always have some content,
119
+ you can add a global `empty_not_ok` flag at the root level of your YAML definition to automatically
120
+ add the `format: non_empty` validation to all columns:
121
+
122
+ ```yaml
123
+ empty_not_ok: true
124
+ columns:
125
+ - name: Column1
126
+ # other validations...
127
+ ```
128
+
129
+ ## Output
130
+
131
+ The validation process provides detailed feedback including:
132
+ - Overall validation status (true/false)
133
+ - Number of invalid rows per validation rule
134
+ - Sample of invalid values for debugging
135
+ - Detailed logging for troubleshooting
136
+
137
+ ## Development
138
+
139
+ ### Prerequisites
140
+
141
+ - Rust 2021 edition or later
142
+ - Python 3.6+ (for Python bindings)
143
+ - Cargo and standard Rust tooling
144
+
145
+ ### Building from Source
146
+
147
+ ```bash
148
+ # Clone the repository
149
+ git clone https://github.com/charro/csv_validation
150
+ cd csv_validation
151
+
152
+ # Build the project
153
+ cargo build --release
154
+
155
+ # Run tests
156
+ cargo test
157
+ ```
158
+
159
+ ## Dependencies
160
+
161
+ - `csv`: CSV parsing
162
+ - `flate2`: Compression support
163
+ - `pyo3`: Python bindings
164
+ - `regex`: Regular expression support
165
+ - `yaml-rust2`: YAML parsing
166
+ - Various utilities for logging and serialization
167
+
168
+ ## License
169
+
170
+ MIT License
171
+
172
+ Copyright (c) 2024 CSV Validation Contributors
173
+
174
+ Permission is hereby granted, free of charge, to any person obtaining a copy
175
+ of this software and associated documentation files (the "Software"), to deal
176
+ in the Software without restriction, including without limitation the rights
177
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
178
+ copies of the Software, and to permit persons to whom the Software is
179
+ furnished to do so, subject to the following conditions:
180
+
181
+ The above copyright notice and this permission notice shall be included in all
182
+ copies or substantial portions of the Software.
183
+
184
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
185
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
186
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
187
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
188
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
189
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
190
+ SOFTWARE.
191
+
192
+ ## Contributing
193
+
194
+ Contributions are welcome! Please feel free to submit a Pull Request.
@@ -0,0 +1,184 @@
1
+ # CSV Validation
2
+
3
+ Blazing fast format validations for your CSV files
4
+
5
+ This is a Python lib with a Rust core that will allow you to validate huge CSV files (GBs) in seconds (or in few minutes for really huge files) using a minimal amount of memory.
6
+
7
+ ## Features
8
+
9
+ - ✨ Validate both plain and gzipped CSV files
10
+ - 🔍 Multiple validation types supported:
11
+ - Regular expressions
12
+ - Minimum/Maximum value checks
13
+ - Value set validation (allowed values)
14
+ - Column name and order validation
15
+ - 🐍 Python bindings included
16
+ - 📝 Detailed validation summaries with sample invalid values
17
+ - 🚀 High performance with optimizations like regex pre-compilation
18
+ - 📊 Support for large CSV files
19
+
20
+ ## Installation
21
+
22
+ ### Python
23
+
24
+ ```bash
25
+ pip install csv_validation
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ### Python
31
+
32
+ #### You can provide a file with the validation rules
33
+ ```python
34
+ from csv_validation import CSVValidator
35
+
36
+ validator = CSVValidator.from_file("validation_rules.yaml")
37
+ is_valid = validator.validate("data.csv")
38
+ ```
39
+
40
+ #### You can also create a validator from a string
41
+ ```python
42
+ validation_rules = """
43
+ columns:
44
+ - name: Name
45
+ regex: ^[A-Za-z\s]{2,50}$
46
+ - name: Age
47
+ format: positive_integer
48
+ max: 120
49
+ """
50
+
51
+ validator = CSVValidator.from_string(validation_rules)
52
+ is_valid = validator.validate("data.csv")
53
+ ```
54
+
55
+ ### Validation Definition Format
56
+
57
+ Create a small, easy to read YAML file with your validation rules. Example:
58
+
59
+ ```yaml
60
+ columns:
61
+ - name: Name
62
+ regex: ^[A-Za-z\s]{2,50}$ # Letters and spaces, 2-50 characters
63
+ - name: Family Name
64
+ regex: ^[A-Za-z\s'-]{2,50}$ # Letters, spaces, hyphens and apostrophes
65
+ - name: Age
66
+ format: positive_integer # Using predefined format instead of custom regex
67
+ max: 120
68
+ - name: Salary
69
+ format: integer # Allows negative integers too
70
+ min: 20000
71
+ - name: Email
72
+ regex: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ # Standard email format
73
+ - name: Phone
74
+ regex: ^\+?[0-9]{10,15}$ # International phone format with optional +
75
+ - name: Status
76
+ values: [active, inactive, pending, suspended] # Only these values are allowed
77
+ - name: Gender
78
+ values: [M, F, NB, O] # M: Male, F: Female, NB: Non-Binary, O: Other
79
+ ```
80
+
81
+ ## Validation Types
82
+
83
+ 1. **Regular Expression** (`regex`)
84
+ - Validate fields against custom regex patterns
85
+
86
+ 2. **Format** (`format`)
87
+ - Predefined formats for common validations
88
+ - Available formats:
89
+ - `integer`: Validates any integer number (positive or negative)
90
+ - `positive_integer`: Validates positive integer numbers
91
+ - `non_empty`: Validates that field contains at least one character
92
+ - More formats will be added in next versions
93
+
94
+ 3. **Minimum Value** (`min`)
95
+ - Check if numeric fields are greater than or equal to a specified value
96
+
97
+ 4. **Maximum Value** (`max`)
98
+ - Check if numeric fields are less than or equal to a specified value
99
+
100
+ 5. **Value Set** (`values`)
101
+ - Ensure fields only contain values from a predefined set
102
+
103
+ ## Global Validations
104
+
105
+ ### empty_not_ok
106
+
107
+ Empty values (empty string '') are considered correct and accepted by default.
108
+ However, if your data must always have some content,
109
+ you can add a global `empty_not_ok` flag at the root level of your YAML definition to automatically
110
+ add the `format: non_empty` validation to all columns:
111
+
112
+ ```yaml
113
+ empty_not_ok: true
114
+ columns:
115
+ - name: Column1
116
+ # other validations...
117
+ ```
118
+
119
+ ## Output
120
+
121
+ The validation process provides detailed feedback including:
122
+ - Overall validation status (true/false)
123
+ - Number of invalid rows per validation rule
124
+ - Sample of invalid values for debugging
125
+ - Detailed logging for troubleshooting
126
+
127
+ ## Development
128
+
129
+ ### Prerequisites
130
+
131
+ - Rust 2021 edition or later
132
+ - Python 3.6+ (for Python bindings)
133
+ - Cargo and standard Rust tooling
134
+
135
+ ### Building from Source
136
+
137
+ ```bash
138
+ # Clone the repository
139
+ git clone https://github.com/charro/csv_validation
140
+ cd csv_validation
141
+
142
+ # Build the project
143
+ cargo build --release
144
+
145
+ # Run tests
146
+ cargo test
147
+ ```
148
+
149
+ ## Dependencies
150
+
151
+ - `csv`: CSV parsing
152
+ - `flate2`: Compression support
153
+ - `pyo3`: Python bindings
154
+ - `regex`: Regular expression support
155
+ - `yaml-rust2`: YAML parsing
156
+ - Various utilities for logging and serialization
157
+
158
+ ## License
159
+
160
+ MIT License
161
+
162
+ Copyright (c) 2024 CSV Validation Contributors
163
+
164
+ Permission is hereby granted, free of charge, to any person obtaining a copy
165
+ of this software and associated documentation files (the "Software"), to deal
166
+ in the Software without restriction, including without limitation the rights
167
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
168
+ copies of the Software, and to permit persons to whom the Software is
169
+ furnished to do so, subject to the following conditions:
170
+
171
+ The above copyright notice and this permission notice shall be included in all
172
+ copies or substantial portions of the Software.
173
+
174
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
175
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
176
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
177
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
178
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
179
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
180
+ SOFTWARE.
181
+
182
+ ## Contributing
183
+
184
+ Contributions are welcome! Please feel free to submit a Pull Request.