Field¶
FieldKey
pydantic-model
¶
Bases: _Key
Field key as a sequence of string parts.
Hashable for use as dict keys in registries. Parts cannot contain forward slashes (/) or double underscores (__).
Examples:
FieldKey("a/b/c") # String format
# FieldKey(parts=['a', 'b', 'c'])
FieldKey(["a", "b", "c"]) # List format
# FieldKey(parts=['a', 'b', 'c'])
FieldKey(FieldKey(["a", "b", "c"])) # FieldKey copy
# FieldKey(parts=['a', 'b', 'c'])
FieldKey("a", "b", "c") # Variadic format
# FieldKey(parts=['a', 'b', 'c'])
Show JSON schema:
{
"description": "Field key as a sequence of string parts.\n\nHashable for use as dict keys in registries.\nParts cannot contain forward slashes (/) or double underscores (__).\n\nExamples:\n ```py\n FieldKey(\"a/b/c\") # String format\n # FieldKey(parts=['a', 'b', 'c'])\n\n FieldKey([\"a\", \"b\", \"c\"]) # List format\n # FieldKey(parts=['a', 'b', 'c'])\n\n FieldKey(FieldKey([\"a\", \"b\", \"c\"])) # FieldKey copy\n # FieldKey(parts=['a', 'b', 'c'])\n\n FieldKey(\"a\", \"b\", \"c\") # Variadic format\n # FieldKey(parts=['a', 'b', 'c'])\n ```",
"properties": {
"parts": {
"items": {
"type": "string"
},
"title": "Parts",
"type": "array"
}
},
"required": [
"parts"
],
"title": "FieldKey",
"type": "object"
}
Fields:
Validators:
-
_validate_input -
_validate_parts_content→parts
Source code in src/metaxy/models/types.py
Attributes¶
Functions¶
__lt__
¶
__le__
¶
__gt__
¶
__ge__
¶
__iter__
¶
__getitem__
¶
__contains__
¶
__reversed__
¶
__get_validators__
classmethod
¶
validate
classmethod
¶
model_dump
¶
Serialize to list format for backward compatibility.
FieldSpec
pydantic-model
¶
FieldSpec(key: CoercibleToFieldKey, code_version: str = DEFAULT_CODE_VERSION, deps: SpecialFieldDep | list[FieldDep] | None = None, *args, **kwargs: Any)
Bases: BaseModel
Show JSON schema:
{
"$defs": {
"FeatureKey": {
"description": "Feature key as a sequence of string parts.\n\nHashable for use as dict keys in registries.\nParts cannot contain forward slashes (/) or double underscores (__).\n\nExamples:\n ```py\n FeatureKey(\"a/b/c\") # String format\n # FeatureKey(parts=['a', 'b', 'c'])\n\n FeatureKey([\"a\", \"b\", \"c\"]) # List format\n # FeatureKey(parts=['a', 'b', 'c'])\n\n FeatureKey(FeatureKey([\"a\", \"b\", \"c\"])) # FeatureKey copy\n # FeatureKey(parts=['a', 'b', 'c'])\n\n FeatureKey(\"a\", \"b\", \"c\") # Variadic format\n # FeatureKey(parts=['a', 'b', 'c'])\n ```",
"properties": {
"parts": {
"items": {
"type": "string"
},
"title": "Parts",
"type": "array"
}
},
"required": [
"parts"
],
"title": "FeatureKey",
"type": "object"
},
"FieldDep": {
"properties": {
"feature": {
"$ref": "#/$defs/FeatureKey"
},
"fields": {
"anyOf": [
{
"items": {
"$ref": "#/$defs/FieldKey"
},
"type": "array"
},
{
"const": "__METAXY_ALL_DEP__",
"type": "string"
}
],
"default": "__METAXY_ALL_DEP__",
"title": "Fields"
}
},
"required": [
"feature"
],
"title": "FieldDep",
"type": "object"
},
"FieldKey": {
"description": "Field key as a sequence of string parts.\n\nHashable for use as dict keys in registries.\nParts cannot contain forward slashes (/) or double underscores (__).\n\nExamples:\n ```py\n FieldKey(\"a/b/c\") # String format\n # FieldKey(parts=['a', 'b', 'c'])\n\n FieldKey([\"a\", \"b\", \"c\"]) # List format\n # FieldKey(parts=['a', 'b', 'c'])\n\n FieldKey(FieldKey([\"a\", \"b\", \"c\"])) # FieldKey copy\n # FieldKey(parts=['a', 'b', 'c'])\n\n FieldKey(\"a\", \"b\", \"c\") # Variadic format\n # FieldKey(parts=['a', 'b', 'c'])\n ```",
"properties": {
"parts": {
"items": {
"type": "string"
},
"title": "Parts",
"type": "array"
}
},
"required": [
"parts"
],
"title": "FieldKey",
"type": "object"
},
"SpecialFieldDep": {
"enum": [
"__METAXY_ALL_DEP__"
],
"title": "SpecialFieldDep",
"type": "string"
}
},
"properties": {
"key": {
"$ref": "#/$defs/FieldKey"
},
"code_version": {
"default": "__metaxy_initial__",
"title": "Code Version",
"type": "string"
},
"deps": {
"anyOf": [
{
"$ref": "#/$defs/SpecialFieldDep"
},
{
"items": {
"$ref": "#/$defs/FieldDep"
},
"type": "array"
}
],
"title": "Deps"
}
},
"title": "FieldSpec",
"type": "object"
}
Fields:
Source code in src/metaxy/models/field.py
def __init__(
self,
key: CoercibleToFieldKey,
code_version: str = DEFAULT_CODE_VERSION,
deps: SpecialFieldDep | list[FieldDep] | None = None,
*args,
**kwargs: Any,
) -> None:
validated_key = FieldKeyAdapter.validate_python(key)
# Handle None deps - use empty list as default
if deps is None:
deps = []
super().__init__(
key=validated_key,
code_version=code_version,
deps=deps,
*args,
**kwargs,
)
Functions¶
__get_pydantic_core_schema__
classmethod
¶
Add custom validator to coerce strings to FieldSpec.
Source code in src/metaxy/models/field.py
@classmethod
def __get_pydantic_core_schema__(cls, source_type, handler):
"""Add custom validator to coerce strings to FieldSpec."""
from pydantic_core import core_schema
# Get the default schema
python_schema = handler(source_type)
# Wrap it with a before validator that converts strings
return core_schema.no_info_before_validator_function(
_validate_field_spec_from_string,
python_schema,
)
FieldDep
pydantic-model
¶
FieldDep(feature: CoercibleToFeatureKey | FeatureSpec | type[Feature], fields: list[CoercibleToFieldKey] | Literal[ALL] = ALL, *args, **kwargs)
Bases: BaseModel
Show JSON schema:
{
"$defs": {
"FeatureKey": {
"description": "Feature key as a sequence of string parts.\n\nHashable for use as dict keys in registries.\nParts cannot contain forward slashes (/) or double underscores (__).\n\nExamples:\n ```py\n FeatureKey(\"a/b/c\") # String format\n # FeatureKey(parts=['a', 'b', 'c'])\n\n FeatureKey([\"a\", \"b\", \"c\"]) # List format\n # FeatureKey(parts=['a', 'b', 'c'])\n\n FeatureKey(FeatureKey([\"a\", \"b\", \"c\"])) # FeatureKey copy\n # FeatureKey(parts=['a', 'b', 'c'])\n\n FeatureKey(\"a\", \"b\", \"c\") # Variadic format\n # FeatureKey(parts=['a', 'b', 'c'])\n ```",
"properties": {
"parts": {
"items": {
"type": "string"
},
"title": "Parts",
"type": "array"
}
},
"required": [
"parts"
],
"title": "FeatureKey",
"type": "object"
},
"FieldKey": {
"description": "Field key as a sequence of string parts.\n\nHashable for use as dict keys in registries.\nParts cannot contain forward slashes (/) or double underscores (__).\n\nExamples:\n ```py\n FieldKey(\"a/b/c\") # String format\n # FieldKey(parts=['a', 'b', 'c'])\n\n FieldKey([\"a\", \"b\", \"c\"]) # List format\n # FieldKey(parts=['a', 'b', 'c'])\n\n FieldKey(FieldKey([\"a\", \"b\", \"c\"])) # FieldKey copy\n # FieldKey(parts=['a', 'b', 'c'])\n\n FieldKey(\"a\", \"b\", \"c\") # Variadic format\n # FieldKey(parts=['a', 'b', 'c'])\n ```",
"properties": {
"parts": {
"items": {
"type": "string"
},
"title": "Parts",
"type": "array"
}
},
"required": [
"parts"
],
"title": "FieldKey",
"type": "object"
}
},
"properties": {
"feature": {
"$ref": "#/$defs/FeatureKey"
},
"fields": {
"anyOf": [
{
"items": {
"$ref": "#/$defs/FieldKey"
},
"type": "array"
},
{
"const": "__METAXY_ALL_DEP__",
"type": "string"
}
],
"default": "__METAXY_ALL_DEP__",
"title": "Fields"
}
},
"required": [
"feature"
],
"title": "FieldDep",
"type": "object"
}
Fields:
-
feature(FeatureKey) -
fields(list[FieldKey] | Literal[ALL])
Source code in src/metaxy/models/field.py
def __init__(
self,
feature: "CoercibleToFeatureKey | FeatureSpec | type[Feature]",
fields: list[CoercibleToFieldKey]
| Literal[SpecialFieldDep.ALL] = SpecialFieldDep.ALL,
*args,
**kwargs,
):
from metaxy.models.feature import Feature
from metaxy.models.feature_spec import FeatureSpec
if isinstance(feature, FeatureSpec):
feature_key = feature.key
elif isinstance(feature, type) and issubclass(feature, Feature):
feature_key = feature.spec().key
else:
feature_key = FeatureKeyAdapter.validate_python(feature)
assert isinstance(feature_key, FeatureKey)
if isinstance(fields, list):
validated_fields: Any = TypeAdapter(list[FieldKey]).validate_python(fields)
else:
validated_fields = fields # Keep the enum value as-is
super().__init__(feature=feature_key, fields=validated_fields, *args, **kwargs)