Skip to content

Commit 7d7ce80

Browse files
committed
Improve documentation
1 parent 3793c20 commit 7d7ce80

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
[![tests](https://github.com/jayqi/sortedcontainers-pydantic/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/jayqi/sortedcontainers-pydantic/actions/workflows/tests.yml?query=branch%3Amain)
66
[![codecov](https://codecov.io/gh/jayqi/sortedcontainers-pydantic/branch/main/graph/badge.svg)](https://codecov.io/gh/jayqi/sortedcontainers-pydantic)
77

8-
This package adds [Pydantic](https://docs.pydantic.dev/latest/) support to [sortedcontainers](https://github.com/grantjenks/python-sortedcontainers/), a fast, pure-Python sorted collections library.
8+
This package adds [Pydantic](https://docs.pydantic.dev/latest/) support to [sortedcontainers](https://github.com/grantjenks/python-sortedcontainers/), a fast, pure-Python library for sorted, mutable collections.
99

10-
It implements [Pydantic's special methods](https://docs.pydantic.dev/latest/concepts/types/#customizing-validation-with-__get_pydantic_core_schema__) on sortedcontainer's `SortedDict`, `SortedList`, and `SortedSet` classes so that you can use them with Pydantic's models, validation, and serialization. To use, simply import the respective class from `sortedcontainers_pydantic` instead of `sortedcontainers`.
10+
It implements [Pydantic's special methods](https://docs.pydantic.dev/latest/concepts/types/#customizing-validation-with-__get_pydantic_core_schema__) on subclasses of sortedcontainer's `SortedDict`, `SortedList`, and `SortedSet` classes so that you can use them with Pydantic's models, validation, and serialization. To use, simply import the respective class of the same name from `sortedcontainers_pydantic` instead of from `sortedcontainers`.
1111

1212
```python
1313
from pydantic import BaseModel, TypeAdapter
@@ -19,6 +19,12 @@ class MyModel(BaseModel):
1919
MyModel(sorted_list=[3, 1, 2])
2020
#> MyModel(sorted_list=SortedList([1, 2, 3]))
2121

22+
MyModel.model_validate_json('{"sorted_list": [3, 1, 2]}')
23+
#> MyModel(sorted_list=SortedList([1, 2, 3]))
24+
25+
MyModel(sorted_list=[3, 1, 2]).model_dump_json()
26+
#> '{"sorted_list":[1,2,3]}'
27+
2228
TypeAdapter(SortedList).validate_python([3, 1, 2])
2329
#> SortedList([1, 2, 3])
2430

@@ -28,6 +34,12 @@ TypeAdapter(SortedList).validate_json("[3, 1, 2]")
2834

2935
<sup>Reproducible example created by [reprexlite](https://github.com/jayqi/reprexlite) v0.5.0</sup>
3036

37+
Currently, only Pydantic V2 is supported.
38+
3139
## Installation
3240

33-
...
41+
sortedcontainers-pydantic is not yet available on PyPI. For now, install from GitHub:
42+
43+
```bash
44+
pip install sortedcontainers-pydantic@git+https://github.com/jayqi/sortedcontainers-pydantic.git
45+
```

0 commit comments

Comments
 (0)