ketozhang/asdf-pydantic

Efficient registration of models to converters by delaying import until serialization

Aperta

#71 aperta il 7 set 2025

 (0 commenti) (0 reazioni) (0 assegnatari)Python (0 fork)auto 404
enhancementhelp wanted

Metriche repository

Star
 (2 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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__)

Guida contributor