Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down