Name | pydantic-kedro JSON |
Version |
0.6.1
JSON |
| download |
home_page | |
Summary | Kedro |
upload_time | 2023-11-09 18:31:02 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.9 |
license | MIT License Copyright (c) 2023 Anatoly Makarevich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
pydantic
kedro
fsspec
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# `pydantic-kedro`
Advanced serialization for [Pydantic](https://docs.pydantic.dev/) models
via [Kedro](https://kedro.readthedocs.io/en/stable/index.html) and
[fsspec](https://filesystem-spec.readthedocs.io/en/latest/).
This package implements custom Kedro "datasets" for both "pure" and "arbitrary"
Pydantic models. You can also use it stand-alone, using Kedro just for
serializing other object types.
Please see the [documentation](https://pydantic-kedro.rtfd.io) for a tutorial
and more examples.
## Usage with Kedro
You can use the [PydanticAutoDataSet][pydantic_kedro.PydanticAutoDataSet]
or any other dataset from `pydantic-kedro` within your
[Kedro catalog](https://docs.kedro.org/en/stable/get_started/kedro_concepts.html#data-catalog)
to save your Pydantic models:
```yaml
# conf/base/catalog.yml
my_pydantic_model:
type: pydantic_kedro.PydanticAutoDataSet
filepath: folder/my_model
```
## Direct Dataset Usage
This example works for "pure", JSON-safe Pydantic models via
`PydanticJsonDataSet`:
```python
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
```
## Standalone Usage
You can also use `pydantic-kedro` as a generic saving and loading engine for
Pydantic models:
```python
from tempfile import TemporaryDirectory
from pydantic import BaseModel
from pydantic_kedro import load_model, save_model
class MyModel(BaseModel):
"""My custom model."""
name: str
# We can use any fsspec URL, so we'll make a temporary folder
with TemporaryDirectory() as tmpdir:
save_model(MyModel(name="foo"), f"{tmpdir}/my_model")
obj = load_model(f"{tmpdir}/my_model")
assert obj.name == "foo"
```
Raw data
{
"_id": null,
"home_page": "",
"name": "pydantic-kedro",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "",
"keywords": "pydantic,kedro,fsspec",
"author": "",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/46/74/2d577c2d602d0c3d4772b964b1c9932849bc03d06a44e4100e75a9853825/pydantic-kedro-0.6.1.tar.gz",
"platform": null,
"description": "# `pydantic-kedro`\n\nAdvanced serialization for [Pydantic](https://docs.pydantic.dev/) models\nvia [Kedro](https://kedro.readthedocs.io/en/stable/index.html) and\n[fsspec](https://filesystem-spec.readthedocs.io/en/latest/).\n\nThis package implements custom Kedro \"datasets\" for both \"pure\" and \"arbitrary\"\nPydantic models. You can also use it stand-alone, using Kedro just for\nserializing other object types.\n\nPlease see the [documentation](https://pydantic-kedro.rtfd.io) for a tutorial\nand more examples.\n\n## Usage with Kedro\n\nYou can use the [PydanticAutoDataSet][pydantic_kedro.PydanticAutoDataSet]\nor any other dataset from `pydantic-kedro` within your\n[Kedro catalog](https://docs.kedro.org/en/stable/get_started/kedro_concepts.html#data-catalog)\nto save your Pydantic models:\n\n```yaml\n# conf/base/catalog.yml\nmy_pydantic_model:\n type: pydantic_kedro.PydanticAutoDataSet\n filepath: folder/my_model\n```\n\n## Direct Dataset Usage\n\nThis example works for \"pure\", JSON-safe Pydantic models via\n`PydanticJsonDataSet`:\n\n```python\nfrom pydantic import BaseModel\nfrom pydantic_kedro import PydanticJsonDataSet\n\n\nclass MyPureModel(BaseModel):\n \"\"\"Your custom Pydantic model with JSON-safe fields.\"\"\"\n\n x: int\n y: str\n\n\nobj = MyPureModel(x=1, y=\"why?\")\n\n# Create an in-memory (temporary) file via `fsspec` and save it\nds = PydanticJsonDataSet(\"memory://temporary-file.json\")\nds.save(obj)\n\n# We can re-load it from the same file\nread_obj = ds.load()\nassert read_obj.x == 1\n```\n\n## Standalone Usage\n\nYou can also use `pydantic-kedro` as a generic saving and loading engine for\nPydantic models:\n\n```python\nfrom tempfile import TemporaryDirectory\n\nfrom pydantic import BaseModel\nfrom pydantic_kedro import load_model, save_model\n\nclass MyModel(BaseModel):\n \"\"\"My custom model.\"\"\"\n\n name: str\n\n# We can use any fsspec URL, so we'll make a temporary folder\nwith TemporaryDirectory() as tmpdir:\n save_model(MyModel(name=\"foo\"), f\"{tmpdir}/my_model\")\n obj = load_model(f\"{tmpdir}/my_model\")\n assert obj.name == \"foo\"\n```\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2023 Anatoly Makarevich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Kedro",
"version": "0.6.1",
"project_urls": {
"github": "https://github.com/NowanIlfideme/pydantic-kedro"
},
"split_keywords": [
"pydantic",
"kedro",
"fsspec"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c52f65e423f239ab5b95579a5cc7200b2c6d8b86f36e86260951188728058893",
"md5": "2a634f72065f6d6c78e771ef914d05ed",
"sha256": "d3ba01a20ade51f455c4f2a1fd3ca671bf58e70916fb8a97cec6e938d2eb7f42"
},
"downloads": -1,
"filename": "pydantic_kedro-0.6.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2a634f72065f6d6c78e771ef914d05ed",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 21472,
"upload_time": "2023-11-09T18:30:57",
"upload_time_iso_8601": "2023-11-09T18:30:57.978117Z",
"url": "https://files.pythonhosted.org/packages/c5/2f/65e423f239ab5b95579a5cc7200b2c6d8b86f36e86260951188728058893/pydantic_kedro-0.6.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "46742d577c2d602d0c3d4772b964b1c9932849bc03d06a44e4100e75a9853825",
"md5": "b5f65370ccad9c9ee12088fa54bf06b2",
"sha256": "1b3430827ed565d523d4a3b31bcdcf3f6cf9eb92f1ccb8bf60cc4fc9bb89e6a3"
},
"downloads": -1,
"filename": "pydantic-kedro-0.6.1.tar.gz",
"has_sig": false,
"md5_digest": "b5f65370ccad9c9ee12088fa54bf06b2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 30124,
"upload_time": "2023-11-09T18:31:02",
"upload_time_iso_8601": "2023-11-09T18:31:02.765833Z",
"url": "https://files.pythonhosted.org/packages/46/74/2d577c2d602d0c3d4772b964b1c9932849bc03d06a44e4100e75a9853825/pydantic-kedro-0.6.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-09 18:31:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "NowanIlfideme",
"github_project": "pydantic-kedro",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pydantic-kedro"
}