github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/clients/python-wrapper/lakefs/models.py (about)

     1  """
     2  Module containing all of lakeFS data models
     3  """
     4  
     5  from __future__ import annotations
     6  
     7  from datetime import datetime
     8  from typing import List, Optional, Literal
     9  
    10  from lakefs.namedtuple import LenientNamedTuple
    11  
    12  _COMMON_PREFIX = "common_prefix"
    13  _OBJECT = "object"
    14  
    15  
    16  class Commit(LenientNamedTuple):
    17      """
    18      NamedTuple representing a lakeFS commit's properties
    19      """
    20      id: str
    21      parents: List[str]
    22      committer: str
    23      message: str
    24      creation_date: int
    25      meta_range_id: str
    26      metadata: Optional[dict[str, str]] = None
    27  
    28  
    29  class Change(LenientNamedTuple):
    30      """
    31      NamedTuple representing a diff change between two refs in lakeFS
    32      """
    33      type: Literal["added", "removed", "changed", "conflict", "prefix_changed"]
    34      path: str
    35      path_type: Literal["common_prefix", "object"]
    36      size_bytes: Optional[int]
    37  
    38      def __repr__(self):
    39          return f'Change(type="{self.type}", path="{self.path}", path_type="{self.path_type}")'
    40  
    41  
    42  class ImportStatus(LenientNamedTuple):
    43      """
    44      NamedTuple representing an ongoing import's status in lakeFS
    45      """
    46  
    47      class _Error(LenientNamedTuple):
    48          message: str
    49  
    50      completed: bool
    51      update_time: datetime
    52      ingested_objects: Optional[int]
    53      metarange_id: Optional[str]
    54      commit: Optional[Commit]
    55      error: Optional[_Error]
    56  
    57      def __init__(self, **kwargs):
    58          commit = kwargs.get("commit")
    59          if commit is not None:
    60              kwargs["commit"] = Commit(**commit)
    61  
    62          error = kwargs.get("error")
    63          if error is not None:
    64              kwargs["error"] = ImportStatus._Error(**error)
    65  
    66          super().__init__(**kwargs)
    67  
    68  
    69  class ServerStorageConfiguration(LenientNamedTuple):
    70      """
    71      Represent a lakeFS server's storage configuration
    72      """
    73      blockstore_type: str
    74      pre_sign_support: bool
    75      import_support: bool
    76      blockstore_namespace_example: str
    77      blockstore_namespace_validity_regex: str
    78      pre_sign_support_ui: bool
    79      import_validity_regex: str
    80      default_namespace_prefix: Optional[str] = None
    81  
    82  
    83  class ObjectInfo(LenientNamedTuple):
    84      """
    85      Represent a lakeFS object's stats
    86      """
    87      path: str
    88      physical_address: str
    89      checksum: str
    90      mtime: int
    91      physical_address_expiry: Optional[int] = None
    92      size_bytes: Optional[int] = None
    93      metadata: Optional[dict[str, str]] = None
    94      content_type: Optional[str] = None
    95  
    96      def __repr__(self):
    97          return f'ObjectInfo(path="{self.path}")'
    98  
    99  
   100  class CommonPrefix(LenientNamedTuple):
   101      """
   102      Represents a common prefix in lakeFS
   103      """
   104      path: str
   105  
   106      def __repr__(self):
   107          return f'CommonPrefix(path="{self.path}")'
   108  
   109  
   110  class RepositoryProperties(LenientNamedTuple):
   111      """
   112      Represent a lakeFS repository's properties
   113      """
   114      id: str
   115      creation_date: int
   116      default_branch: str
   117      storage_namespace: str