Kedro
Project description
pydantic-kedro
Advanced serialization for Pydantic models via Kedro and fsspec.
This package implements custom Kedro "datasets" for both "pure" and "arbitrary" Pydantic models.
Examples
"Pure" Pydantic Models
This example works for "pure", JSON-safe Pydantic models via
PydanticJsonDataSet
:
from pydantic import BaseModel
from pydantic_kedro import PydanticJsonDataSet
class MyPureModel(BaseModel):
"""Your custom Pydantic model with JSON-safe fields."""
x: int
y: str
obj = MyPureModel(x=1, y="why?")
# Create an in-memory (temporary) file via `fsspec` and save it
ds = PydanticJsonDataSet("memory://temporary-file.json")
ds.save(obj)
# We can re-load it from the same file
read_obj = ds.load()
assert read_obj.x == 1
Note that specifying custom JSON encoders also will work.
Models with Arbitrary Types
Pydantic supports models with arbitrary types
if you specify it in the model's config.
You can't save/load these via JSON, but you can use the other dataset types,
PydanticFolderDataSet
and
PydanticZipDataSet
:
from pydantic import BaseModel
from pydantic_kedro import PydanticJsonDataSet
# TODO
class MyArbitraryModel(BaseModel):
"""Your custom Pydantic model with JSON-unsafe fields."""
x: int
y: str
# TODO
Further Reading
See the configuration...
Check out the API Reference for auto-generated docs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pydantic-kedro-0.1.1.tar.gz
.
File metadata
- Download URL: pydantic-kedro-0.1.1.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c72fdd3921e1b4eb7c93f0a8081fcc9e8ea7b435518e9d05ca3d3601d89a4028 |
|
MD5 | bd0e2e48ec09aa843728c26f013fe4d9 |
|
BLAKE2b-256 | 2780833bdc58225eb1a7de19064133385f53bfdb56a253e1f668113d28fabc7d |
File details
Details for the file pydantic_kedro-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pydantic_kedro-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bdb38bb621ee4d3bfede2f8582ef96a1e2f70643d4c3a55f33018c34046831d |
|
MD5 | 04244ae395f1cd863327539a7dc4ca70 |
|
BLAKE2b-256 | 766a94de0f34a77c64453e8e30d61470730022ca1e1e3667ff0287f1542a29fd |