Metadata-Version: 2.1
Name: strictobject
Version: 0.0.1
Summary: Lightweight validation for python objects.
Author: leonixyz
Project-URL: Homepage, https://github.com/leonixyz/strictobject
Project-URL: Bug Tracker, https://github.com/leonixyz/strictobject/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE

# strictobject

Lightweight validation for python objects.

Examples:

1. Simple validation
    ```python
    from strictobject import StrictObject

    class A(StrictObject):
        num: int
    
    A(num=0)  # ok
    A(num=42)  # ok
    A(num="not an int")  # will throw a TypeError
    ```
2. Custom validation
    ```python
    from strictobject import StrictObject

    class B(StrictObject):
        fortytwo: Union[int|str]
        # custom validators must by named by "validate_" followed by
        # the class attribute name, and they should return a bool
        def validate_fortytwo(self, val) -> bool:
            return int(val) == 42
    
    B(num=42)  # ok
    B(num="42")  # ok
    B(num=123)  # will throw a TypeError
    ```

Works with all built-in types, and with special types `List`, `Union`, `Optional` from package `typing`.
