Skip to main content

INI-config validator

Project description

pyversions

DwnMonth DwnWeek DwnDay

license

This module helps to check configparser-loaded configurations.

Usage

  1. Initialize description of valid configuration: schema = configchecker.ConfigSchema()

  2. Add an information of possible sections by calling schema.section with section name validator and boolean flag „section required“.

  3. In every section describe possible section’s values by calling sect.value.

Name/value validators

There are basic validators:

  • ItemDefaultValidator — always returns true

  • ItemStringValidator — checks if a string equals to given (probably, case-insensitive)

  • ItemRegexValidator — checks matching a string to given regexp

  • ItemNumberValidator — checks that a string is a non-negative integer

And validator-composers which allow to create more complex checks:

  • ItemNotValidator, ItemAndValidator, ItemOrValidator — first-order logic on validators

  • ItemCountValidator — takes a validator and a function that check number of validator’s true positives (i.e. returns True)

Examples

import configparser
import configchecker as v

config = configparser.ConfigParser()
config.read_file("config")

schema = v.ConfigSchema()

# Section with name „REQUIRED“ will be mandatory
with schema.section("REQUIRED") as s:
    # It must have keys matching regexp r'item_\d+' and numeric value and nothing more
    s.value(v.ItemRegexValidator(r'item_\d+', value_val=v.ItemNumberValidator()).no_other()

# Section with name r'OPT_\w+' (check by regexp) will be optional
with schema.section(v.ItemRegexValidator(r'OPT_\w+'), required=False) as s:
    # And it may have anything
    pass

# Other sections will be restricted
schema.no_other()

# Run checks
v.ConfigSchemaValidator(schema).validate(config)

Also, you can find lots of examples in tests (test_configchecker.py)

Author

Samun Victor, victor.samun@gmail.com

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

configchecker-1.0.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

configchecker-1.0.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file configchecker-1.0.1.tar.gz.

File metadata

  • Download URL: configchecker-1.0.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.5

File hashes

Hashes for configchecker-1.0.1.tar.gz
Algorithm Hash digest
SHA256 953f7d230967f096e3a72934674fab67eb4aa39ce2c96ddd0cee2edba413605d
MD5 783693ce6fe1b952a09dd6d19fde7d6f
BLAKE2b-256 e119042d9fdfa5b686e77ae7af721a85700abf8cff37beb5bc486817df7d29bc

See more details on using hashes here.

File details

Details for the file configchecker-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for configchecker-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3a06c341921e1dc839dab0e5135cca60310a4b617d3e2f1df7dd9cfd3ed808c0
MD5 8573f854a1ab63443389e0810f1d211d
BLAKE2b-256 65b2a0aa401877bdfbd0d30e5c6356ddf43c2c07469a124b20dfba93908fa8f6

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