Skip to content

upathtype

Class info

Classes

Name Children Inherits
UPath
mkdocs_mknodes.appconfig.upathtype
A Pydantic type for universal_pathlib.UPath.

    🛈 DocStrings

    Pydantic types for universal_pathlib (upath.UPath) with validation capabilities.

    This module provides a Pydantic-compatible type for upath.UPath, offering similar functionality to Pydantic's built-in Path type. It includes validators for existence checks and path type verification.

    Example
    from pydantic import BaseModel
    
    class Config(BaseModel):
        input_file: UPathFile
        output_dir: UPathDir
        temp_path: UPath
    
    # Usage
    config = Config(
        input_file="data.csv",
        output_dir="output",
        temp_path="temp/workspace"
    )
    

    FileConfig

    Bases: BaseModel

    Example configuration using UPath types.

    Source code in mkdocs_mknodes/appconfig/upathtype.py
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    class FileConfig(BaseModel):
        """Example configuration using UPath types."""
    
        input_file: UPathFile
        output_dir: UPathDir
        temp_path: UPath
    
        model_config = {
            "frozen": True,
            "extra": "forbid",
        }
    

    UPath

    A Pydantic type for universal_pathlib.UPath.

    This type handles conversion of strings and path-like objects to UPath objects, with proper serialization support. It can be used directly in Pydantic models and supports validation via the provided validator types.

    Source code in mkdocs_mknodes/appconfig/upathtype.py
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    class UPath:
        """A Pydantic type for universal_pathlib.UPath.
    
        This type handles conversion of strings and path-like objects to UPath objects,
        with proper serialization support. It can be used directly in Pydantic models
        and supports validation via the provided validator types.
        """
    
        @classmethod
        def __get_pydantic_core_schema__(
            cls,
            _source_type: Any,
            _handler: GetCoreSchemaHandler,
        ) -> CoreSchema:
            """Generate the Pydantic core schema for UPath type."""
            return core_schema.json_or_python_schema(
                json_schema=core_schema.str_schema(),
                python_schema=core_schema.union_schema([
                    core_schema.is_instance_schema(upath.UPath),
                    core_schema.chain_schema([
                        core_schema.str_schema(),
                        core_schema.no_info_plain_validator_function(_convert_to_upath),
                    ]),
                ]),
                serialization=core_schema.plain_serializer_function_ser_schema(
                    lambda x: str(x), return_schema=core_schema.str_schema(), when_used="json"
                ),
            )
    
        @classmethod
        def __get_pydantic_json_schema__(
            cls,
            _core_schema: CoreSchema,
            _handler: GetJsonSchemaHandler,
        ) -> JsonSchemaValue:
            """Generate the JSON schema for UPath type."""
            return {"type": "string", "format": "path"}
    

    __get_pydantic_core_schema__ classmethod

    __get_pydantic_core_schema__(
        _source_type: Any, _handler: GetCoreSchemaHandler
    ) -> CoreSchema
    

    Generate the Pydantic core schema for UPath type.

    Source code in mkdocs_mknodes/appconfig/upathtype.py
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    @classmethod
    def __get_pydantic_core_schema__(
        cls,
        _source_type: Any,
        _handler: GetCoreSchemaHandler,
    ) -> CoreSchema:
        """Generate the Pydantic core schema for UPath type."""
        return core_schema.json_or_python_schema(
            json_schema=core_schema.str_schema(),
            python_schema=core_schema.union_schema([
                core_schema.is_instance_schema(upath.UPath),
                core_schema.chain_schema([
                    core_schema.str_schema(),
                    core_schema.no_info_plain_validator_function(_convert_to_upath),
                ]),
            ]),
            serialization=core_schema.plain_serializer_function_ser_schema(
                lambda x: str(x), return_schema=core_schema.str_schema(), when_used="json"
            ),
        )
    

    __get_pydantic_json_schema__ classmethod

    __get_pydantic_json_schema__(
        _core_schema: CoreSchema, _handler: GetJsonSchemaHandler
    ) -> JsonSchemaValue
    

    Generate the JSON schema for UPath type.

    Source code in mkdocs_mknodes/appconfig/upathtype.py
    138
    139
    140
    141
    142
    143
    144
    145
    @classmethod
    def __get_pydantic_json_schema__(
        cls,
        _core_schema: CoreSchema,
        _handler: GetJsonSchemaHandler,
    ) -> JsonSchemaValue:
        """Generate the JSON schema for UPath type."""
        return {"type": "string", "format": "path"}