Pydantic

Overview

The Pydantic Generator produces Pydantic flavored python dataclasses from a linkml model, with optional support for user-supplied jinja2 templates to generate alternate classes.

Docs

Command Line

gen-pydantic

Generate pydantic classes to represent a LinkML model

gen-pydantic [OPTIONS] YAMLFILE

Options

--template_file <template_file>

Optional jinja2 template to use for class generation

-f, --format <format>

Output format (default=pydantic)

Options

pydantic

--metadata, --no-metadata

Include metadata in output (default=–metadata)

--useuris, --metauris

Include metadata in output (default=–useuris)

-im, --importmap <importmap>

Import mapping file

--log_level <log_level>

Logging level (default=WARNING)

Options

CRITICAL | ERROR | WARNING | INFO | DEBUG

--mergeimports, --no-mergeimports

Merge imports into source file (default=mergeimports)

Arguments

YAMLFILE

Required argument

Code

class linkml.generators.pydanticgen.PydanticGenerator(schema: Union[str, TextIO, linkml_runtime.linkml_model.meta.SchemaDefinition], template_file: Optional[str] = None, format: str = 'pydantic', genmeta: bool = False, gen_classvars: bool = True, gen_slots: bool = True, **kwargs)[source]
serialize() None[source]

Generate output in the required format

Parameters

kwargs – Generater specific parameters

Returns

Generated output

Additional Notes

LinkML contains two Python generators. The Pydantic dataclass generator is specifically useful for FastAPI, but is newer and less full featured than the standard Python generator.