ketozhang/asdf-pydantic

Efficient registration of models to converters by delaying import until serialization

Open

#71 opened on Sep 7, 2025

 (0 comments) (0 reactions) (0 assignees)Python (0 forks)auto 404
enhancementhelp wanted

Repository metrics

Stars
 (2 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Currently, all asdf-pydantic models must be loaded into the same module where the Converter and Extension is defined since registration of the model to the converter is done dynamically via:

from asdf_pydantic import AsdfPydanticConverter
from mypackage import MyModel

converter = AsdfPydanticConverter()
converter.add_models(MyModel)

ASDF recommends delaying expensive imports in the construction of converters https://www.asdf-format.org/projects/asdf/en/latest/asdf/extending/converters.html#entry-point-performance-considerations

Overall, users should take care to avoid expensive imports during model definition, in general, regardless of ASDF. However since it is common to see behavioral methods in models relying on 3rd party (e.g., factories, adapters, CRUD), this can't always be avoided.

We may be able to provide a way for users to register the model's qualified names (i.e., package.module.object) to the converter. The challenge here is how to get the model-embedded tag and schema URIs without triggering imports. The URIs may be dynamic (e.g., requires importing the package __version__)

Contributor guide