
Research
/Security News
Malicious npm Packages Target WhatsApp Developers with Remote Kill Switch
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Custom field validation for Python with Pydantic
PyValidX is a powerful and flexible validation library built on top of Pydantic that provides a rich set of validators for common use cases while allowing you to create custom validation logic with ease.
from pyvalidx import ValidatedModel, field_validated
from pyvalidx.core import is_required
from pyvalidx.string import is_email, is_strong_password
from pyvalidx.numeric import min_value
class User(ValidatedModel):
name: str = field_validated(is_required())
email: str = field_validated(is_required(), is_email())
password: str = field_validated(is_required(), is_strong_password())
age: int = field_validated(is_required(), min_value(18))
# This will validate automatically
try:
user = User(
name="John Doe",
email="john@example.com",
password="SecurePass123!",
age=25
)
print("User created successfully!")
except ValidationException as e:
print(f"Validation failed: {e.to_dict()}")
Install PyValidX using pip:
pip install pyvalidx
Or with poetry:
poetry add pyvalidx
Validators are functions that check if a value meets certain criteria. They return True
if valid, False
otherwise.
A Pydantic model that automatically runs custom validators on initialization and provides error handling.
A field decorator that attaches validators to model fields.
A custom exception that provides structured error information when validation fails.
is_required()
- Ensures field is not None, empty string, or empty listmin_length()
- Minimum string/list lengthmax_length()
- Maximum string/list lengthsame_as()
- Field must match another fieldrequired_if()
- Conditional requirement based on another fieldis_email()
- Valid email formatis_strong_password()
- Strong password requirementsmatches_regex()
- Custom regex pattern matchingno_whitespace()
- No spaces allowedis_phone()
- Colombian phone number formatis_positive()
- Positive numbers onlyis_integer()
- Integer type validationis_float()
- Float type validationmin_value()
- Minimum numeric valuemax_value()
- Maximum numeric valueis_date()
- Valid date formatis_future_date()
- Date must be in the futureis_past_date()
- Date must be in the pastis_today()
- Date must be todayis_dict()
- Dictionary type validationis_list()
- List type validationis_boolean()
- Boolean type validationis_in()
- Value must be in specified choicesContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.
Harrison Alonso Arroyave Gaviria
FAQs
Custom field validation
We found that pyvalidx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.