{"id":37063361,"url":"https://github.com/ketozhang/asdf-pydantic","last_synced_at":"2026-01-14T07:12:56.630Z","repository":{"id":148390199,"uuid":"614633986","full_name":"ketozhang/asdf-pydantic","owner":"ketozhang","description":"Type-validated scientific data serialization with ASDF and pydantic","archived":false,"fork":false,"pushed_at":"2025-09-06T21:40:51.000Z","size":165,"stargazers_count":2,"open_issues_count":11,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-06T23:27:16.988Z","etag":null,"topics":["advanced-scientific-data-format","asdf","astronomy","astropy","pydantic","validation"],"latest_commit_sha":null,"homepage":"https://asdf-pydantic.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ketozhang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-03-16T01:50:55.000Z","updated_at":"2025-08-19T05:29:09.000Z","dependencies_parsed_at":"2024-01-01T23:40:59.617Z","dependency_job_id":"3e2cf4fa-c222-4ec0-915a-361280fb50d1","html_url":"https://github.com/ketozhang/asdf-pydantic","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/ketozhang/asdf-pydantic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketozhang%2Fasdf-pydantic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketozhang%2Fasdf-pydantic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketozhang%2Fasdf-pydantic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketozhang%2Fasdf-pydantic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ketozhang","download_url":"https://codeload.github.com/ketozhang/asdf-pydantic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketozhang%2Fasdf-pydantic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28412687,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T05:26:33.345Z","status":"ssl_error","status_checked_at":"2026-01-14T05:21:57.251Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["advanced-scientific-data-format","asdf","astronomy","astropy","pydantic","validation"],"created_at":"2026-01-14T07:12:56.046Z","updated_at":"2026-01-14T07:12:56.619Z","avatar_url":"https://github.com/ketozhang.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# asdf-pydantic\n\n[![PyPI - Version](https://img.shields.io/pypi/v/asdf-pydantic.svg)](https://pypi.org/project/asdf-pydantic)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/asdf-pydantic.svg)](https://pypi.org/project/asdf-pydantic)\n[![Documentation Status](https://readthedocs.org/projects/asdf-pydantic/badge/?version=latest)](https://asdf-pydantic.readthedocs.io/en/latest/?badge=latest)\n\n:::{tip}\nFor v1, see [https://asdf-pydantic.readthedocs.io/en/v1/](https://asdf-pydantic.readthedocs.io/en/v1/)\n:::\n\n\u003cdiv style=\"width: 33vw; min-width: 50em; max-width: 70em; margin:auto;\"\u003e\n\nType-validated scientific data serialization with [*ASDF*](https://asdf.readthedocs.io/en/stable/) and [*Pydantic*](https://pydantic-docs.helpmanual.io/) models\n\n```py\nimport asdf\nfrom asdf_pydantic import AsdfPydanticModel\n\nclass Rectangle(AsdfPydanticModel):\n    _tag = \"asdf://asdf-pydantic/examples/tags/rectangle-1.0.0\"\n\n    width: float\n    height: float\n\n# After creating extension and install ...\n\naf = asdf.AsdfFile()\naf[\"rect\"] = Rectangle(width=1, height=1)\n```\n\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eASDF File\u003c/b\u003e\u003c/summary\u003e\n\n```py\nprint(af.dumps())\n```\n\n```yaml\n#ASDF 1.0.0\n#ASDF_STANDARD 1.5.0\n%YAML 1.1\n%TAG ! tag:stsci.edu:asdf/\n--- !core/asdf-1.1.0\nasdf_library: !core/software-1.0.0 {\n    author: The ASDF Developers,\n    homepage: 'http://github.com/asdf-format/asdf',\n    name: asdf,\n    version: 2.14.3}\nhistory:\n  extensions:\n  - !core/extension_metadata-1.0.0\n    extension_class: asdf.extension.BuiltinExtension\n    software: !core/software-1.0.0 {\n        name: asdf,\n        version: 2.14.3}\n  - !core/extension_metadata-1.0.0 {\n    extension_class: mypackage.shapes.ShapesExtension,\n    extension_uri: 'asdf://asdf-pydantic/shapes/extensions/shapes-1.0.0'}\nrect: !\u003casdf://asdf-pydantic/shapes/tags/rectangle-1.0.0\u003e {\n    height: 1.0,\n    width: 1.0}\n...\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eASDF Schema\u003c/b\u003e\u003c/summary\u003e\n\n```py\nprint(af[\"rect\"].model_asdf_schema())\n```\n\n\n```yaml\n%YAML 1.1\n---\n$schema: http://stsci.edu/schemas/asdf/asdf-schema-1.0.0\nid: asdf://asdf-pydantic/examples/tags/rectangle-1.0.0/schema\ntitle: Rectangle\ntype: object\nproperties:\n  width:\n    title: Width\n    type: number\n  height:\n    title: Height\n    type: number\nrequired:\n- width\n- height\n```\n\n\n\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eJSON Schema\u003c/b\u003e\u003c/summary\u003e\n\n```py\nprint(af[\"rect\"].model_json_schema())\n```\n\n```yaml\n{\n    \"properties\": {\n        \"width\": {\n            \"title\": \"Width\",\n            \"type\": \"number\"\n        },\n        \"height\": {\n            \"title\": \"Height\",\n            \"type\": \"number\"\n        }\n    },\n    \"required\": [\n        \"width\",\n        \"height\"\n    ],\n    \"title\": \"Rectangle\",\n    \"type\": \"object\"\n}\n```\n\n\u003c/details\u003e\n\n\u003c/div\u003e\n\n## Features\n\n- [x] Create ASDF tag from your *pydantic* models with batteries ([converters](https://asdf.readthedocs.io/en/stable/asdf/extending/converters.html)) included\n- [x] Automatically generate ASDF schemas\n- [x] Validate data models as you create them, and not only when reading and writing ASDF files\n- [x] Preserve Python types when deserializing ASDF files\n- [x] All the benefits of *pydantic* (e.g., JSON encoder, JSON schema, *pydantic* types).\n\n## Installation\n\n```sh\npip install \"asdf-pydantic\u003e=2a\"\n```\n\n## Usage\n\nDefine your data model with [`AsdfPydanticModel`](#asdf_pydantic.model.AsdfPydanticModel). For *pydantic* fans, this has\nall the features of *pydantic's* BaseModel.\n\n```py\n# mypackage/shapes.py\nfrom asdf_pydantic import AsdfPydanticModel\n\nclass Rectangle(AsdfPydanticModel):\n    _tag = \"asdf://asdf-pydantic/examples/tags/rectangle-1.0.0\"\n\n    width: Annotated[\n        u.Quantity[u.m], AsdfTag(\"tag:stsci.edu:asdf/core/unit/quantity-1.*\")\n    ]\n    height: Annotated[\n        u.Quantity[u.m], AsdfTag(\"tag:stsci.edu:asdf/core/unit/quantity-1.*\")\n    ]\n```\n\nThen create an ASDF extension with the help of the provided converter class [`AsdfPydanticConverter`](#asdf_pydantic.converter.AsdfPydanticConverter).\n\n```py\n# mypackage/extensions.py\nfrom asdf.extension import Extension\nfrom asdf_pydantic.converter import AsdfPydanticConverter\nfrom mypackage.shapes import Rectangle\n\nconverter = AsdfPydanticConverter()\nconverter.add_models(Rectangle)\n\nclass ShapesExtension(Extension):\n    extension_uri = \"asdf://asdf-pydantic/examples/extensions/shapes-1.0.0\"\n    converters = [converter]\n    tags = [*converter.tags]\n```\n\nAfter your extension is installed with either the entrypoint method or temporarily\nwith `asdf.get_config()`:\n\n```py\nimport asdf\nfrom mypackage.extensions import ShapeExtension\n\nasdf.get_config().add_extension(ShapesExtension())\n\naf = asdf.AsdfFile()\naf[\"rect\"] = Rectangle(width=1, height=1)\n\n# Write\naf.write_to(\"shapes.asdf\")\n\n# Read back and validate\nwith asdf.open(\"shapes.asdf\", \"rb\") as af:\n    print(af[\"rect\"])\n```\n\n## Read Further\n\n```{toctree}\n:maxdepth: 1\n\nconcepts/index\ntutorials/index\napidocs/index\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fketozhang%2Fasdf-pydantic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fketozhang%2Fasdf-pydantic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fketozhang%2Fasdf-pydantic/lists"}