Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [push]
on: [push, pull_request]

jobs:
lint:
Expand Down
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [Unreleased]

## [3.0.0] - 2025-05-16

### Changed
- Updated contribution guidelines.
- Updated CI workflow to run on Pull Request.
- Updated README.md to include more information and examples of code usage as well as corrected some old examples.
- Added contributors to the CONTRIBUTORS file.

### Deleted
- Removed `uuid` as a dependency.

### Added
- Added explanation about chaining API to README.md.

## [2.0.1] - 2024-07-16

### Changed
Expand Down Expand Up @@ -57,7 +72,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added base source code files for the project.
- Base `README.md` file.

[unreleased]: https://github.com/Naapperas/zon/compare/v2.0.1...HEAD
[Unreleased]: https://github.com/Naapperas/zon/compare/v3.0.0...HEAD
[3.0.0]: https://github.com/Naapperas/zon/compare/v2.0.1...v3.0.0
[2.0.1]: https://github.com/Naapperas/zon/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/Naapperas/zon/compare/v1.1.0...v2.0.0
[1.1.0]: https://github.com/Naapperas/zon/compare/v1.0.0...v1.1.0
Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ Pull requests should be used to propose changes to the codebase. When creating a
- **All pull requests** should be tagged with the appropriate labels. If you are unsure about which labels to use, please use the `help wanted` label.
- **All pull requests** should (but are not strictly required to) be accompanied by a description of the alternatives considered when making the changes in the pull request.

All changes must be summarized in [CHANGELOG.md](CHANGELOG.md).

Furthermore, new contributors can add themselves to the list of contributors, present at [CONTRIBUTORS](CONTRIBUTORS).


4 changes: 3 additions & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Nuno Pereira <nunoafonso2002@gmail.com>
Nuno Pereira <nunoafonso2002@gmail.com>
cachho <admin@ch-webdev.com>
Almas Akchabayev <>
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,42 @@ 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!')
```

#### Chaining

Most validators can be chained together, just like `zod`:

```python
validator = zon.string().min(5).max(10).email()
```

This is equivalent to:

```python
validator = zon.string()
validator = validator.min(5)
validator = validator.max(10)
validator = validator.email()
```

### Basic types

`zon` features most of `zod`'s basic types:
Expand Down Expand Up @@ -147,7 +183,7 @@ zon.element_list(zon.string())
Like strings, lists also have some extra methods that check the length of the list:

```python
validator = zon.list(...)
validator = zon.element_list(...)

validator.min(5)
validator.max(10)
Expand Down Expand Up @@ -187,7 +223,7 @@ validator = zon.record({
"name": zon.string(),
"age": zon.number(),
"isAwesome": zon.boolean(),
"friends": zon.array(zon.string()),
"friends": zon.element_list(zon.string()),
"address": zon.record({
"street": zon.string(),
"city": zon.string(),
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "zon"
version = "2.0.0"
version = "3.0.0"
authors = [
{ name="Nuno Pereira", email="nunoafonso2002@gmail.com" },
]
Expand All @@ -21,8 +21,7 @@ classifiers = [
]
dependencies = [
"validators>0.28",
"typing_extensions>4.12",
"uuid==1.30"
"typing_extensions>4.12"
]

[project.optional-dependencies]
Expand Down
6 changes: 4 additions & 2 deletions zon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Why is this needed even?
from __future__ import annotations

__version__ = "2.0.0"
__version__ = "3.0.0"
__author__ = "Nuno Pereira"
__email__ = "nunoafonso2002@gmail.com"
__license__ = "MIT"
Expand Down Expand Up @@ -181,7 +181,9 @@ def _default_validate(self, data: T, ctx: ValidationContext) -> T:
)

@final
def _validate(self, data: T) -> tuple[Literal[True], T] | tuple[Literal[False], ZonError]:
def _validate(
self, data: T
) -> tuple[Literal[True], T] | tuple[Literal[False], ZonError]:
"""Validates the supplied data.

Args:
Expand Down