Skip to content

File

File

Bases: BaseClass

Attributes:

Name Type Description
id str

id of the file

name str

name of the file including the extension

Source code in furthrmind\collection\file.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class File(BaseClass):
    """
    Attributes
    ----------
    id : str
        id of the file
    name : str
        name of the file including the extension
    """

    id = ""
    name = ""

    _attr_definition = {
    }

    def __init__(self, id=None, data=None):
        super().__init__(id, data)

    @classmethod
    def get(cls, id=None):
        raise TypeError("Not implemented")

    @classmethod
    def _get_all(cls):
        raise TypeError("Not implemented")

    def download(self, folder: str, overwrite: bool = False):
        """
        Method to download a file

        Parameters
        ----------
        folder : str
            The folder where the file should be saved
        overwrite : bool, optional
            Whether to overwrite the existing file in the folder if it already exists (default is False)
        """

        from furthrmind.file_loader import FileLoader
        fl = FileLoader(self.fm.host, self.fm.api_key)

        if not os.path.isdir(folder):
            raise ValueError("Folder does not exist")
        fl.downloadFile(self.id, folder, overwrite)

    def download_bytes(self) -> BytesIO:
        """
        Method to download a file and save to BytesIO object

        Returns:
            BytesIO: The downloaded file stored as BytesIO object
        """

        from furthrmind.file_loader import FileLoader
        fl = FileLoader(self.fm.host, self.fm.api_key)

        flag, bytes_io = fl.downloadFile(self.id, bytesIO=True)
        return bytes_io

    def update_file(self, file_path: str, file_name: str = ""):
        """
        Update a file.

        Parameters
        ----------
        file_path : str
            The path to the file.
        file_name : str, optional
            The new file name. Defaults to "". If not set, the file_name is taken from the file_path.

        Raises
        ------
        ValueError
            If the file does not exist.

        """
        from furthrmind.file_loader import FileLoader
        fl = FileLoader(self.fm.host, self.fm.api_key)

        if not os.path.isfile(file_path):
            raise ValueError("File does not exist")

        fl.updateFile(self.id, file_path, file_name)

delete(id='', project_id='') classmethod

Method to delete an item. Can be called as a classmethod with providing the id to be deleted or on the instance of a class

Parameters:

Name Type Description Default
id str

The id of the resource to delete

''
project_id str

Optionally to delete an item in another project as the furthrmind sdk was initiated with

''

Returns:

Type Description
str

The id of the item

Source code in furthrmind\collection\baseclass.py
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
@classmethod
def delete(cls, id: str = "", project_id: str = "") -> str:
    """
    Method to delete an item. Can be called as a classmethod with providing the id to be deleted or on the instance
    of a class

    Parameters
    ----------
    id : str
        The id of the resource to delete
    project_id : str, optional
        Optionally to delete an item in another project as the furthrmind sdk was initiated with

    Returns
    -------
    str
        The id of the item
    """

    if isclass(cls):
        return cls._delete_class_method(id, project_id)
    else:
        self = cls
        return self._delete_instance_method(project_id)

download(folder, overwrite=False)

Method to download a file

Parameters:

Name Type Description Default
folder str

The folder where the file should be saved

required
overwrite bool

Whether to overwrite the existing file in the folder if it already exists (default is False)

False
Source code in furthrmind\collection\file.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def download(self, folder: str, overwrite: bool = False):
    """
    Method to download a file

    Parameters
    ----------
    folder : str
        The folder where the file should be saved
    overwrite : bool, optional
        Whether to overwrite the existing file in the folder if it already exists (default is False)
    """

    from furthrmind.file_loader import FileLoader
    fl = FileLoader(self.fm.host, self.fm.api_key)

    if not os.path.isdir(folder):
        raise ValueError("Folder does not exist")
    fl.downloadFile(self.id, folder, overwrite)

download_bytes()

Method to download a file and save to BytesIO object

Returns: BytesIO: The downloaded file stored as BytesIO object

Source code in furthrmind\collection\file.py
51
52
53
54
55
56
57
58
59
60
61
62
63
def download_bytes(self) -> BytesIO:
    """
    Method to download a file and save to BytesIO object

    Returns:
        BytesIO: The downloaded file stored as BytesIO object
    """

    from furthrmind.file_loader import FileLoader
    fl = FileLoader(self.fm.host, self.fm.api_key)

    flag, bytes_io = fl.downloadFile(self.id, bytesIO=True)
    return bytes_io

to_dict()

Converts the object's attributes to a dictionary representation.

Returns:

Type Description
dict

Dictionary containing the object's attributes (excluding private attributes, callable attributes, and attributes of type Furthrmind).

Source code in furthrmind\collection\baseclass.py
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
def to_dict(self):
    """
    Converts the object's attributes to a dictionary representation.

    Returns
    -------
    dict
        Dictionary containing the object's attributes (excluding private attributes, callable attributes, and attributes of type Furthrmind).
    """

    from furthrmind import Furthrmind

    data = {}
    for attr in dir(self):
        if attr.startswith("_"):
            continue
        value = getattr(self, attr)
        if callable(value):
            continue
        if isinstance(value, Furthrmind):
            continue
        data[attr] = self._convert(value)
    return data

update_file(file_path, file_name='')

Update a file.

Parameters:

Name Type Description Default
file_path str

The path to the file.

required
file_name str

The new file name. Defaults to "". If not set, the file_name is taken from the file_path.

''

Raises:

Type Description
ValueError

If the file does not exist.

Source code in furthrmind\collection\file.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def update_file(self, file_path: str, file_name: str = ""):
    """
    Update a file.

    Parameters
    ----------
    file_path : str
        The path to the file.
    file_name : str, optional
        The new file name. Defaults to "". If not set, the file_name is taken from the file_path.

    Raises
    ------
    ValueError
        If the file does not exist.

    """
    from furthrmind.file_loader import FileLoader
    fl = FileLoader(self.fm.host, self.fm.api_key)

    if not os.path.isfile(file_path):
        raise ValueError("File does not exist")

    fl.updateFile(self.id, file_path, file_name)