A library for validating data at the edges of data systems.
Project description
Horkos
A library for validating data at the edges of data systems.
Install
pip install horkos
Documentation
Detailed documentation can be found on Read the Docs.
Usage
First define the data schema:
# http-requests-schema.yaml
name: "http_requests"
description: >-
This is the http request event data set, it is all about http requests we
receive. It's important to include as much information about it
as is reasonable. The hardest thing about data is understanding it after
the fact.
fields:
path:
type: string
description: >-
The path of the url that was hit. This will be everything after the
host portion of the url.
params:
type: string
nullable: true
checks:
- json
description: >-
The parameters of the http request. If the method is a `GET` these come
from the url otherwise they are the JSON from the request body.
method:
type: string
checks:
- name: choice
args:
options:
- DELETE
- GET
- HEAD
- OPTIONS
- PATCH
- POST
- PUT
description: >-
The http method of the request. Must be one of:
`DELETE`, `GET`, `HEAD`, `OPTIONS`, `PATCH`, `POST`, or `PUT`.
response_code:
type: integer
description: The http response code of the request
timestamp:
type: string
checks:
- iso_timestamp
description: The time at which the http request was received.
To use this schema to validate records:
import horkos
schema = horkos.load_schema('http-requests-schema.yaml')
schema.process({'path': '/foo/bar'})
# RecordValidationError: Casting errors - params is required, method is required, ...
schema.process({
'path': '/foo/bar',
'params': '{"foo": "bar"}',
'method': 'BAD',
'response_code': '200',
'timestamp': '2020-06-15T12:34:56',
})
# RecordValidationError: Check errors - "BAD" in method did not pass choice check, ...
schema.process({
'path': '/foo/bar',
'params': '{"foo": "bar"}',
'method': 'GET',
'response_code': '200',
'timestamp': '2020-06-15T12:34:56',
})
# {..., 'response_code': 200, ...}
CLI
It's also possible to use horkos via cli to validate csv and json files.
path,params,method,response_code,timestamp
/foo/bar,,GET,200,2020-06-15T12:34:56
/fizbuz,{"param":"value"},POST,200,2020-12-15T12:34:56
/fizbuz,,ERROR,500,2020-12-15T12:34:56
/fizbuz,,GET,BAD,2020-12-15T12:34:56
To validate the csv run:
$ horkos check -s http-requests-schema.yaml data.csv
[Row 2]: Check errors - value of "ERROR" for method did not pass choice check
[Row 3]: Casting errors - value of "BAD" for response_code could not be cast to integer
2 errors found
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
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 horkos-0.2.7.tar.gz.
File metadata
- Download URL: horkos-0.2.7.tar.gz
- Upload date:
- Size: 23.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
130289918c5389b6175debe92747907999e4c81c406390b19b2e9a6056a18046
|
|
| MD5 |
57a64a9b7cb76ff02d3ed0130e96987e
|
|
| BLAKE2b-256 |
e11a59bebefd2220f9a06106e1e27e239bcc8c046d0456c9f1d27f596b1ccdc4
|
File details
Details for the file horkos-0.2.7-py3-none-any.whl.
File metadata
- Download URL: horkos-0.2.7-py3-none-any.whl
- Upload date:
- Size: 30.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
922109e6a60962b39e86ef984dcdeddd2648846cefa1f82d695a8239a78dea9b
|
|
| MD5 |
3cc0503c7e5e67fa2311efc258ebacae
|
|
| BLAKE2b-256 |
6f5267b9e06193fb72551d306ec4634608bf61af91a9253a4e11c8bf83025f13
|