diff --git a/README.md b/README.md index e23d424..99d644d 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,26 @@ In its essence, `zon` behaves much like `zod`. If you have used `zod`, you will > [!NOTE] > There are some differences in the public API between `zon` and `zod`. Those mostly stem from the fact that Python does not have type inference like Typescript has. There are other slight deviations between `zon` and `zod`. +### General + +#### Validate + +To validate against a schema, use `validator.validate()` + +```python +validator = zon.string() +message = validator.validate("Hello World!") # returns 'Hello World!' +``` + +Alternatively, you may use `validator.safe_validate()`. +`save_validate` will tell you whether the validation was successful, without throwing an error. Depending on the needs of your project, you can do this to handle exceptions more elegantly. + +```python +validator = zon.string() +success, message = validator.safe_validate("Hello World!") # returns (True, 'Hello World!') +``` + + ### Basic types `zon` features most of `zod`'s basic types: