Janus is a modern Python library for data validation, serialization, and schema versioning. It provides developers with a flexible, performant, and extensible toolkit to handle input validation, data transformation, and API schema compatibility with ease.
Click here for the documentation
- Robust Data Validation: Includes a comprehensive set of validators for strings, numbers, dates, collections, and more.
- Nested Schema Validation: Supports complex and deeply nested data structures.
- Schema Versioning: Seamlessly handle schema evolution and data migration between API versions.
- Serialization: Convert Python objects to JSON or YAML formats with error handling.
- Custom Validators: Easily extend Janus with custom validation rules.
- Open for Personal & Commercial Use: Use Janus freely in personal and commercial projects (not for resale as a standalone product).
Install Janus via pip:
pip install janus-validation
Define a validation schema:
from janus.utils.validators import is_required, is_type, is_email
from janus.core.validator import SchemaValidator
schema = {
"name": [is_required, is_type(str)],
"email": [is_required, is_email],
"age": [is_type(int)],
}
validator = SchemaValidator(schema)
data = {"name": "Alice", "email": "[email protected]", "age": 30}
validated_data = validator.validate(data)
print("Validated Data:", validated_data)
Manage schema evolution with ease:
from janus.core.schema_versioning import SchemaVersioning
versioning = SchemaVersioning()
# Register schemas
versioning.register_schema("v1", {"name": [is_required]})
versioning.register_schema("v2", {"name": [is_required], "email": [is_email]})
# Validate data with specific schema versions
data = {"name": "Alice", "email": "[email protected]"}
validated = versioning.validate_with_version("v2", data)
print("Validated:", validated)
Convert Python objects to JSON or YAML:
from janus.core.serializer import JSONSerializer, YAMLSerializer
serializer = JSONSerializer()
json_data = serializer.serialize({"name": "Alice", "age": 30})
print("Serialized JSON:", json_data)
yaml_serializer = YAMLSerializer()
yaml_data = yaml_serializer.serialize({"name": "Alice", "age": 30})
print("Serialized YAML:", yaml_data)
Janus is free to use for both personal and commercial projects. However, Janus itself cannot be resold or distributed as a standalone product.
Developed and maintained by Altxria Inc. with contributions from a growing community of passionate developers.
If you find Janus useful, consider sponsoring us to support ongoing development and new features!