Skip to content

Fields

FilterField

FilterField(
    default: Any = PydanticUndefined,
    *,
    target: Optional[str] = None,
    type_: Union[FilterTypeLiteral, FilterType, None] = None,
    **field_kwargs: Any
) -> FilterFieldInfo

Create a field for objects that can be configured.

Used to provide extra information about a field.

PARAMETER DESCRIPTION
default

Default value to be passed to pydantic.Field.

TYPE: Any DEFAULT: PydanticUndefined

target

Target for filtering.

TYPE: Optional[str] DEFAULT: None

type_

Filter type.

TYPE: Union[FilterTypeLiteral, FilterType, None] DEFAULT: None

**field_kwargs

Other arguments to pass to pydantic.Field.

TYPE: Any DEFAULT: {}

Source code in pydantic_filters/filter/_fields.py
def FilterField(  # noqa: N802
        default: Any = PydanticUndefined,  # noqa: ANN401
        *,
        target: Optional[str] = None,
        type_: Union[FilterTypeLiteral, FilterType, None] = None,
        **field_kwargs: Any,  # noqa: ANN003
) -> FilterFieldInfo:
    """
    Create a field for objects that can be configured.

    Used to provide extra information about a field.

    Args:
        default: Default value to be passed to pydantic.Field.
        target: Target for filtering.
        type_: Filter type.
        **field_kwargs: Other arguments to pass to pydantic.Field.
    """

    field_kwargs["default"] = default
    if type_ is not None:
        type_ = FilterType(type_)

    return FilterFieldInfo(
        type_=type_,
        target=target,
        field_kwargs=field_kwargs,
    )

SearchField

SearchField(
    default: Any = PydanticUndefined,
    *,
    target: Sequence[str],
    type_: Union[SearchTypeLiteral, SearchType, None] = None,
    **field_kwargs: Any
) -> SearchFieldInfo

Create a field for objects that can be configured.

Used to provide extra information about a field.

PARAMETER DESCRIPTION
default

Default value to be passed to pydantic.Field.

TYPE: Any DEFAULT: PydanticUndefined

target

Target for search.

TYPE: Sequence[str]

type_

Search type.

TYPE: Union[SearchTypeLiteral, SearchType, None] DEFAULT: None

**field_kwargs

Other arguments to pass to pydantic.Field.

TYPE: Any DEFAULT: {}

Source code in pydantic_filters/filter/_fields.py
def SearchField(  # noqa: N802
        default: Any = PydanticUndefined,  # noqa: ANN401
        *,
        target: Sequence[str],
        type_: Union[SearchTypeLiteral, SearchType, None] = None,
        **field_kwargs: Any,  # noqa: ANN003
) -> SearchFieldInfo:
    """
    Create a field for objects that can be configured.

    Used to provide extra information about a field.

    Args:
        default: Default value to be passed to pydantic.Field.
        target: Target for search.
        type_: Search type.
        **field_kwargs: Other arguments to pass to pydantic.Field.
    """

    field_kwargs["default"] = default
    if type_ is not None:
        type_ = SearchType(type_)

    return SearchFieldInfo(
        type_=type_,
        target=target,
        field_kwargs=field_kwargs,
    )

FilterFieldInfo

FilterFieldInfo(
    *,
    target: Optional[str] = None,
    type_: Optional[FilterType] = None,
    is_sequence: Optional[bool] = None,
    field_kwargs: Optional[Dict[str, Any]] = None
)

Bases: BaseField

This class holds information about a filter field.

FilterFieldInfo is used for any filter field definition regardless of whether the FilterField() function is explicitly used.

Warning

You generally shouldn't be creating FilterFieldInfo directly, you'll only need to use it when accessing BaseFilter.filter_fields internals.

PARAMETER DESCRIPTION
target

Target for filtering.

TYPE: Optional[str] DEFAULT: None

type_

Filter type.

TYPE: Optional[FilterType] DEFAULT: None

is_sequence

Is the field annotated as sequence.

TYPE: Optional[bool] DEFAULT: None

field_kwargs

Other arguments to pass to pydantic.Field.

TYPE: Optional[Dict[str, Any]] DEFAULT: None

Source code in pydantic_filters/filter/_fields.py
def __init__(
        self,
        *,
        target: Optional[str] = None,
        type_: Optional[FilterType] = None,
        is_sequence: Optional[bool] = None,
        field_kwargs: Optional[Dict[str, Any]] = None,
) -> None:
    self.target = target
    self.type = type_
    self.is_sequence = is_sequence
    super().__init__(
        field_kwargs=field_kwargs,
    )

field_kwargs property

field_kwargs: Dict[str, Any]

Get arguments for pydantic.FieldInfo creating.

SearchFieldInfo

SearchFieldInfo(
    *,
    target: Sequence[str],
    type_: Optional[SearchType] = None,
    is_sequence: Optional[bool] = None,
    field_kwargs: Optional[Dict[str, Any]] = None
)

Bases: BaseField

This class holds information about a search field.

SearchFieldInfo is used for any search field definition regardless of whether the SearchField() function is explicitly used.

Warning

You generally shouldn't be creating SearchFieldInfo directly, you'll only need to use it when accessing BaseFilter.search_fields internals.

PARAMETER DESCRIPTION
target

Target for search.

TYPE: Sequence[str]

type_

Search type.

TYPE: Optional[SearchType] DEFAULT: None

is_sequence

Is the field annotated as sequence.

TYPE: Optional[bool] DEFAULT: None

field_kwargs

Other arguments to pass to pydantic.Field.

TYPE: Optional[Dict[str, Any]] DEFAULT: None

Source code in pydantic_filters/filter/_fields.py
def __init__(
        self,
        *,
        target: Sequence[str],
        type_: Optional[SearchType] = None,
        is_sequence: Optional[bool] = None,
        field_kwargs: Optional[Dict[str, Any]] = None,
) -> None:

    if not target:
        raise ValueError("Target must contain at least one value")

    self.target = target
    self.type = type_
    self.is_sequence = is_sequence
    super().__init__(
        field_kwargs=field_kwargs,
    )

field_kwargs property

field_kwargs: Dict[str, Any]

Get arguments for pydantic.FieldInfo creating.