Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

horkos-0.2.1.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

horkos-0.2.1-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

File details

Details for the file horkos-0.2.1.tar.gz.

File metadata

  • Download URL: horkos-0.2.1.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0

File hashes

Hashes for horkos-0.2.1.tar.gz
Algorithm Hash digest
SHA256 09c2deb3a7a0016b1bbdd8e3fc44b655fa23e8bf6572f489a69d8936ee78f747
MD5 504617e1acc27f1e7cb82b68f3ca38af
BLAKE2b-256 c654b07a27fd00d31dc7d91f7df4dcc9cc2c3e04718dbcd5d4c3ae207c1ee34a

See more details on using hashes here.

File details

Details for the file horkos-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: horkos-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 29.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.0

File hashes

Hashes for horkos-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 78b202ff9d62954c9c4c72dcfba3eece25d367e050be8e2133825f08645c8cf4
MD5 0d19cb190ce701a205d8a3ca8f194d8d
BLAKE2b-256 e54e7866cd281b43fa31ecc64404762b6eb3e99da56af525c63d6d3260e326c7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page