Skip to content

Serializers

lume_services.files.serializers.image

Classes

ImageSerializer

Bases: SerializerBase

Pillow image serializer.

Functions
serialize
serialize(filename, image: Image)
Source code in lume_services/files/serializers/image.py
8
9
def serialize(self, filename, image: Image):
    image.save(filename)
deserialize classmethod
deserialize(filename) -> Image
Source code in lume_services/files/serializers/image.py
11
12
13
14
@classmethod
def deserialize(cls, filename) -> Image:

    return Image.open(filename)

lume_services.files.serializers.text

Classes

TextSerializer

Bases: SerializerBase

Functions
serialize
serialize(filename, text)
Source code in lume_services/files/serializers/text.py
5
6
7
8
def serialize(self, filename, text):

    with open(filename, "w") as f:
        f.write(text)
deserialize classmethod
deserialize(filename)
Source code in lume_services/files/serializers/text.py
10
11
12
13
14
15
16
17
18
@classmethod
def deserialize(cls, filename):

    text = ""

    with open(filename, "r") as f:
        text = f.read()

    return text

lume_services.files.serializers.yaml

Classes

YAMLSerializer

Bases: SerializerBase

Functions
serialize
serialize(filename, object: List[dict]) -> None
Source code in lume_services/files/serializers/yaml.py
 7
 8
 9
10
def serialize(self, filename, object: List[dict]) -> None:

    with open(filename, "w") as f:
        yaml.dump(object, f)
deserialize classmethod
deserialize(filename: str) -> List[dict]
Source code in lume_services/files/serializers/yaml.py
12
13
14
15
16
17
18
19
20
21
22
23
24
@classmethod
def deserialize(cls, filename: str) -> List[dict]:
    yaml_rep = None

    with open(filename, "r") as f:

        try:
            yaml_rep = yaml.safe_load(f)

        except yaml.YAMLError as exc:
            print(exc)

    return yaml_rep