{"id":24297057,"url":"https://github.com/jayclassless/datachecker","last_synced_at":"2025-07-25T10:33:33.339Z","repository":{"id":69476878,"uuid":"205615746","full_name":"jayclassless/datachecker","owner":"jayclassless","description":null,"archived":false,"fork":false,"pushed_at":"2019-09-01T01:40:53.000Z","size":93,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-06T08:57:24.594Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jayclassless.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-01T01:40:32.000Z","updated_at":"2019-09-01T01:40:57.000Z","dependencies_parsed_at":"2023-06-09T12:31:17.634Z","dependency_job_id":null,"html_url":"https://github.com/jayclassless/datachecker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jayclassless/datachecker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jayclassless%2Fdatachecker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jayclassless%2Fdatachecker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jayclassless%2Fdatachecker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jayclassless%2Fdatachecker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jayclassless","download_url":"https://codeload.github.com/jayclassless/datachecker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jayclassless%2Fdatachecker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266990934,"owners_count":24017732,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-16T19:50:00.677Z","updated_at":"2025-07-25T10:33:33.268Z","avatar_url":"https://github.com/jayclassless.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"datachecker\n===========\n\n**datachecker** is a simple library for performing common validations and sanitization of data.\n\nA simple example:\n\n::\n\n    \u003e\u003e\u003e import datachecker as dc\n    \u003e\u003e\u003e checker = dc.Checker(dc.string, dc.strip, dc.email)\n    \u003e\u003e\u003e checker.is_valid('hello@example.com')\n    True\n    \u003e\u003e\u003e checker.process('hello@example.com')\n    u'hello@example.com'\n    \u003e\u003e\u003e checker.is_valid('  hello@example.com')\n    True\n    \u003e\u003e\u003e checker.process('  hello@example.com')\n    u'hello@example.com'\n    \u003e\u003e\u003e checker.is_valid('bad data')\n    False\n    \u003e\u003e\u003e checker.process('bad data')\n    Traceback (most recent call last):\n      ...\n    datachecker.errors.FormatError: bad data is not formatted properly\n\nA more involved example:\n\n::\n\n    \u003e\u003e\u003e import datachecker as dc\n    \u003e\u003e\u003e checker = dc.Checker(dc.dict({\n    ...     'foo': [dc.required, dc.string, dc.upper],\n    ...     'bar': [dc.required, dc.integer(max=10)],\n    ...     'baz': [dc.optional(default='green'), dc.string(coerce=True), dc.lower],\n    ... }))\n    \u003e\u003e\u003e checker.process({\n    ...     'foo': 'Happy',\n    ...     'bar': 5,\n    ... })\n    {'baz': 'green', 'foo': u'HAPPY', 'bar': 5}\n    \u003e\u003e\u003e checker.process({\n    ...     'foo': 'Happy',\n    ...     'bar': 5,\n    ...     'baz': 'PURPLE!'\n    ... })\n    {'baz': u'purple!', 'foo': u'HAPPY', 'bar': 5}\n    \u003e\u003e\u003e checker.process({\n    ...     'foo': 'Turn it up',\n    ...     'bar': 11,\n    ... })\n    Traceback (most recent call last):\n      ...\n    datachecker.errors.BoundsError: Value is above the limit of 10\n\n\nWhen the data being checked passes all validations, the checker will return the processed, sanitized\ndata. Othewise, it will raise a CheckerError exception.\n\n\nInstallation\n------------\n\nUse `pip \u003chttp://www.pip-installer.org\u003e`_. There are no excuses.\n\n::\n\n    pip install datachecker\n\nIf you plan on using the DNS-checking abilities of some of the built-in processors, then you'll also need\nto install `dnspython \u003chttp://www.dnspython.org\u003e`_.\n\n::\n\n    pip install dnspython\n\n\nHow it Works\n------------\n\nThe main concept around **datachecker** is that it sends the incoming data through a pipeline of processors,\nfeeding the output of one as the input to the next. If we can get to the end of the pipeline without raising\nan exception, then the resulting data is declared valid.\n\nProcessors that check the data against some rule and raises an exception when the data does not pass the rule\nare known as \"validators\". Processors that alter the data as it passes through them are known as \"sanitizers\".\n\n\nChecker\n-------\n\nTo use **datachecker**, you first build yourself a Checker object, telling it what processors to use. You can specify any number of processors to apply to your input data.\n\n::\n\n    \u003e\u003e\u003e checker = dc.Checker(dc.required, dc.string, dc.upper)\n\nThen you can use your Checker object to validate and/or sanitize your data:\n\n::\n\n    \u003e\u003e\u003e checker.process('foo')\n    u'FOO'\n    \u003e\u003e\u003e checker.is_valid('foo')\n    True\n\nThe Checker object exposes two methods:\n\n**process(data)**\n\n    The process method runs your input data through the processors you specified and returns the resulting value. If any of the processors finds the input data to be invalid, a CheckerError exception will be raised.\n\n**is_valid(data)**\n\n    The is_valid method returns a simple boolean indicating whether or not the input data passes successfuly through all the processors.\n\n\nBuilt-In Processors\n-------------------\n\n\n**integer**\n\nEnsures the input value is an integer datatype (either ``int`` or ``long``).\n\n*Options*\n\n* coerce: True/False; Will cause the processor to attempt to coerce the value into an integer. This allows you to accept an input of \"1\" and interpret it as the integer 1.\n* min: Enforces a minimum value check. Defaults to ``None``, which means don't check.\n* max: Enforces a maximum value check. Defaults to ``None``, which means don't check.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.integer).is_valid(1)\n    True\n    \u003e\u003e\u003e dc.Checker(dc.integer).is_valid('1')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.integer(coerce=True)).is_valid('1')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.integer).is_valid(1.2)\n    False\n    \u003e\u003e\u003e dc.Checker(dc.integer(min=5)).is_valid(1)\n    False\n    \u003e\u003e\u003e dc.Checker(dc.integer(min=5)).is_valid(6)\n    True\n\n\n**float**\n\nEnsures the input value is a ``float`` datatype.\n\n*Options*\n\n* coerce: True/False; Will cause the processor to attempt to coerce the value into a ``float``. This allows you to accept an input of \"1.23\" and interpret it as the ``float`` 1.23.\n* min: Enforces a minimum value check. Defaults to ``None``, which means don't check.\n* max: Enforces a maximum value check. Defaults to ``None``, which means don't check.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.float).is_valid(1)\n    False\n    \u003e\u003e\u003e dc.Checker(dc.float).is_valid(1.23)\n    True\n    \u003e\u003e\u003e dc.Checker(dc.float).is_valid('1.23')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.float(coerce=True)).is_valid('1.23')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.float).is_valid(1)\n    False\n    \u003e\u003e\u003e dc.Checker(dc.float(min=5)).is_valid(1.23)\n    False\n    \u003e\u003e\u003e dc.Checker(dc.float(min=5)).is_valid(6.23)\n    True\n\n\n**decimal**\n\nEnsures the input value is a ``Decimal`` datatype.\n\n*Options*\n\n* coerce: True/False; Will cause the processor to attempt to coerce the value into a ``Decimal``. This allows you to accept an input of \"1.23\" and interpret it as Decimal('1.23').\n* min: Enforces a minimum value check. Defaults to ``None``, which means don't check.\n* max: Enforces a maximum value check. Defaults to ``None``, which means don't check.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.decimal).is_valid(Decimal('1.23'))\n    True\n    \u003e\u003e\u003e dc.Checker(dc.decimal).is_valid('1.23')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.decimal(coerce=True)).is_valid('1.23')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.decimal).is_valid(1.23)\n    False\n    \u003e\u003e\u003e dc.Checker(dc.decimal(min=5)).is_valid(Decimal('1.23'))\n    False\n    \u003e\u003e\u003e dc.Checker(dc.decimal(min=5)).is_valid(Decimal('6.23'))\n    True\n\n\n**string**\n\nEnsures the input value is a string datatype.\n\n*Options*\n\n* coerce: True/False; Will cause the processor to attempt to coerce the value into a string. This allows you to accept an input of 1.23 and interpret it as the string \"1.23\".\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.string).is_valid('abc')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.string).is_valid(1.23)\n    False\n    \u003e\u003e\u003e dc.Checker(dc.string(coerce=True)).is_valid(1.23)\n    True\n    \u003e\u003e\u003e dc.Checker(dc.string).is_valid(u'abc')\n    True\n\n\n**boolean**\n\nEnsures the input value is a ``bool`` datatype.\n\n*Options*\n\n* coerce: True/False; Will cause the processor to attempt to coerce the value into a ``bool``. Values that resembe \"True\"/\"Yes\"/\"Y\"/\"1\"/1/\"On\" will evaluate to True, values that resemble \"False\"/\"No\"/\"N\"/\"0\"/0/\"Off\" will evaluate to False.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.boolean).is_valid(True)\n    True\n    \u003e\u003e\u003e dc.Checker(dc.boolean).is_valid(False)\n    True\n    \u003e\u003e\u003e dc.Checker(dc.boolean).is_valid('True')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.boolean(coerce=True)).is_valid('True')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.boolean(coerce=True)).is_valid(1)\n    True\n    \u003e\u003e\u003e dc.Checker(dc.boolean(coerce=True)).is_valid(0)\n    True\n    \u003e\u003e\u003e dc.Checker(dc.boolean(coerce=True)).is_valid('foo')\n    False\n\n\n**length**\n\nEnsures that the input iterable has a length within the specified bounds. This processor can operate on anything that is an iterable; strings, lists, tuples, or anything that implements the iterable interface.\n\n*Options*\n\n* min: Enforces a minimum length check. Defaults to ``None``, which means don't check.\n* min: Enforces a maximum length check. Defaults to ``None``, which means don't check.\n* exact: Requires that the length be exactly the specified integer. Defaults to ``None``, which means don't check.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.length(min=2)).is_valid([1, 2, 3])\n    True\n    \u003e\u003e\u003e dc.Checker(dc.length(min=2)).is_valid('abc')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.length(max=2)).is_valid('abc')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.length(min=2)).is_valid(1.23)\n    False\n    \u003e\u003e\u003e dc.Checker(dc.length(exact=3)).is_valid([1, 2, 3])\n    True\n\n\n**ip**\n\nEnsures that the input value is a string representation of an IP address.\n\n*Options*\n\n* ipv4: True/False; Tells the processor to allow IPv4-style addresses. Defaults to True.\n* ipv6: True/False; Tells the processor to allow IPv6-style addresses. Defaults to True if the system supports IPv6.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.ip).is_valid('127.0.0.1')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.ip).is_valid('foo')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.ip).is_valid('::1')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.ip(ipv6=False)).is_valid('::1')\n    False\n\n\n**domain**\n\nEnsures that the input value looks like a domain.\n\n*Options*\n\n* check_dns: True/False; Tells the processor to actually perform DNS checks on the domain to determine if it is actually real. Defaults to False.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.domain).is_valid('google.com')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.domain).is_valid('googleco.m')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.domain).is_valid('foo.bar')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.domain(check_dns=True)).is_valid('foo.bar')\n    False\n\n\n**match**\n\nEnsures that the input value is a string that matches the given regular expression.\n\nThere are also a set of built-in matchers for common cases: ``alpha``, ``numeric``, and ``alphanumeric``\n\n*Options*\n\n* options: The Python regular expression flags that should be used (e.g., re.UNICODE, re.IGNORECASE, etc). Defaults to 0 (no flags).\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.match(r'^[abc]+$')).is_valid('abcabc')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.match(r'^[abc]+$')).is_valid('foo')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.match(r'^[abc]+$')).is_valid(1)\n    False\n    \u003e\u003e\u003e dc.Checker(dc.alpha).is_valid('abc')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.alpha).is_valid('123')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.numeric).is_valid('abc')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.numeric).is_valid('123')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.alphanumeric).is_valid('abc')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.alphanumeric).is_valid('123')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.alphanumeric).is_valid('abc123')\n    True\n\n\n**email**\n\nEnsures that the input value looks like an email address.\n\n*Options*\n\n* check_dns: True/False; Tells the processor to actually perform DNS checks on the domain portion of the email address to determine if the domain is actually capable of receiving email. Defaults to False.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.email).is_valid('foo@bar.com')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.email).is_valid('foo')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.email).is_valid('foo@bar@baz.com')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.email).is_valid('foo@asfdsafsasaffdsafdsafsadfdsaf.com')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.email(check_dns=True)).is_valid('foo@asfdsafsasaffdsafdsafsadfdsaf.com')\n    False\n\n\n**url**\n\nEnsures that the input value looks like a URL.\n\n*Options*\n\n* schemes: A list that tells the processor what URL schemes to limit valid data to. Defaults to ``None``, which means don't check.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.url).is_valid('http://www.google.com')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.url).is_valid('www.google.com')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.url).is_valid('foo')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.url(schemes=['http'])).is_valid('http://www.google.com')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.url(schemes=['https'])).is_valid('http://www.google.com')\n    False\n\n\n**lower**\n\nForces the input string to be all lowercase characters.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.lower).process('FooBar')\n    'foobar'\n\n\n**upper**\n\nForces the input string to be all uppercase characters.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.upper).process('FooBar')\n    'FOOBAR'\n\n\n**strip**\n\nRemoves whitespace (or specified characters) from one or both ends of a string.\n\n*Options*\n\n* left: True/False; Tells the processor to strip characters from the left end of the string. Defaults to True.\n* right: True/False; Tells the processor to strip characters from the right end of the string. Defaults to True.\n* chars: A string of characters that the processor will remove from either end of the string. Defaults to ``None``, which means all whitespace\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.strip).process('  foo  ')\n    'foo'\n    \u003e\u003e\u003e dc.Checker(dc.strip(right=False)).process('  foo  ')\n    'foo  '\n    \u003e\u003e\u003e dc.Checker(dc.strip(chars='cmowz.')).process('www.example.com')\n    'example'\n    \u003e\u003e\u003e dc.Checker(dc.strip(left=False, chars='cmowz.')).process('www.example.com')\n    'www.example'\n\n\n**title**\n\nForces the input string to be title-cased.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.title).process('foo bar')\n    'Foo Bar'\n\n\n**swapcase**\n\nForces the input to have its casing reversed so that lowercased characters become uppercased and vice-versa.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.swapcase).process('FooBar')\n    'fOObAR'\n\n\n**capitalize**\n\nForces the input string to have its first character capitalized and the rest lowercase.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.capitalize).process('FooBar')\n    'Foobar'\n\n\n**replace**\n\nPerforms a regular-expression based string replacement on the input.\n\nThere are also a set of built-in replacers for common cases: ``collapse_whitespace``\n\n*Options*\n\n* options: The Python regular expression flags that should be used (e.g., re.UNICODE, re.IGNORECASE, etc). Defaults to 0 (no flags).\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.replace(r'\\sAnd\\s', ' \u0026 ')).process('Baked Beans And Spam')\n    'Baked Beans \u0026 Spam'\n    \u003e\u003e\u003e dc.Checker(dc.replace(r'\\d+', '#')).process('a1b23c456d7890')\n    'a#b#c#d#'\n\n\n**constant**\n\nEnsures that the input value is a specific value.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.constant('foo')).is_valid('foo')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.constant('foo')).is_valid('bar')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.constant(123)).is_valid(123)\n    True\n\n\n**choice**\n\nEnsures that the input value is one of a list of acceptible values.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.choice('foo', 'bar')).is_valid('foo')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.choice('foo', 'bar')).is_valid('bar')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.choice('foo', 'bar')).is_valid('baz')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.choice(1, 2, 3)).is_valid(2)\n    True\n\n\n**required**\n\nEnsures that a value was specified (e.g., the value is not ``None``)\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.required).is_valid('foo')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.required).is_valid(None)\n    False\n\n\n**optional**\n\nIf no input value was specified (e.g., the value is ``None``), then this processor will return the specified default value.\n\nNote that if this processor returns the default value rather than the input value, then all processing will stop. No other processors specified in the chain will execute.\n\n*Options*\n\n* default: The value to return if an input value is not specified. Defaults to ``None``.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.optional(default='foo')).process(None)\n    'foo'\n    \u003e\u003e\u003e dc.Checker(dc.optional(default='foo')).process('bar')\n    'bar'\n    \u003e\u003e\u003e dc.Checker(dc.optional(default='foo'), dc.upper).process(None)\n    'foo'\n    \u003e\u003e\u003e dc.Checker(dc.optional(default='foo'), dc.upper).process('bar')\n    'BAR'\n\n\n\n**list**\n\nEnsures that the input value is a ``list``.\n\nThis processor can also apply a series of processors to each element in the ``list``.\n\n*Options*\n\n* coerce: True/False; Tells the processor to try to coerce the input value into being a ``list``. If the value is a ``tuple`` or some other iterable object, it will be turned into a ``list`` with all the same elements. Otherwise, the value is turned into a ``list`` with one element; the original input value. Defaults to False.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.list).is_valid([1,2,3])\n    True\n    \u003e\u003e\u003e dc.Checker(dc.list).is_valid('foobar')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.list).is_valid(['a','b','c'])\n    True\n    \u003e\u003e\u003e dc.Checker(dc.list(dc.integer)).is_valid(['a','b','c'])\n    False\n    \u003e\u003e\u003e dc.Checker(dc.list(dc.integer)).is_valid([1,2,3])\n    True\n    \u003e\u003e\u003e dc.Checker(dc.list(coerce=True)).is_valid('foobar')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.list(dc.upper, coerce=True)).process('foobar')\n    ['FOOBAR']\n\n\n**tuple**\n\nEnsures that the input value is a ``tuple``.\n\nThis processor can also apply a series of processors to each element in the ``tuple``.\n\n*Options*\n\n* coerce: True/False; Tells the processor to try to coerce the input value into being a ``tuple``. If the value is a ``list`` or some other iterable object, it will be turned into a ``tuple`` with all the same elements. Otherwise, the value is turned into a ``tuple`` with one element; the original input value. Defaults to False.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.tuple).is_valid((1,2,3))\n    True\n    \u003e\u003e\u003e dc.Checker(dc.tuple).is_valid('foobar')\n    False\n    \u003e\u003e\u003e dc.Checker(dc.tuple).is_valid(('a','b','c'))\n    True\n    \u003e\u003e\u003e dc.Checker(dc.tuple(dc.integer)).is_valid(('a','b','c'))\n    False\n    \u003e\u003e\u003e dc.Checker(dc.tuple(dc.integer)).is_valid((1,2,3))\n    True\n    \u003e\u003e\u003e dc.Checker(dc.tuple(coerce=True)).is_valid('foobar')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.tuple(dc.upper, coerce=True)).process('foobar')\n    ('FOOBAR',)\n\n\n**dict**\n\nEnsures that the input value is a ``dict``.\n\nThis processor can also apply a series of processors to each item in the ``dict``.\n\n*Options*\n\n* coerce: True/False; Tells the processor to try to coerce the input value into being a ``dict``. Defaults to False.\n* ignore_extra: True/False; Tells the processor to not raise errors if keys exist beyond those that are specified. Defaults to False.\n* ignore_missing: True/False; Tells the processor to not assume ``None`` for keys that are not found in the input data. Defaults to False.\n* pass_extra: True/False; Tells the processor that any extra keys found in the input data beyond those that are specified should be passed along in the results. Defaults to False, which means the extras are dropped.\n* capture_all_errors: True/False; Tells the processor to process every key in the input data and return an Exception that contains error messages for all keys that failed processing. Defaults to False, which means that the first error encountered in processing is immediately returned.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e checker = dc.Checker(dc.dict({\n    ...     'foo': [dc.required, dc.string, dc.upper],\n    ...     'bar': [dc.required, dc.integer(max=10)],\n    ...     'baz': [dc.optional(default='green'), dc.string(coerce=True), dc.lower],\n    ... }))\n    \u003e\u003e\u003e checker.process({\n    ...     'foo': 'Happy',\n    ...     'bar': 5,\n    ... })\n    {'baz': 'green', 'foo': u'HAPPY', 'bar': 5}\n    \u003e\u003e\u003e checker.process({\n    ...     'foo': 'Happy',\n    ...     'bar': 5,\n    ...     'baz': 'PURPLE!'\n    ... })\n    {'baz': u'purple!', 'foo': u'HAPPY', 'bar': 5}\n    \u003e\u003e\u003e checker.process({\n    ...     'foo': 'Turn it up',\n    ...     'bar': 11,\n    ... })\n    Traceback (most recent call last):\n      ...\n    datachecker.errors.BoundsError: Value is above the limit of 10\n\n\n**iterable**\n\nEnsures that the input data is an iterable.\n\n*Examples*\n\n::\n\n    \u003e\u003e\u003e dc.Checker(dc.iterable).is_valid([1,2,3])\n    True\n    \u003e\u003e\u003e dc.Checker(dc.iterable).is_valid((1,2,3))\n    True\n    \u003e\u003e\u003e dc.Checker(dc.iterable).is_valid('foo')\n    True\n    \u003e\u003e\u003e dc.Checker(dc.iterable).is_valid({'foo':'bar'})\n    True\n    \u003e\u003e\u003e dc.Checker(dc.iterable).is_valid(1)\n    False\n\n\nCustom Processors\n-----------------\n\nYou can implement your own processors for use in **datachecker** by simply implementing a callable that accepts at least one argument to receive the input data, and then returns the (possibly modified) data. For example:\n\n::\n\n    \u003e\u003e\u003e def reverse(data):\n    ...     return data[::-1]\n    ... \n    \u003e\u003e\u003e dc.Checker(reverse).process('foobar')\n    'raboof'\n\nTo act as a validator rather than a sanitizer, simply raise a CheckerError exception when the input data is invalid. For Example:\n\n::\n\n    \u003e\u003e\u003e def is_foo(data):\n    ...     if data != 'foo':\n    ...         raise dc.CheckerError('Not foo!')\n    ...     return data\n    ... \n    \u003e\u003e\u003e dc.Checker(is_foo).is_valid('foo')\n    True\n    \u003e\u003e\u003e dc.Checker(is_foo).is_valid('bar')\n    False\n\nIf necessary, you can also implement a function that itself returns a processor function. This is handy when you'd like to do some up-front logic or preparation that doesn't need to occur during every single invocation of your processor. To do this, you'll need to mark the generating function with a decorator. For example:\n\n::\n\n    \u003e\u003e\u003e @dc.processor\n    ... def is_twentyfive():\n    ...     twentyfive = 5 * 5\n    ...     def is_twentyfive_processor(data):\n    ...         if data != twentyfive:\n    ...             raise dc.CheckerError('Not 25!')\n    ...     return is_twentyfive_processor\n    ... \n    \u003e\u003e\u003e dc.Checker(is_twentyfive).is_valid(25)\n    True\n    \u003e\u003e\u003e dc.Checker(is_twentyfive).is_valid(26)\n    False\n\n\nLicense\n-------\n\nThe MIT License\n\nCopyright (c)2013 Clover Wireless\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjayclassless%2Fdatachecker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjayclassless%2Fdatachecker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjayclassless%2Fdatachecker/lists"}