Skip to content

Commit 330b5f1

Browse files
committed
Update README examples
1 parent 8b511be commit 330b5f1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Create ASDF tags with *pydantic* models.
1313
from asdf_pydantic import AsdfPydanticModel
1414

1515
class Rectangle(AsdfPydanticModel):
16+
_tag = "asdf://asdf-pydantic/examples/tags/rectangle-1.0.0"
17+
1618
width: float
1719
height: float
1820

@@ -54,7 +56,8 @@ rect: !<asdf://asdf-pydantic/shapes/tags/rectangle-1.0.0> {
5456

5557
- [x] Create ASDF tag from your *pydantic* models with batteries ([converters](https://asdf.readthedocs.io/en/stable/asdf/extending/converters.html)) included.
5658
- [x] Validates data models as you create them and not only when reading and writing ASDF files.
57-
- [x] All the cool things that comes with *pydantic* (e.g., JSON encoder, Pydantic types)
59+
- [x] Preserve Python types when deserializing ASDF files.
60+
- [x] All the cool things that comes with *pydantic* (e.g., JSON encoder, JSON schema, Pydantic types)
5861
- [ ] <span style="color: #736f73">Comes with schemas.</span>
5962

6063
## Installation
@@ -71,6 +74,8 @@ Define your data model
7174
from asdf_pydantic import AsdfPydanticModel
7275

7376
class Rectangle(AsdfPydanticModel):
77+
_tag = "asdf://asdf-pydantic/examples/tags/rectangle-1.0.0"
78+
7479
width: float
7580
height: float
7681
```
@@ -82,7 +87,7 @@ from asdf.extension import Extension
8287
from asdf_pydantic.converter import AsdfPydanticConverter
8388
from mypackage.shapes import Rectangle
8489

85-
AsdfPydanticConverter.register_models(Rectangle)
90+
AsdfPydanticConverter.add_models(Rectangle)
8691

8792
class ShapesExtension(Extension):
8893
extension_uri = "asdf://asdf-pydantic/examples/extensions/shapes-1.0.0"
@@ -97,10 +102,13 @@ Install the extension either by entry point specification or add it to
97102
import asdf
98103
from mypackage.extensions import ShapeExtension
99104

100-
asdf.get_config().register_extension(ShapeExtension)
105+
asdf.get_config().add_extension(ShapesExtension())
101106

102107
af = asdf.AsdfFile()
103108
af["rect"] = Rectangle(width=1, height=1)
109+
110+
with open("shapes.asdf", "wb") as fp:
111+
af.write_to(fp)
104112
```
105113

106114
---

asdf_pydantic/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.0"
1+
__version__ = "1.0.1"

0 commit comments

Comments
 (0)