klotan
Description
Klotan is a Python library used to match a structure (tuples, lists, dicts) with a template. A template is made of a set of criteria.
Installation
You just have to clone this repository and install it using the command
pip install .
Or you can also install it from PyPi
pip install klotan
You can test the installation by running the following command :
python -c "import klotan; print(klotan.match.match([klotan.criteria.equals(22)], [33]).is_valid())"
which should print False
Usage
Klotan can be used to validate some form results for example
person_template = {
# The gender can be either M, F or N/A
"gender": criteria.is_in("M", "F", "N/A"),
# Expects a name starting with a capital letter, followed by 1 to 15 letters
"name": criteria.regex("[A-Z][a-z]{1,15}"),
# Jeanne Calment still holds the world record
"age": criteria.between(0, 122),
# Matches all emails
"email": criteria.is_email(),
# Optional field, matches if value is an URL
match.optional("personal_website"): criteria.is_url(),
# Matches valid IBANs
"iban": criteria.is_valid_iban(),
# Matches valid credit card numbers
"credit_card": criteria.is_valid_credit_card_number(),
# We only accept people without debts !
"amount_of_money": criteria.is_positive(),
# This criteria will accept anything
"bonus": criteria.accept(),
}
# Those are of course, fake informations
person = {
"gender": "M",
"name": "Bob",
"age": 18,
"email": "bob.dupont@gmail.com",
"personal_website": "https://bob.dupont.fr/",
"iban": "FR68 1009 6000 7018 7224 1164 C75",
"credit_card": "4929609419559701",
"bonus": lambda: 0,
}
print(match.match(person_template, person).to_string())
The code above prints the following output :
{
"gender": Criteria<is_in>("M", "F", "N/A") << ("M") => True,
"name": Criteria<regex>("[A-Z][a-z]{1,15}") << ("Bob") => True,
"age": Criteria<between>(0, 122) << (18) => True,
"email": Criteria<is_email> << ("bob.dupont@gmail.com") => True,
"personal_website": Criteria<is_url> << ("https://bob.dupont.fr/") => True,
"iban": Criteria<is_valid_iban> << ("FR68 1009 6000 7018 7224 1164 C75") => True,
"credit_card": Criteria<is_valid_credit_card_number> << ("4929609419559701") => True,
"amount_of_money": Criteria<expected>(Criteria<is_positive>, False) << (None) => False,
"bonus": Criteria<accept> << (<function <lambda> at 0x000001C4767330D0>) => True
}
Licensing
Klotan uses the MIT license, you can find more details about it here
Contributing
You can find more details about contributions here
Metadata
Release files for klotan 1.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| klotan-1.11.0-py3-none-any.whl | Python 3 | none | any | Details for klotan-1.11.0-py3-none-any.whl |
Release files / klotan-1.11.0-py3-none-any.whl
| Download URL | klotan-1.11.0-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
039c8fc3616da007cba6be659a241163222dddf5d1dfa78b719edb77475ad894
|
|
BLAKE2b-256 checksum How to use checksums |
c2a83f30bd1d55c5a1a4a0571783123271a497714b149556da40af194b70d524
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.0
|
Security for klotan 1.11.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.