A simple Python rule-making utlity
Project description
RuleTools
A simple Python rule-making utility
Installation
pip install ruletools
Importing
import ruletools
Usage
Just as an example we will use this code:
rules1 = RuleSet()
add_rule()
The function add_rule takes one argument: the rule you want to add to the RuleSet object. It adds the specified rule to the specified RuleSet object.
rules1.add_rule(Required()) # what Required() does will be discussed later
MaxLength()
MaxLength takes one argument: the maximum length you want the text to be. It adds the specified MaxLength rule into the specified RuleSet object. This uses add_rule to work, just like all the other rules.
rules1.add_rule(MaxLength(10))
MinLength
MinLength takes one argument: the minimum length you want the text to be. It adds the specified MaxLength rule into the specified RuleSet object.
rules1.add_rule(MinLength(2))
IncludeNumber
IncludeNumber takes no arguments. It adds the IncludeNumber rule to the specified RuleSet object, meaning the text must have numbers.
rules1.add_rule(IncludeNumber())
NoNumber
NoNumber takes no arguments. It adds the NoNumber rule into the specified RuleSet object, meaning the text cannot contain numbers.
rules1.add_rule(NoNumber())
IncludeLetters
IncludeLetters takes no arguments. It adds the IncludeLetters rule to the specified RuleSet object, meaning the text must contain letters.
rules1.add_rule(IncludeLetters())
NoLetters
NoLetters takes no arguments. It adds the NoLetters rule to the specified RuleSet object, meaning the text must not contain letters.
rules1.add_rule(NoLetters())
IncludeSpecialChar
IncludeSpecialChar takes no arguments. It adds the IncludeSpecialChar rule to the specified RuleSet object, meaning the text must contain special characters.
rules1.add_rule(IncludeSpecialCharacter())
NoSpecialChar
NoSpecialChar takes no arguments. It adds the NoSpecialChar rule to the specified RuleSet object, meaning the text must not contain special characters.
rules1.add_rule(NoSpecialChar())
RegexPattern
RegexPattern takes one argument: the regex pattern that the text needs to match. It adds the specified RegexPattern rule to the specified RuleSet object, meaning the text needs to match the specified regex pattern.
rules1.add_rule(RegexPattern(r"^\d+$"))
StartWith
StartWith takes one argument: the character(s) that the text should start with. It adds the specified StartWith rule to the specified RuleSet object, meaning the text must start with the specified character(s).
rules1.add_rule(StartWith("A"))
Endwith
EndWith takes one argument: the character(s) that the text must end with. It adds the specified EndWith rule to the specified RuleSet object, meaning the text must end with the specified character(s).
rules1.add_rule(EndWith("Z"))
Contain
Contain takes one argument: the character(s) that the text must contain. It adds the specified Contain rule to the specified RuleSet object, meaning the text must contain the specified character(s).
rules1.add_rule(Contain("B"))
Required
Required takes no arguments . It adds the Required rule to the specified RuleSet object, meaning the text cannot be empty or just spaces.
rules1.add_rule(Required())
CustomRule
CustomRule takes one argument: a function that takes one argument, the text, and returns a Boolean value. It adds the specified CustomRule rule to the specified RuleSet object, meaning the function needs to return True.
rules1.add_rule(CustomRule(lambda text: text.isupper()))
validate
validate takes one argument: the text it needs to validate against the rules provided. It checks the text provided against the rules of the specified RuleSet object. It returns a Boolean value.
if rules1.validate("hello"):
print("Yes!")
else:
print("No!")
return_error_log
return_error_log takes no arguments. It returns the reason(s) why the text did not meet the criteria.
errors = return_error_log()
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 ruletools-1.0.0.tar.gz.
File metadata
- Download URL: ruletools-1.0.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d57b9bc9ccb8a300f691c78f8ffd065d6ff233dfb07c76d23b1ae039c984fe87
|
|
| MD5 |
e50aa3d9607ff284f6931b224cc43373
|
|
| BLAKE2b-256 |
57ffdc85921ee92501ab92c6f1ab1d2645ccb1e4b5f40351c3eb85b56b1f9be6
|
File details
Details for the file ruletools-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ruletools-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ccfeca8fbaec608d1bc3c7806e95b5fb36d5b8c896ac67f1e9e17194ca1ff6e
|
|
| MD5 |
ed762b7948fb014c97368463db161bfd
|
|
| BLAKE2b-256 |
59837bf56a4a6f55e1aa3bd953dc3dc52e612a738072a6ddd11288146d0eb88b
|