inputrules


Nameinputrules JSON
Version 0.0.5 PyPI version JSON
download
home_pagehttps://github.com/alvarodeleon/inputrules
SummaryA robust Python library for validating and sanitizing input data with predefined rules and filters
upload_time2025-07-10 22:21:26
maintainerNone
docs_urlNone
authorAlvaro De Leon
requires_python>=3.6
licenseNone
keywords validation sanitization input forms json security filters
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # InputRules - Input Rules Library 

**Version 0.0.5** - Enhanced security and stability improvements

Is an Alpha version, develop in progress, do not use it in production

---

## Installation

```bash
pip install inputrules
```
| **Total** | **Last Month** | **Last Week** |
|-----------|----------------|---------------|
| [![Downloads](https://static.pepy.tech/badge/inputrules)](https://pepy.tech/project/inputrules) | [![Downloads](https://static.pepy.tech/badge/inputrules/month)](https://pepy.tech/project/inputrules) | [![Downloads](https://static.pepy.tech/badge/inputrules/week)](https://pepy.tech/project/inputrules) |

---

A robust Python library for validating and sanitizing input data from Forms, JSON, and HTTP Requests with predefined rules and filters.

## Example
```python
from inputrules import InputRules

#JSON Example
data = {
        "id":100,
        "data": {
            "name":"  Alvaro ",
            "lastname":" De Leon  ",
            "age":35,
            "email": "asdasd",
            "opt":"30",
            "parms":[
                10,20,30,40,50,60,70,80,90,100
            ],
            "phones": {
                "name":"Zaraza",
                "home":"123456",
                "cell":"123456"
            }
        }
    }
#Example of list of options
options = ['10','20','30','40','50']

o = InputRules(data)

o.rules("id","required,integer")
o.rules("data.name","required,string","trim,upper")
o.rules("data.lastname","required,string","trim,lower")
o.rules("data.age","required,integer")
o.rules("data.phone","string")
o.rules("data.email","string","b64encode")
o.rules("data.opt","options",options=options)
o.rules("data.phones.name","required,string")

if o.verify():
    print("Data is valid")
    data = o.data()
    print(data)
```

## Data Validation with InputRules

InputRules provides a powerful data validation system through the `InputRules` class. This class allows you to validate input data in a structured way and apply filters automatically.

### Importing

```python
from inputrules import InputRules, check
```

### Basic Usage

```python
# Example data
data = {
    "id": 100,
    "name": "  John  ",
    "email": "john@example.com",
    "age": 25,
    "status": "active"
}

# Create InputRules instance
validator = InputRules(data)

# Define validation rules
validator.rules("id", "required,integer")
validator.rules("name", "required,string", "trim,upper")
validator.rules("email", "required,mail")
validator.rules("age", "required,integer")
validator.rules("status", "required,options", options=["active", "inactive"])

# Validate data
if validator.verify():
    print("Data is valid")
    validated_data = validator.data()
    print(validated_data)
else:
    print("Errors found:")
    for error in validator.errors():
        print(f"- {error}")
```

### Available Validation Rules

#### Basic Rules
- `required`: Field is required
- `string`: Must be a string
- `integer`: Must be an integer
- `float`: Must be a decimal number
- `numeric`: Must be a number (integer or decimal)
- `empty`: Must be empty
- `!empty`: Must not be empty
- `none`: Must be None
- `!none`: Must not be None

#### Format Rules
- `mail`: Must be a valid email address
- `domain`: Must be a valid domain
- `ip`: Must be a valid IP address
- `uuid`: Must be a valid UUID
- `options`: Must be in a list of valid options

### Available Filters

Filters are automatically applied to data after validation:

#### Text Filters
- `trim` or `strip`: Removes whitespace from beginning and end
- `lower`: Converts to lowercase
- `upper`: Converts to uppercase
- `ucfirst`: First letter uppercase
- `ucwords`: First letter of each word uppercase

#### Conversion Filters
- `int` or `integer`: Converts to integer
- `float`: Converts to decimal
- `str` or `string`: Converts to string

#### Encoding Filters
- `base64` or `b64encode`: Encodes in base64
- `b64decode`: Decodes from base64
- `md5`: Generates MD5 hash
- `urlencode`: Encodes for URL
- `urldecode`: Decodes from URL

#### Security Filters
- `xss` or `escape`: Escapes HTML characters
- `sql`: Sanitizes SQL input (removes dangerous SQL injection patterns)
- `htmlentities`: Converts characters to HTML entities
- `htmlspecialchars`: Converts special characters to HTML entities
- `striptags`: Removes HTML tags
- `addslashes`: Escapes quotes and backslashes
- `stripslashes`: Removes backslashes

#### Format Filters
- `nl2br`: Converts line breaks to `<br>`
- `br2nl`: Converts `<br>` to line breaks
- `json`: Converts to JSON

**Note**: The `serialize` and `unserialize` filters have been removed for security reasons.

### Nested Structure Validation

`InputRules` supports validation of nested data structures using dot notation:

```python
data = {
    "user": {
        "profile": {
            "name": "  Maria  ",
            "email": "maria@example.com",
            "age": 30
        },
        "settings": {
            "theme": "dark",
            "notifications": True
        }
    }
}

validator = InputRules(data)

# Validate nested fields
validator.rules("user.profile.name", "required,string", "trim,ucfirst")
validator.rules("user.profile.email", "required,mail")
validator.rules("user.profile.age", "required,integer")
validator.rules("user.settings.theme", "required,options", options=["light", "dark"])
validator.rules("user.settings.notifications", "required")

if validator.verify():
    validated_data = validator.data()
    print(validated_data)
```

### Complete Example with Options

```python
from inputrules import InputRules

# Form data
form_data = {
    "username": "  admin  ",
    "password": "123456",
    "email": "admin@example.com",
    "role": "admin",
    "profile": {
        "first_name": "  john  ",
        "last_name": "  doe  ",
        "age": 35,
        "country": "US"
    }
}

# Valid options
role_options = ["admin", "user", "moderator"]
country_options = ["US", "CA", "UK", "DE", "FR"]

# Create validator
validator = InputRules(form_data)

# Define rules
validator.rules("username", "required,string", "trim,lower")
validator.rules("password", "required,string", "md5")
validator.rules("email", "required,mail")
validator.rules("role", "required,options", options=role_options)
validator.rules("profile.first_name", "required,string", "trim,ucfirst")
validator.rules("profile.last_name", "required,string", "trim,ucfirst")
validator.rules("profile.age", "required,integer")
validator.rules("profile.country", "required,options", options=country_options)

# Validate
if validator.verify():
    print("✓ Valid data")
    clean_data = validator.data()
    print("Processed data:", clean_data)
else:
    print("✗ Validation errors:")
    for error in validator.errors():
        print(f"  - {error}")
```

## check Class - Individual Validations

The `check` class provides static methods for validating individual values. It's useful for specific validations without needing to create a complete schema.

### Importing

```python
from inputrules import check
```

### Validation Methods

#### Type Validation
```python
# Validate if it's a string
check.string("text")        # True
check.string(123)           # False

# Validate if it's an integer
check.integer(42)           # True
check.integer(3.14)         # False

# Validate if it's a decimal
check.float(3.14)           # True
check.float(42)             # False

# Validate if it's numeric (integer or decimal)
check.numeric(42)           # True
check.numeric(3.14)         # True
check.numeric("text")       # False
```

#### State Validation
```python
# Validate if it's empty
check.empty("")             # True
check.empty(None)           # True
check.empty(0)              # True
check.empty("text")         # False

# Validate if it's None
check.none(None)            # True
check.none("")              # False

# Validate if it's NOT None
check.notnone("text")       # True
check.notnone(None)         # False
```

#### Format Validation
```python
# Validate email
check.mail("user@example.com")      # True
check.mail("invalid-email")         # False

# Validate domain
check.domain("example.com")         # True
check.domain("invalid..domain")     # False

# Validate IP
check.ip("192.168.1.1")            # True
check.ip("999.999.999.999")        # False

# Validate UUID
check.uuid("123e4567-e89b-12d3-a456-426614174000")  # True
check.uuid("invalid-uuid")                          # False
```

#### Options Validation
```python
# Validate if it's in a list of options
options = ["red", "green", "blue"]
check.options("red", options)       # True
check.options("yellow", options)    # False
```

#### Validation with Multiple Rules
```python
# Use multiple rules separated by commas
check.rules("john@example.com", "required,mail")    # True
check.rules("", "required,string")                  # False
check.rules(25, "required,integer")                 # True
check.rules("test", "required,string,!empty")       # True
```

### Data Sanitization

```python
# Sanitize SQL input
user_input = "'; DROP TABLE users; --"
safe_input = check.sanitize_sql(user_input)
print(safe_input)  # " DROP TABLE users "
```

### Practical Examples

#### Registration Form Validation
```python
from inputrules import check

def validate_registration(form_data):
    errors = []
    
    # Validate username
    if not check.rules(form_data.get('username'), 'required,string,!empty'):
        errors.append("Username is required and must be valid")
    
    # Validate email
    if not check.rules(form_data.get('email'), 'required,mail'):
        errors.append("Email must be a valid address")
    
    # Validate age
    if not check.rules(form_data.get('age'), 'required,integer'):
        errors.append("Age must be an integer")
    
    # Validate role
    valid_roles = ['admin', 'user', 'moderator']
    if not check.options(form_data.get('role'), valid_roles):
        errors.append("Role must be admin, user or moderator")
    
    return len(errors) == 0, errors

# Usage
form_data = {
    'username': 'john_doe',
    'email': 'john@example.com',
    'age': 28,
    'role': 'user'
}

is_valid, errors = validate_registration(form_data)
if is_valid:
    print("Valid form")
else:
    print("Errors:", errors)
```

#### Configuration Validation
```python
from inputrules import check

def validate_config(config):
    """Validates system configuration"""
    
    # Validate database host
    if not check.rules(config.get('db_host'), 'required,string,!empty'):
        return False, "Database host is required"
    
    # Validate port
    port = config.get('db_port')
    if not check.integer(port) or port <= 0 or port > 65535:
        return False, "Port must be an integer between 1 and 65535"
    
    # Validate admin email
    admin_email = config.get('admin_email')
    if not check.mail(admin_email):
        return False, "Admin email is not valid"
    
    # Validate log level
    log_levels = ['DEBUG', 'INFO', 'WARNING', 'ERROR']
    if not check.options(config.get('log_level'), log_levels):
        return False, "Log level must be DEBUG, INFO, WARNING or ERROR"
    
    return True, "Valid configuration"

# Usage
config = {
    'db_host': 'localhost',
    'db_port': 3306,
    'admin_email': 'admin@company.com',
    'log_level': 'INFO'
}

is_valid, message = validate_config(config)
print(message)
```

### Integration Example

```python
from inputrules import InputRules, check

# User data
user_data = {
    'name': '  John Doe  ',
    'email': 'john@example.com',
    'age': 30,
    'status': 'active'
}

# Validate data
validator = InputRules(user_data)
validator.rules("name", "required,string", "trim,ucfirst")
validator.rules("email", "required,mail")
validator.rules("age", "required,integer")
validator.rules("status", "required,options", options=["active", "inactive"])

if validator.verify():
    # Valid data, process it
    clean_data = validator.data()
    print(f"Validated data: {clean_data}")
else:
    print("Validation errors:")
    for error in validator.errors():
        print(f"- {error}")
```

## Security Improvements

### Version 0.0.5 Security Enhancements

- **Removed unsafe `serialize`/`unserialize` filters**: These filters used Python's `pickle` module which could execute arbitrary code with untrusted input
- **Enhanced SQL injection protection**: The `sql` filter now removes more dangerous patterns including:
  - DROP TABLE, DELETE FROM, INSERT INTO, UPDATE SET
  - SQL comments (-- and /* */)
  - UNION SELECT attacks
  - OR 1=1 patterns
- **Improved `addslashes` filter**: Now properly escapes single quotes, double quotes, and backslashes
- **Fixed `urlencode` filter**: Removed double encoding issue

### Empty Function Improvements

The `empty()` function now correctly handles all data types:
- Collections (lists, dicts, tuples, sets): empty if length is 0
- Booleans: `False` is considered a valid value, not empty
- Numbers: 0 and 0.0 are considered empty
- Strings: empty or whitespace-only strings are considered empty

## Bug Fixes in Version 0.0.4

- **Fixed class variable sharing**: Each `InputRules` instance now has independent variables
- **Improved error handling**: Better handling of missing keys in nested structures
- **Enhanced `getValue()` function**: Now returns `None` instead of raising exceptions
- **Fixed validation schema**: Better handling of nested structures and missing data




This documentation provides a complete guide for using both `InputRules` and the `check` class, allowing you to validate and sanitize data robustly and securely.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/alvarodeleon/inputrules",
    "name": "inputrules",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "validation, sanitization, input, forms, json, security, filters",
    "author": "Alvaro De Leon",
    "author_email": "info@alvarodeleon.com",
    "download_url": "https://files.pythonhosted.org/packages/cd/30/36ca8e5b6971ad4084ea189c2db711e72e3722a853d2b94f19d6f6dfb54b/inputrules-0.0.5.tar.gz",
    "platform": null,
    "description": "# InputRules - Input Rules Library \n\n**Version 0.0.5** - Enhanced security and stability improvements\n\nIs an Alpha version, develop in progress, do not use it in production\n\n---\n\n## Installation\n\n```bash\npip install inputrules\n```\n| **Total** | **Last Month** | **Last Week** |\n|-----------|----------------|---------------|\n| [![Downloads](https://static.pepy.tech/badge/inputrules)](https://pepy.tech/project/inputrules) | [![Downloads](https://static.pepy.tech/badge/inputrules/month)](https://pepy.tech/project/inputrules) | [![Downloads](https://static.pepy.tech/badge/inputrules/week)](https://pepy.tech/project/inputrules) |\n\n---\n\nA robust Python library for validating and sanitizing input data from Forms, JSON, and HTTP Requests with predefined rules and filters.\n\n## Example\n```python\nfrom inputrules import InputRules\n\n#JSON Example\ndata = {\n        \"id\":100,\n        \"data\": {\n            \"name\":\"  Alvaro \",\n            \"lastname\":\" De Leon  \",\n            \"age\":35,\n            \"email\": \"asdasd\",\n            \"opt\":\"30\",\n            \"parms\":[\n                10,20,30,40,50,60,70,80,90,100\n            ],\n            \"phones\": {\n                \"name\":\"Zaraza\",\n                \"home\":\"123456\",\n                \"cell\":\"123456\"\n            }\n        }\n    }\n#Example of list of options\noptions = ['10','20','30','40','50']\n\no = InputRules(data)\n\no.rules(\"id\",\"required,integer\")\no.rules(\"data.name\",\"required,string\",\"trim,upper\")\no.rules(\"data.lastname\",\"required,string\",\"trim,lower\")\no.rules(\"data.age\",\"required,integer\")\no.rules(\"data.phone\",\"string\")\no.rules(\"data.email\",\"string\",\"b64encode\")\no.rules(\"data.opt\",\"options\",options=options)\no.rules(\"data.phones.name\",\"required,string\")\n\nif o.verify():\n    print(\"Data is valid\")\n    data = o.data()\n    print(data)\n```\n\n## Data Validation with InputRules\n\nInputRules provides a powerful data validation system through the `InputRules` class. This class allows you to validate input data in a structured way and apply filters automatically.\n\n### Importing\n\n```python\nfrom inputrules import InputRules, check\n```\n\n### Basic Usage\n\n```python\n# Example data\ndata = {\n    \"id\": 100,\n    \"name\": \"  John  \",\n    \"email\": \"john@example.com\",\n    \"age\": 25,\n    \"status\": \"active\"\n}\n\n# Create InputRules instance\nvalidator = InputRules(data)\n\n# Define validation rules\nvalidator.rules(\"id\", \"required,integer\")\nvalidator.rules(\"name\", \"required,string\", \"trim,upper\")\nvalidator.rules(\"email\", \"required,mail\")\nvalidator.rules(\"age\", \"required,integer\")\nvalidator.rules(\"status\", \"required,options\", options=[\"active\", \"inactive\"])\n\n# Validate data\nif validator.verify():\n    print(\"Data is valid\")\n    validated_data = validator.data()\n    print(validated_data)\nelse:\n    print(\"Errors found:\")\n    for error in validator.errors():\n        print(f\"- {error}\")\n```\n\n### Available Validation Rules\n\n#### Basic Rules\n- `required`: Field is required\n- `string`: Must be a string\n- `integer`: Must be an integer\n- `float`: Must be a decimal number\n- `numeric`: Must be a number (integer or decimal)\n- `empty`: Must be empty\n- `!empty`: Must not be empty\n- `none`: Must be None\n- `!none`: Must not be None\n\n#### Format Rules\n- `mail`: Must be a valid email address\n- `domain`: Must be a valid domain\n- `ip`: Must be a valid IP address\n- `uuid`: Must be a valid UUID\n- `options`: Must be in a list of valid options\n\n### Available Filters\n\nFilters are automatically applied to data after validation:\n\n#### Text Filters\n- `trim` or `strip`: Removes whitespace from beginning and end\n- `lower`: Converts to lowercase\n- `upper`: Converts to uppercase\n- `ucfirst`: First letter uppercase\n- `ucwords`: First letter of each word uppercase\n\n#### Conversion Filters\n- `int` or `integer`: Converts to integer\n- `float`: Converts to decimal\n- `str` or `string`: Converts to string\n\n#### Encoding Filters\n- `base64` or `b64encode`: Encodes in base64\n- `b64decode`: Decodes from base64\n- `md5`: Generates MD5 hash\n- `urlencode`: Encodes for URL\n- `urldecode`: Decodes from URL\n\n#### Security Filters\n- `xss` or `escape`: Escapes HTML characters\n- `sql`: Sanitizes SQL input (removes dangerous SQL injection patterns)\n- `htmlentities`: Converts characters to HTML entities\n- `htmlspecialchars`: Converts special characters to HTML entities\n- `striptags`: Removes HTML tags\n- `addslashes`: Escapes quotes and backslashes\n- `stripslashes`: Removes backslashes\n\n#### Format Filters\n- `nl2br`: Converts line breaks to `<br>`\n- `br2nl`: Converts `<br>` to line breaks\n- `json`: Converts to JSON\n\n**Note**: The `serialize` and `unserialize` filters have been removed for security reasons.\n\n### Nested Structure Validation\n\n`InputRules` supports validation of nested data structures using dot notation:\n\n```python\ndata = {\n    \"user\": {\n        \"profile\": {\n            \"name\": \"  Maria  \",\n            \"email\": \"maria@example.com\",\n            \"age\": 30\n        },\n        \"settings\": {\n            \"theme\": \"dark\",\n            \"notifications\": True\n        }\n    }\n}\n\nvalidator = InputRules(data)\n\n# Validate nested fields\nvalidator.rules(\"user.profile.name\", \"required,string\", \"trim,ucfirst\")\nvalidator.rules(\"user.profile.email\", \"required,mail\")\nvalidator.rules(\"user.profile.age\", \"required,integer\")\nvalidator.rules(\"user.settings.theme\", \"required,options\", options=[\"light\", \"dark\"])\nvalidator.rules(\"user.settings.notifications\", \"required\")\n\nif validator.verify():\n    validated_data = validator.data()\n    print(validated_data)\n```\n\n### Complete Example with Options\n\n```python\nfrom inputrules import InputRules\n\n# Form data\nform_data = {\n    \"username\": \"  admin  \",\n    \"password\": \"123456\",\n    \"email\": \"admin@example.com\",\n    \"role\": \"admin\",\n    \"profile\": {\n        \"first_name\": \"  john  \",\n        \"last_name\": \"  doe  \",\n        \"age\": 35,\n        \"country\": \"US\"\n    }\n}\n\n# Valid options\nrole_options = [\"admin\", \"user\", \"moderator\"]\ncountry_options = [\"US\", \"CA\", \"UK\", \"DE\", \"FR\"]\n\n# Create validator\nvalidator = InputRules(form_data)\n\n# Define rules\nvalidator.rules(\"username\", \"required,string\", \"trim,lower\")\nvalidator.rules(\"password\", \"required,string\", \"md5\")\nvalidator.rules(\"email\", \"required,mail\")\nvalidator.rules(\"role\", \"required,options\", options=role_options)\nvalidator.rules(\"profile.first_name\", \"required,string\", \"trim,ucfirst\")\nvalidator.rules(\"profile.last_name\", \"required,string\", \"trim,ucfirst\")\nvalidator.rules(\"profile.age\", \"required,integer\")\nvalidator.rules(\"profile.country\", \"required,options\", options=country_options)\n\n# Validate\nif validator.verify():\n    print(\"\u2713 Valid data\")\n    clean_data = validator.data()\n    print(\"Processed data:\", clean_data)\nelse:\n    print(\"\u2717 Validation errors:\")\n    for error in validator.errors():\n        print(f\"  - {error}\")\n```\n\n## check Class - Individual Validations\n\nThe `check` class provides static methods for validating individual values. It's useful for specific validations without needing to create a complete schema.\n\n### Importing\n\n```python\nfrom inputrules import check\n```\n\n### Validation Methods\n\n#### Type Validation\n```python\n# Validate if it's a string\ncheck.string(\"text\")        # True\ncheck.string(123)           # False\n\n# Validate if it's an integer\ncheck.integer(42)           # True\ncheck.integer(3.14)         # False\n\n# Validate if it's a decimal\ncheck.float(3.14)           # True\ncheck.float(42)             # False\n\n# Validate if it's numeric (integer or decimal)\ncheck.numeric(42)           # True\ncheck.numeric(3.14)         # True\ncheck.numeric(\"text\")       # False\n```\n\n#### State Validation\n```python\n# Validate if it's empty\ncheck.empty(\"\")             # True\ncheck.empty(None)           # True\ncheck.empty(0)              # True\ncheck.empty(\"text\")         # False\n\n# Validate if it's None\ncheck.none(None)            # True\ncheck.none(\"\")              # False\n\n# Validate if it's NOT None\ncheck.notnone(\"text\")       # True\ncheck.notnone(None)         # False\n```\n\n#### Format Validation\n```python\n# Validate email\ncheck.mail(\"user@example.com\")      # True\ncheck.mail(\"invalid-email\")         # False\n\n# Validate domain\ncheck.domain(\"example.com\")         # True\ncheck.domain(\"invalid..domain\")     # False\n\n# Validate IP\ncheck.ip(\"192.168.1.1\")            # True\ncheck.ip(\"999.999.999.999\")        # False\n\n# Validate UUID\ncheck.uuid(\"123e4567-e89b-12d3-a456-426614174000\")  # True\ncheck.uuid(\"invalid-uuid\")                          # False\n```\n\n#### Options Validation\n```python\n# Validate if it's in a list of options\noptions = [\"red\", \"green\", \"blue\"]\ncheck.options(\"red\", options)       # True\ncheck.options(\"yellow\", options)    # False\n```\n\n#### Validation with Multiple Rules\n```python\n# Use multiple rules separated by commas\ncheck.rules(\"john@example.com\", \"required,mail\")    # True\ncheck.rules(\"\", \"required,string\")                  # False\ncheck.rules(25, \"required,integer\")                 # True\ncheck.rules(\"test\", \"required,string,!empty\")       # True\n```\n\n### Data Sanitization\n\n```python\n# Sanitize SQL input\nuser_input = \"'; DROP TABLE users; --\"\nsafe_input = check.sanitize_sql(user_input)\nprint(safe_input)  # \" DROP TABLE users \"\n```\n\n### Practical Examples\n\n#### Registration Form Validation\n```python\nfrom inputrules import check\n\ndef validate_registration(form_data):\n    errors = []\n    \n    # Validate username\n    if not check.rules(form_data.get('username'), 'required,string,!empty'):\n        errors.append(\"Username is required and must be valid\")\n    \n    # Validate email\n    if not check.rules(form_data.get('email'), 'required,mail'):\n        errors.append(\"Email must be a valid address\")\n    \n    # Validate age\n    if not check.rules(form_data.get('age'), 'required,integer'):\n        errors.append(\"Age must be an integer\")\n    \n    # Validate role\n    valid_roles = ['admin', 'user', 'moderator']\n    if not check.options(form_data.get('role'), valid_roles):\n        errors.append(\"Role must be admin, user or moderator\")\n    \n    return len(errors) == 0, errors\n\n# Usage\nform_data = {\n    'username': 'john_doe',\n    'email': 'john@example.com',\n    'age': 28,\n    'role': 'user'\n}\n\nis_valid, errors = validate_registration(form_data)\nif is_valid:\n    print(\"Valid form\")\nelse:\n    print(\"Errors:\", errors)\n```\n\n#### Configuration Validation\n```python\nfrom inputrules import check\n\ndef validate_config(config):\n    \"\"\"Validates system configuration\"\"\"\n    \n    # Validate database host\n    if not check.rules(config.get('db_host'), 'required,string,!empty'):\n        return False, \"Database host is required\"\n    \n    # Validate port\n    port = config.get('db_port')\n    if not check.integer(port) or port <= 0 or port > 65535:\n        return False, \"Port must be an integer between 1 and 65535\"\n    \n    # Validate admin email\n    admin_email = config.get('admin_email')\n    if not check.mail(admin_email):\n        return False, \"Admin email is not valid\"\n    \n    # Validate log level\n    log_levels = ['DEBUG', 'INFO', 'WARNING', 'ERROR']\n    if not check.options(config.get('log_level'), log_levels):\n        return False, \"Log level must be DEBUG, INFO, WARNING or ERROR\"\n    \n    return True, \"Valid configuration\"\n\n# Usage\nconfig = {\n    'db_host': 'localhost',\n    'db_port': 3306,\n    'admin_email': 'admin@company.com',\n    'log_level': 'INFO'\n}\n\nis_valid, message = validate_config(config)\nprint(message)\n```\n\n### Integration Example\n\n```python\nfrom inputrules import InputRules, check\n\n# User data\nuser_data = {\n    'name': '  John Doe  ',\n    'email': 'john@example.com',\n    'age': 30,\n    'status': 'active'\n}\n\n# Validate data\nvalidator = InputRules(user_data)\nvalidator.rules(\"name\", \"required,string\", \"trim,ucfirst\")\nvalidator.rules(\"email\", \"required,mail\")\nvalidator.rules(\"age\", \"required,integer\")\nvalidator.rules(\"status\", \"required,options\", options=[\"active\", \"inactive\"])\n\nif validator.verify():\n    # Valid data, process it\n    clean_data = validator.data()\n    print(f\"Validated data: {clean_data}\")\nelse:\n    print(\"Validation errors:\")\n    for error in validator.errors():\n        print(f\"- {error}\")\n```\n\n## Security Improvements\n\n### Version 0.0.5 Security Enhancements\n\n- **Removed unsafe `serialize`/`unserialize` filters**: These filters used Python's `pickle` module which could execute arbitrary code with untrusted input\n- **Enhanced SQL injection protection**: The `sql` filter now removes more dangerous patterns including:\n  - DROP TABLE, DELETE FROM, INSERT INTO, UPDATE SET\n  - SQL comments (-- and /* */)\n  - UNION SELECT attacks\n  - OR 1=1 patterns\n- **Improved `addslashes` filter**: Now properly escapes single quotes, double quotes, and backslashes\n- **Fixed `urlencode` filter**: Removed double encoding issue\n\n### Empty Function Improvements\n\nThe `empty()` function now correctly handles all data types:\n- Collections (lists, dicts, tuples, sets): empty if length is 0\n- Booleans: `False` is considered a valid value, not empty\n- Numbers: 0 and 0.0 are considered empty\n- Strings: empty or whitespace-only strings are considered empty\n\n## Bug Fixes in Version 0.0.4\n\n- **Fixed class variable sharing**: Each `InputRules` instance now has independent variables\n- **Improved error handling**: Better handling of missing keys in nested structures\n- **Enhanced `getValue()` function**: Now returns `None` instead of raising exceptions\n- **Fixed validation schema**: Better handling of nested structures and missing data\n\n\n\n\nThis documentation provides a complete guide for using both `InputRules` and the `check` class, allowing you to validate and sanitize data robustly and securely.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A robust Python library for validating and sanitizing input data with predefined rules and filters",
    "version": "0.0.5",
    "project_urls": {
        "Homepage": "https://github.com/alvarodeleon/inputrules"
    },
    "split_keywords": [
        "validation",
        " sanitization",
        " input",
        " forms",
        " json",
        " security",
        " filters"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ff71995c0d0d88a5bf8b64328b79599abda7377271ce0c70196b8f208cec4d8f",
                "md5": "072859e7ba7112d0d0f53c2bab849c52",
                "sha256": "1d122342f0f23d6a501ee2dca26c36cfa075c0eeafcffb4e87360862dba8b00e"
            },
            "downloads": -1,
            "filename": "inputrules-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "072859e7ba7112d0d0f53c2bab849c52",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 9188,
            "upload_time": "2025-07-10T22:21:25",
            "upload_time_iso_8601": "2025-07-10T22:21:25.065180Z",
            "url": "https://files.pythonhosted.org/packages/ff/71/995c0d0d88a5bf8b64328b79599abda7377271ce0c70196b8f208cec4d8f/inputrules-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "cd3036ca8e5b6971ad4084ea189c2db711e72e3722a853d2b94f19d6f6dfb54b",
                "md5": "52a9894531157fb2b0596cf2c09c721c",
                "sha256": "9775410c4fe5a15b1b67ff4689e2bf21efe2d692cacc92ca25f9c2fa1afe49f5"
            },
            "downloads": -1,
            "filename": "inputrules-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "52a9894531157fb2b0596cf2c09c721c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 18589,
            "upload_time": "2025-07-10T22:21:26",
            "upload_time_iso_8601": "2025-07-10T22:21:26.622268Z",
            "url": "https://files.pythonhosted.org/packages/cd/30/36ca8e5b6971ad4084ea189c2db711e72e3722a853d2b94f19d6f6dfb54b/inputrules-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-10 22:21:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alvarodeleon",
    "github_project": "inputrules",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "inputrules"
}
        
Elapsed time: 0.47688s