Skip to content

Meta

Representation of the “meta.xml” part.

Classes:

Name Description
Meta

Representation of the “meta.xml” part.

Attributes:

Name Type Description
GENERATOR

GENERATOR module-attribute

GENERATOR = f'odfdo {__version__}'

Meta

Bases: XmlPart, DcCreatorMixin, DcDateMixin

Representation of the “meta.xml” part.

Methods:

Name Description
__init__

Initialize the Meta XML part.

as_dict

Return the metadata of the document as a Python dict.

as_json

Return the metadata of the document as a JSON string.

as_text

Return meta information as text, with some formatting for

clear_user_defined_metadata

Remove all user-defined metadata fields from the document.

delete_user_defined_metadata_of_name

Delete all user-defined metadata fields with a specific name.

from_dict

Set the metadata of the document from a Python dict.

get_auto_reload

Get the MetaAutoReload “meta:auto-reload” element or None.

get_creation_date

Get the creation date of the document.

get_description

Get the description of the document. Also known as comments.

get_editing_cycles

Get the number of times the document was edited, as reported by the

get_editing_duration

Get the time the document was edited, as reported by the generator.

get_generator

Get the signature of the software that generated this document.

get_hyperlink_behaviour

Get the MetaHyperlinkBehaviour “meta:hyperlink-behaviour” element or

get_initial_creator

Get the first creator of the document.

get_keywords

Get the keywords of the document. Return the field as-is, without

get_language

Get the default language of the document BUT only from the metadata,

get_statistic

Get the statistics about a document, “meta:document-statistic” tag.

get_subject

Get the subject of the document.

get_template

Get the MetaTemplate “meta:template” element or None.

get_title

Get the title of the document.

get_user_defined_metadata

Get all additional user-defined metadata for a document.

get_user_defined_metadata_of_name

Return the content of the user defined metadata of that name. Return

set_auto_reload

Set or replace the meta:auto-reload element.

set_creation_date

Set the creation date of the document.

set_description

Set the description of the document. Also known as comments.

set_editing_cycles

Set the number of times the document was edited.

set_editing_duration

Set the time the document was edited.

set_generator

Set the signature of the software that generated this document.

set_generator_default

Set the signature of the software that generated this document to

set_hyperlink_behaviour

Set or replace the meta:hyperlink-behaviour element.

set_initial_creator

Set the first creator of the document.

set_keywords

Set the keywords of the document. Although the name is plural, a str

set_language

Set the default language of the document BUT only in the metadata,

set_statistic

Set the statistics about a document, “meta:document-statistic” tag.

set_subject

Set the subject of the document.

set_template

Set or replace the meta:template element.

set_title

Set the title of the document.

set_user_defined_metadata

Set a user defined metadata of that name and value.

strip

Strip metadata to their minimal content.

Attributes:

Name Type Description
auto_reload MetaAutoReload | None

Get the MetaAutoReload “meta:auto-reload” element or None.

creation_date datetime | None

Get or set the date and time when a document was created

description str | None

Get or set the description of a document .

editing_cycles int | None

Get or set the number of times a document has been edited

editing_duration timedelta | None

Get or set the total time spent editing a document <meta:editing-

generator str | None

Get or set the signature of the software that generated this

get_comments
get_meta_body
hyperlink_behaviour MetaHyperlinkBehaviour | None

Get the MetaHyperlinkBehaviour “meta:hyperlink-behaviour” element or

initial_creator str | None

Get or set the initial creator of a document .

keyword str | None

Get or set some keyword(s) keyword pertaining to a document

keywords
language str | None

Get or set the default language of the document BUT only in the

meta_body Metadata

Return the body of the “meta.xml” part.

odf_office_version str

Return the “office:version” value of the document.

print_date datetime | None

Get or set the date and time when a document when a document was

printed_by str | None

Get or set the name of the last person who printed a document.

set_comments
statistic dict[str, int] | None

Get or set the statistics about a document, “meta:document-

subject str | None

Get or set the subject of a document .

template MetaTemplate | None

Get the MetaTemplate “meta:template” element or None.

title str | None

Get or set the title of the document .

user_defined_metadata dict[str, Decimal | datetime | date | timedelta | bool | str]

Get or set all additional user-defined metadata for a document.

Source code in odfdo/meta.py
  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
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 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
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
class Meta(XmlPart, DcCreatorMixin, DcDateMixin):
    """Representation of the "meta.xml" part."""

    def __init__(self, *args: Any, **kwargs: Any) -> None:
        """Initialize the Meta XML part.

        This represents the `meta.xml` file within an ODF document, containing
        various document metadata.

        Args:
            *args: Positional arguments passed to the parent `XmlPart` constructor.
            **kwargs: Keyword arguments passed to the parent `XmlPart` constructor.
        """
        super().__init__(*args, **kwargs)
        self._generator_modified: bool = False

    def _get_body(self) -> Metadata:
        """Internal method to get the root `office:meta` element.

        Returns:
            Metadata: The `office:meta` element.
        """
        return self.get_element("//office:meta")  # type: ignore[return-value]

    get_meta_body = _get_body

    @property
    def meta_body(self) -> Metadata:
        """Return the body of the "meta.xml" part."""
        return self._get_body()

    @property
    def odf_office_version(self) -> str:
        """Return the "office:version" value of the document."""
        odm = self.get_element("//office:document-meta")
        # "office:version" sould be always present
        if odm:
            return odm.get_attribute_string("office:version") or ""
        return ""  # pragma: nocover

    def get_title(self) -> str | None:
        """Get the title of the document.

        This is not the first heading but the title metadata.

        (Also available as "self.title" property.)

        Returns:
            str | None: The title string, or None if inexistent.
        """
        element = self.get_element("//dc:title")
        if element is None:
            return None
        return element.text

    def set_title(self, title: str) -> None:
        """Set the title of the document.

        This is not the first heading but the title metadata.

        (Also available as "self.title" property.)

        Args:
            title: The title string to set.
        """
        element = self.get_element("//dc:title")
        if element is None:
            element = Element.from_tag("dc:title")
            self.body.append(element)
        element.text = title

    @property
    def title(self) -> str | None:
        """Get or set the title of the document <dc:title>.

        Returns: str (or None if inexistent)
        """
        return self.get_title()

    @title.setter
    def title(self, title: str) -> None:
        return self.set_title(title)

    def get_description(self) -> str | None:
        """Get the description of the document. Also known as comments.

        (Also available as "self.description" property.)

        Returns:
            str | None: The description string, or None if inexistent.
        """
        element = self.get_element("//dc:description")
        if element is None:
            return None
        return element.text

    # As named in OOo
    get_comments = get_description

    def set_description(self, description: str) -> None:
        """Set the description of the document. Also known as comments.

        (Also available as "self.description" property.)

        Args:
            description: The description string to set.
        """
        element = self.get_element("//dc:description")
        if element is None:
            element = Element.from_tag("dc:description")
            self.body.append(element)
        element.text = description

    set_comments = set_description

    @property
    def description(self) -> str | None:
        """Get or set the description of a document <dc:description>.

        Returns: str (or None if inexistent)
        """
        return self.get_description()

    @description.setter
    def description(self, description: str) -> None:
        return self.set_description(description)

    def get_subject(self) -> str | None:
        """Get the subject of the document.

        (Also available as "self.subject" property.)

        Returns:
            str | None: The subject string, or None if inexistent.
        """
        element = self.get_element("//dc:subject")
        if element is None:
            return None
        return element.text

    def set_subject(self, subject: str) -> None:
        """Set the subject of the document.

        (Also available as "self.subject" property.)

        Args:
            subject: The subject string to set.
        """
        element = self.get_element("//dc:subject")
        if element is None:
            element = Element.from_tag("dc:subject")
            self.body.append(element)
        element.text = subject

    @property
    def subject(self) -> str | None:
        """Get or set the subject of a document <dc:subject>.

        Returns: str (or None if inexistent)
        """
        return self.get_subject()

    @subject.setter
    def subject(self, subject: str) -> None:
        return self.set_subject(subject)

    def get_language(self) -> str | None:
        """Get the default language of the document BUT only from the metadata,
        "dc:language".

        Prefer the Document.get_language() function.

        (Also available as "self.language" property.)

        Returns:
            str | None: The language string, or None if inexistent.

        Example::

            >>> document.meta.get_language()
            fr-FR
        """
        element = self.get_element("//dc:language")
        if element is None:
            return None
        return element.text

    def set_language(self, language: str) -> None:
        """Set the default language of the document BUT only in the metadata,
        "dc:language".

        To set globally the default language, prefer the
        Document.set_language() function.

        (Also available as "self.language" property.)

        Args:
            language: The language string to set.

        Example::

            >>> document.meta.set_language('fr-FR')
        """
        language = str(language)
        if not is_RFC3066(language):
            raise TypeError(
                'Language must be "xx" lang or "xx-YY" lang-COUNTRY code (RFC3066)'
            )
        element = self.get_element("//dc:language")
        if element is None:
            element = Element.from_tag("dc:language")
            self.body.append(element)
        element.text = language

    @property
    def language(self) -> str | None:
        """Get or set the default language of the document BUT only in the
        metadata, "dc:language".

        To set globally the default language, prefer the
        Document.language property.

        Returns: str (or None if inexistent)
        """
        return self.get_language()

    @language.setter
    def language(self, language: str) -> None:
        return self.set_language(language)

    def get_creation_date(self) -> datetime | None:
        """Get the creation date of the document.

        (Also available as "self.creation_date" property.)

        Returns:
            datetime | None: The creation date as a datetime object, or None if inexistent.
        """
        element = self.get_element("//meta:creation-date")
        if element is None:
            return None
        creation_date = element.text
        return DateTime.decode(creation_date)

    def set_creation_date(self, date: datetime | None = None) -> None:
        """Set the creation date of the document.

        If provided datetime is None, use current time.

        (Also available as "self.creation_date" property.)

        Args:
            date: The datetime object to set as the creation date.
        """
        element = self.get_element("//meta:creation-date")
        if element is None:
            element = Element.from_tag("meta:creation-date")
            self.body.append(element)
        if date is None:
            date = datetime.now()
        element.text = DateTime.encode(date)

    @property
    def creation_date(self) -> datetime | None:
        """Get or set the date and time when a document was created
        <meta:creation-date>.

        If provided datetime is None, use current time.

        Returns: datetime (or None if inexistent)
        """
        return self.get_creation_date()

    @creation_date.setter
    def creation_date(self, date: datetime | None = None) -> None:
        return self.set_creation_date(date)

    @property
    def print_date(self) -> datetime | None:
        """Get or set the date and time when a document when a document was
        last printed <meta:print-date>

        If provided datetime is None, use current time.

        Returns:
            datetime | None: The print date as a datetime object, or None if inexistent.
        """
        element = self.get_element("//meta:print-date")
        if element is None:
            return None
        date = element.text
        return DateTime.decode(date)

    @print_date.setter
    def print_date(self, date: datetime | None = None) -> None:
        element = self.get_element("//meta:print-date")
        if element is None:
            element = Element.from_tag("meta:print-date")
            self.body.append(element)
        if date is None:
            date = datetime.now()
        element.text = DateTime.encode(date)

    def get_template(self) -> MetaTemplate | None:
        """Get the MetaTemplate "meta:template" element or None.

        Returns:
            A MetaTemplate instance or None.
        """
        element: MetaTemplate | None = self.get_element("//meta:template")  # type: ignore[assignment]
        return element

    @property
    def template(self) -> MetaTemplate | None:
        """Get the MetaTemplate "meta:template" element or None.

        Returns:
            A MetaTemplate instance or None.
        """
        return self.get_template()

    def set_template(
        self,
        date: datetime | None = None,
        href: str = "",
        title: str = "",
    ) -> None:
        """Set or replace the `meta:template` element.

        This specifies the document template used to create the current document.
        Any existing `meta:template` element will be removed.

        Args:
            date: The date and time when the template was used.
            href: The URI for the document template (XLink).
            title: The title of the document template (XLink).
        """
        template = MetaTemplate(date=date, href=href, title=title)
        current = self.template
        if isinstance(current, MetaTemplate):
            current.delete()
        self.body.append(template)

    def get_auto_reload(self) -> MetaAutoReload | None:
        """Get the MetaAutoReload "meta:auto-reload" element or None.

        Returns:
            A MetaAutoReload instance or None.
        """
        element: MetaAutoReload | None = self.get_element("//meta:auto-reload")  # type: ignore[assignment]
        return element

    @property
    def auto_reload(self) -> MetaAutoReload | None:
        """Get the MetaAutoReload "meta:auto-reload" element or None.

        Returns:
            A MetaAutoReload instance or None.
        """
        return self.get_auto_reload()

    def set_auto_reload(self, delay: timedelta, href: str = "") -> None:
        """Set or replace the `meta:auto-reload` element.

        This specifies whether a document is reloaded or replaced by another
        document after a specified period of time. Any existing
        `meta:auto-reload` element will be removed.

        Args:
            delay: The time delay after which the document should auto-reload.
            href: The URL or path to the document to reload or replace with.
        """
        autoreload = MetaAutoReload(delay=delay, href=href)
        current = self.auto_reload
        if isinstance(current, MetaAutoReload):
            current.delete()
        self.body.append(autoreload)

    def get_hyperlink_behaviour(self) -> MetaHyperlinkBehaviour | None:
        """Get the MetaHyperlinkBehaviour "meta:hyperlink-behaviour" element or
        None.

        Returns:
            A MetaHyperlinkBehaviour instance or None.
        """
        element: MetaHyperlinkBehaviour | None = self.get_element(  # type: ignore[assignment]
            "//meta:hyperlink-behaviour"
        )
        return element

    @property
    def hyperlink_behaviour(self) -> MetaHyperlinkBehaviour | None:
        """Get the MetaHyperlinkBehaviour "meta:hyperlink-behaviour" element or
        None.

        Returns:
            A MetaHyperlinkBehaviour instance or None.
        """
        return self.get_hyperlink_behaviour()

    def set_hyperlink_behaviour(
        self,
        target_frame_name: str = "_blank",
        show: str = "replace",
    ) -> None:
        """Set or replace the `meta:hyperlink-behaviour` element.

        This specifies the default behavior for hyperlinks in a document.
        Any existing `meta:hyperlink-behaviour` element will be removed.

        Args:
            target_frame_name: The name of the target frame for the hyperlink.
                Defaults to "_blank" (new window/tab).
            show: Specifies how the target resource is presented.
                Defaults to "replace".
        """
        behaviour = MetaHyperlinkBehaviour(
            target_frame_name=target_frame_name, show=show
        )
        current = self.hyperlink_behaviour
        if isinstance(current, MetaHyperlinkBehaviour):
            current.delete()
        self.body.append(behaviour)

    def get_initial_creator(self) -> str | None:
        """Get the first creator of the document.

        (Also available as "self.initial_creator" property.)

        Returns:
            str | None: The initial creator string, or None if inexistent.

        Example::

            >>> document.meta.get_initial_creator()
            Unknown
        """
        element = self.get_element("//meta:initial-creator")
        if element is None:
            return None
        return element.text

    def set_initial_creator(self, creator: str) -> None:
        """Set the first creator of the document.

        (Also available as "self.initial_creator" property.)

        Args:
            creator: The creator string to set.

        Example::

            >>> document.meta.set_initial_creator("Plato")
        """
        element = self.get_element("//meta:initial-creator")
        if element is None:
            element = Element.from_tag("meta:initial-creator")
            self.body.append(element)
        element.text = creator

    @property
    def initial_creator(self) -> str | None:
        """Get or set the initial creator of a document <meta:initial-creator>.

        Returns: str (or None if inexistent)
        """
        return self.get_initial_creator()

    @initial_creator.setter
    def initial_creator(self, creator: str) -> None:
        return self.set_initial_creator(creator)

    @property
    def printed_by(self) -> str | None:
        """Get or set the name of the last person who printed a document.
        <meta:printed-by>

        Returns:
            str | None: The printed by string, or None if inexistent.
        """
        element = self.get_element("//meta:printed-by")
        if element is None:
            return None
        return element.text

    @printed_by.setter
    def printed_by(self, printed_by: str) -> None:
        element = self.get_element("//meta:printed-by")
        if element is None:
            element = Element.from_tag("meta:printed-by")
            self.body.append(element)
        element.text = printed_by

    def get_keywords(self) -> str | None:
        """Get the keywords of the document. Return the field as-is, without
        any assumption on the keyword separator.

        (Also available as "self.keyword" and "self.keywords" property.)

        Returns:
            str | None: The keywords string, or None if inexistent.
        """
        element = self.get_element("//meta:keyword")
        if element is None:
            return None
        return element.text

    def set_keywords(self, keywords: str) -> None:
        """Set the keywords of the document. Although the name is plural, a str
        string is required, so join your list first.

        (Also available as "self.keyword" and "self.keywords" property.)

        Args:
            keywords: The keywords string to set.
        """
        element = self.get_element("//meta:keyword")
        if element is None:
            element = Element.from_tag("meta:keyword")
            self.body.append(element)
        element.text = keywords

    @property
    def keyword(self) -> str | None:
        """Get or set some keyword(s) keyword pertaining to a document
        <dc:keyword>.

        Returns:
            str | None: The keyword string, or None if inexistent.
        """
        return self.get_keywords()

    @keyword.setter
    def keyword(self, keyword: str) -> None:
        return self.set_keywords(keyword)

    keywords = keyword

    def get_editing_duration(self) -> timedelta | None:
        """Get the time the document was edited, as reported by the generator.

        (Also available as "self.editing_duration" property.)

        Returns:
            timedelta | None: The editing duration as a timedelta object, or None if inexistent.
        """
        element = self.get_element("//meta:editing-duration")
        if element is None:
            return None
        duration = element.text
        return Duration.decode(duration)

    def set_editing_duration(self, duration: timedelta) -> None:
        """Set the time the document was edited.

        (Also available as "self.editing_duration" property.)

        Args:
            duration: The timedelta object representing the editing duration.
        """
        if not isinstance(duration, timedelta):
            raise TypeError("duration must be a timedelta")
        element = self.get_element("//meta:editing-duration")
        if element is None:
            element = Element.from_tag("meta:editing-duration")
            self.body.append(element)
        element.text = Duration.encode(duration)

    @property
    def editing_duration(self) -> timedelta | None:
        """Get or set the total time spent editing a document <meta:editing-
        duration>.

        Returns: timedelta (or None if inexistent)
        """
        return self.get_editing_duration()

    @editing_duration.setter
    def editing_duration(self, duration: timedelta) -> None:
        return self.set_editing_duration(duration)

    def get_editing_cycles(self) -> int | None:
        """Get the number of times the document was edited, as reported by the
        generator.

        (Also available as "self.editing_cycles" property.)

        Returns:
            int | None: The number of editing cycles as an integer, or None if inexistent.
        """
        element = self.get_element("//meta:editing-cycles")
        if element is None:
            return None
        cycles = element.text
        return int(cycles)

    def set_editing_cycles(self, cycles: int) -> None:
        """Set the number of times the document was edited.

        (Also available as "self.editing_cycles" property.)

        Args:
            cycles: The number of editing cycles to set.
        """
        if not isinstance(cycles, int):
            raise TypeError("cycles must be an int")
        if cycles < 1:
            raise ValueError("cycles must be a positive int")
        element = self.get_element("//meta:editing-cycles")
        if element is None:
            element = Element.from_tag("meta:editing-cycles")
            self.body.append(element)
        element.text = str(cycles)

    @property
    def editing_cycles(self) -> int | None:
        """Get or set the number of times a document has been edited
        <meta:editing-cycles>.

        When a document is created, this value is set to 1. Each time
        a document is saved, the editing-cycles number is incremented by 1.

        Returns: int (or None if inexistent)
        """
        return self.get_editing_cycles()

    @editing_cycles.setter
    def editing_cycles(self, cycles: int) -> None:
        return self.set_editing_cycles(cycles)

    @property
    def generator(self) -> str | None:
        """Get or set the signature of the software that generated this
        document.

        Returns:
            str | None: The generator string, or None if inexistent.

        Example::

            >>> document.meta.generator
            KOffice/2.0.0
            >>> document.meta.generator = "Odfdo experiment"
        """
        element = self.get_element("//meta:generator")
        if element is None:
            return None
        return element.text

    @generator.setter
    def generator(self, generator: str) -> None:
        element = self.get_element("//meta:generator")
        if element is None:
            element = Element.from_tag("meta:generator")
            self.body.append(element)
        element.text = generator
        self._generator_modified = True

    def get_generator(self) -> str | None:
        """Get the signature of the software that generated this document.

        (Also available as "self.generator" property.)

        Returns:
            str (or None if inexistent).

        Example::

            >>> document.meta.get_generator()
            KOffice/2.0.0
        """
        return self.generator

    def set_generator(self, generator: str) -> None:
        """Set the signature of the software that generated this document.

        (Also available as "self.generator" property.)

        Args:
            generator: The generator string to set.

        Example::

            >>> document.meta.set_generator("Odfdo experiment")
        """
        self.generator = generator

    def set_generator_default(self) -> None:
        """Set the signature of the software that generated this document to
        ourself.

        Example::

            >>> document.meta.set_generator_default()
        """
        if not self._generator_modified:
            self.generator = GENERATOR

    def get_statistic(self) -> dict[str, int] | None:
        """Get the statistics about a document, "meta:document-statistic" tag.

        (Also available as "self.statistic" property.)

        Returns:
            A dict (or None if inexistent).

        Example::

            >>> document.get_statistic():
            {'meta:table-count': 1,
             'meta:image-count': 2,
             'meta:object-count': 3,
             'meta:page-count': 4,
             'meta:paragraph-count': 5,
             'meta:word-count': 6,
             'meta:character-count': 7,
             'meta:non-whitespace-character-count': 3}
        """
        element = self.get_element("//meta:document-statistic")
        if element is None:
            return None
        statistic = {}
        for key, value in element.attributes.items():
            statistic[to_str(key)] = int(value)
        return statistic

    def set_statistic(self, statistic: dict[str, int]) -> None:
        """Set the statistics about a document, "meta:document-statistic" tag.

        (Also available as "self.statistic" property.)

        Args:
            statistic: The statistics dictionary to set.

        Example::

            >>> statistic = {'meta:table-count': 1,
                             'meta:image-count': 2,
                             'meta:object-count': 3,
                             'meta:page-count': 4,
                             'meta:paragraph-count': 5,
                             'meta:word-count': 6,
                             'meta:character-count': 7,
                             'meta:non-whitespace-character-count': 3}
            >>> document.meta.set_statistic(statistic)
        """
        if not isinstance(statistic, dict):
            raise TypeError("Statistic must be a dict")
        element = self.get_element("//meta:document-statistic")
        if element is None:
            element = Element.from_tag("meta:document-statistic")
            self.body.append(element)
        for key, value in statistic.items():
            try:
                ivalue = int(value)
            except ValueError as e:
                msg = f"Statistic value must be a int: {key}:{value!r}"
                raise TypeError(msg) from e
            element.set_attribute(to_str(key), str(ivalue))

    @property
    def statistic(self) -> dict[str, int] | None:
        """Get or set the statistics about a document, "meta:document-
        statistic" tag.

        Returns:
            dict[str, int] | None: The statistics dictionary, or None if inexistent.

        Example::

            >>> document.get_statistic():
            {'meta:table-count': 1,
             'meta:image-count': 2,
             'meta:object-count': 3,
             'meta:page-count': 4,
             'meta:paragraph-count': 5,
             'meta:word-count': 6,
             'meta:character-count': 7,
             'meta:non-whitespace-character-count':3}
        """
        return self.get_statistic()

    @statistic.setter
    def statistic(self, statistic: dict[str, int]) -> None:
        return self.set_statistic(statistic)

    def get_user_defined_metadata(
        self,
    ) -> dict[str, Decimal | datetime | dtdate | timedelta | bool | str]:
        """Get all additional user-defined metadata for a document.

        (Also available as "self.user_defined_metadata" property.)

        Returns:
           A dict of str/value mapping.

        Value types can be: Decimal, datetime, date, timedelta, bool or str.
        """
        return {
            data.name: data.value
            for data in cast(
                list[MetaUserDefined], self.get_elements("//meta:user-defined")
            )
        }

    def _user_defined_metadata_list(
        self,
    ) -> list[dict[str, Decimal | datetime | dtdate | timedelta | bool | str]]:
        """Internal helper to retrieve all user-defined metadata as a sorted list of dictionaries.

        Returns:
            list[dict[str, Any]]: A sorted list of dictionaries, each
                representing a user-defined metadata field.
        """
        user_defined = [
            data.as_dict()
            for data in cast(
                list[MetaUserDefined], self.get_elements("//meta:user-defined")
            )
        ]
        return sorted(user_defined, key=itemgetter("meta:name"))

    def clear_user_defined_metadata(self) -> None:
        """Remove all user-defined metadata fields from the document.

        Iteratively deletes all `meta:user-defined` elements.
        """
        while True:
            element = self.get_element("//meta:user-defined")
            if isinstance(element, MetaUserDefined):
                element.delete()
                continue
            break

    @property
    def user_defined_metadata(
        self,
    ) -> dict[str, Decimal | datetime | dtdate | timedelta | bool | str]:
        """Get or set all additional user-defined metadata for a document.

        Return a dict of str/value mapping.

        Value types can be: Decimal, datetime, date, timedelta, bool or str.
        """
        return self.get_user_defined_metadata()

    @user_defined_metadata.setter
    def user_defined_metadata(self, metadata: dict[str, Any]) -> None:
        self.clear_user_defined_metadata()
        for key, val in metadata.items():
            self.set_user_defined_metadata(name=key, value=val)

    def _user_defined_metadata_by_name(self, name: str) -> MetaUserDefined | None:
        """Internal helper to find a specific user-defined metadata element by name.

        Args:
            name: The name of the user-defined metadata field to find.

        Returns:
            MetaUserDefined | None: The `MetaUserDefined` element if found,
                otherwise `None`.
        """
        for item in cast(
            list[MetaUserDefined], self.get_elements("//meta:user-defined")
        ):
            if item.name == name:
                return item
        return None

    def get_user_defined_metadata_of_name(self, keyname: str) -> dict[str, Any] | None:
        """Return the content of the user defined metadata of that name. Return
        None if no name matches or a dic of fields.

        Args:
            keyname: The name of the user-defined metadata field to find.

        Returns:
            dict[str, Any]: A dict with keys "name", "value", "value_type", "text".
        """
        item = self._user_defined_metadata_by_name(keyname)
        if item is None:
            return None
        return item.as_dict_full()

    def set_user_defined_metadata(
        self,
        name: str,
        value: bool
        | int
        | float
        | Decimal
        | datetime
        | dtdate
        | str
        | timedelta
        | None,
    ) -> None:
        """Set a user defined metadata of that name and value.

        If value is None, any existing metadata of that name is deleted.

        Args:
            name: The name of the user-defined metadata field.
            value: The value to set for the metadata field.
                Can be a boolean, int, float, Decimal, datetime, date, string,
                timedelta, or None for deletion.
        """
        if value is None:
            self.delete_user_defined_metadata_of_name(name)
            return
        value_type = MetaUserDefined._value_to_value_type(value)
        # Already the same element ?
        metadata = self._user_defined_metadata_by_name(name)
        if metadata is None:
            metadata = MetaUserDefined(name=name, value_type=value_type, value=value)
            self.body.append(metadata)
        else:
            metadata.value_type = value_type
            metadata.value = value

    def delete_user_defined_metadata_of_name(self, name: str) -> None:
        """Delete all user-defined metadata fields with a specific name.

        Args:
            name: The name of the user-defined metadata field to delete.
        """
        while True:
            metadata = self._user_defined_metadata_by_name(name)
            if not metadata:
                return
            metadata.delete()

    def as_dict(self, full: bool = False) -> dict[str, Any]:
        """Return the metadata of the document as a Python dict.

        if 'full' is True, export also the keys with no value assigned.

        Args:
            full: If True, exports also the keys with no value assigned.

        Returns:
            The metadata of the document as a Python dict.
        """

        def _stats() -> dict[str, int]:
            doc_stats = self.statistic
            if doc_stats is None:
                msg = "Document statistics not found"
                raise LookupError(msg)
            return {
                key: doc_stats.get(key, 0)
                for key in (
                    "meta:table-count",
                    "meta:image-count",
                    "meta:object-count",
                    "meta:page-count",
                    "meta:paragraph-count",
                    "meta:word-count",
                    "meta:character-count",
                    "meta:non-whitespace-character-count",
                )
            }

        def _meta_template() -> dict[str, Any] | None:
            template = self.template
            if template is None:
                return None
            return template.as_dict()

        def _meta_reload() -> dict[str, Any] | None:
            reload = self.auto_reload
            if reload is None:
                return None
            return reload.as_dict()

        def _meta_behaviour() -> dict[str, Any] | None:
            behaviour = self.hyperlink_behaviour
            if behaviour is None:
                return None
            return behaviour.as_dict()

        meta_data: dict[str, Any] = {
            "meta:creation-date": self.creation_date,
            "dc:date": self.date,
            "meta:editing-duration": self.editing_duration,
            "meta:editing-cycles": self.editing_cycles,
            "meta:document-statistic": _stats(),
            "meta:generator": self.generator,
            "dc:title": self.title,
            "dc:description": self.description,
            "dc:creator": self.creator,
            "meta:keyword": self.keyword,
            "dc:subject": self.subject,
            "dc:language": self.language,
            "meta:initial-creator": self.initial_creator,
            "meta:print-date": self.print_date,
            "meta:printed-by": self.printed_by,
            "meta:template": _meta_template(),
            "meta:auto-reload": _meta_reload(),
            "meta:hyperlink-behaviour": _meta_behaviour(),
            "meta:user-defined": self._user_defined_metadata_list(),
        }

        if not full:
            meta_data = {key: val for key, val in meta_data.items() if val}
        return meta_data

    def _as_json_dict(self, full: bool = False) -> dict[str, Any]:
        """Internal method to prepare metadata as a JSON-compatible dictionary.

        This converts various Python types (datetime, timedelta, Decimal) into
        their string representations suitable for JSON serialization.

        Args:
            full (bool): If True, exports all keys including those with no value assigned.

        Returns:
            dict[str, Any]: A dictionary of metadata ready for JSON serialization.
        """

        def _convert(data: dict[str, Any]) -> None:
            for key, val in data.items():
                if isinstance(val, datetime):
                    data[key] = DateTime.encode(val)
                elif isinstance(val, timedelta):
                    data[key] = Duration.encode(val)
                elif isinstance(val, Decimal):
                    data[key] = json.loads(str(Decimal(val)))

        meta_data: dict[str, Any] = self.as_dict(full=full)
        user_defined = meta_data.get("meta:user-defined", [])
        for item in user_defined:
            _convert(item)
        meta_data["meta:user-defined"] = user_defined
        meta_template = meta_data.get("meta:template")
        if meta_template is not None:
            _convert(meta_template)
            meta_data["meta:template"] = meta_template
        reload = meta_data.get("meta:auto-reload")
        if reload is not None:
            _convert(reload)
            meta_data["meta:auto-reload"] = reload
        meta_data["meta:user-defined"] = user_defined

        _convert(meta_data)
        return meta_data

    def as_json(self, full: bool = False) -> str:
        """Return the metadata of the document as a JSON string.

        if 'full' is True, export also the keys with no value assigned.

        Args:
            full:  boolean

        Returns:
            The metadata of the document as a JSON string.
        """
        return json.dumps(
            self._as_json_dict(full=full),
            ensure_ascii=False,
            sort_keys=False,
            indent=4,
        )

    def as_text(self, no_user_defined_msg: str = "") -> str:
        """Return meta information as text, with some formatting for
        printing.

        Args:
            no_user_defined_msg: customize the string when no user defined
                data is present.

        Returns:
            The metadata of the document as a text.
        """
        data = self._as_json_dict(full=False)
        result: list[str] = []

        def _append_info(name: str, key: str) -> None:
            value = data.get(key)
            if value:
                result.append(f"{name}: {value}")

        _append_info("Title", "dc:title")
        _append_info("Subject", "dc:subject")
        _append_info("Description", "dc:description")
        _append_info("Language", "dc:language")
        _append_info("Modification date", "dc:date")
        _append_info("Creation date", "meta:creation-date")
        _append_info("Creator", "dc:creator")
        _append_info("Initial creator", "meta:initial-creator")
        _append_info("Keyword", "meta:keyword")
        _append_info("Editing duration", "meta:editing-duration")
        _append_info("Editing cycles", "meta:editing-cycles")
        _append_info("Generator", "meta:generator")

        result.append("Statistic:")
        statistic = data.get("meta:document-statistic", {})
        for name, value in statistic.items():
            result.append(f"  - {name[5:].replace('-', ' ').capitalize()}: {value}")

        user_metadata = data.get("meta:user-defined", [])
        if user_metadata:
            msg = ""
        else:
            msg = f" {no_user_defined_msg}"
        result.append(f"User defined metadata:{msg}")
        for item in user_metadata:
            result.append(f"  - {item['meta:name']}: {item['value']}")

        return "\n".join(result)

    @staticmethod
    def _complete_stats(
        current_stats: dict[str, int],
        imported_stats: dict[str, int] | None,
    ) -> dict[str, int]:
        """Internal helper to merge and complete document statistics.

        It takes current statistics and imported statistics, filling in missing
        values with 0 and prioritizing imported values.

        Args:
            current_stats (dict[str, int]): The current document statistics.
            imported_stats (dict[str, int] | None): The statistics to import,
                or None.

        Returns:
            dict[str, int]: A merged dictionary of statistics.
        """
        if imported_stats is None:
            imported_stats = {}
            current_stats = {}
        new: dict[str, int] = {}
        for key in (
            "meta:table-count",
            "meta:image-count",
            "meta:object-count",
            "meta:page-count",
            "meta:paragraph-count",
            "meta:word-count",
            "meta:character-count",
            "meta:non-whitespace-character-count",
        ):
            new[key] = imported_stats.get(key, current_stats.get(key, 0))
        return new

    def from_dict(self, data: dict[str, Any]) -> None:
        """Set the metadata of the document from a Python dict.

        The loaded metadata are merged with the existing metadata.
        If the new value of a key is None:
            - meta:creation-date: use current time,
            - dc:date: use creation date,
            - meta:editing-duration: set to zero,
            - meta:editing-cycles: set to 1,
            - meta:generator: use odfdo generator string.
            Other keys (not mandatory keys): remove key/value pair from
            metadata.

        Args:
            data: A dictionary of metadata.
        """

        def _value_delete(key: str) -> Any:
            value = data.get(key, current.get(key))
            if value is None:
                child = self.get_element(f"//{key}")
                if child is not None:
                    self.delete_element(child)
            return value

        current = self.as_dict()
        new_stats = self._complete_stats(
            current["meta:document-statistic"],
            data.get("meta:document-statistic", {}),
        )
        # mandatory
        self.statistic = new_stats

        key = "meta:creation-date"
        creation_date = data.get(key, current.get(key))
        if creation_date is None:
            creation_date = datetime.now().replace(microsecond=0)
        self.creation_date = creation_date

        key = "dc:date"
        dc_date = data.get(key, current.get(key))
        if dc_date is None:
            dc_date = creation_date
        if dc_date < creation_date:
            dc_date = creation_date
        max_editing = dc_date - creation_date
        self.date = dc_date

        key = "meta:editing-duration"
        editing_duration = data.get(key, current.get(key))
        if editing_duration is None:
            editing_duration = timedelta(0)
        if editing_duration > max_editing:
            editing_duration = max_editing
        self.editing_duration = editing_duration

        key = "meta:editing-cycles"
        editing_cycles = data.get(key, current.get(key))
        if editing_cycles is None:
            editing_cycles = 1
        self.editing_cycles = max(editing_cycles, 1)

        key = "meta:generator"
        generator = data.get(key, current.get(key))
        if not generator:
            generator = GENERATOR
        self.generator = generator

        # not mandatory values
        # - if not in imported: keep original value
        # - if imported is None: erase original value

        key = "dc:title"
        value = _value_delete(key)
        if value is not None:
            self.title = value

        key = "dc:description"
        value = _value_delete(key)
        if value is not None:
            self.description = value

        key = "dc:creator"
        value = _value_delete(key)
        if value is not None:
            self.creator = value

        key = "meta:keyword"
        value = _value_delete(key)
        if value is not None:
            self.keyword = value

        key = "dc:subject"
        value = _value_delete(key)
        if value is not None:
            self.subject = value

        key = "dc:language"
        value = _value_delete(key)
        if value is not None:
            self.language = value

        key = "meta:initial-creator"
        value = _value_delete(key)
        if value is not None:
            self.initial_creator = value

        key = "meta:print-date"
        value = _value_delete(key)
        if value is not None:
            self.print_date = value

        key = "meta:printed-by"
        value = _value_delete(key)
        if value is not None:
            self.printed_by = value

        key = "meta:template"
        value = _value_delete(key)
        if value is not None:
            self.set_template(
                date=value["meta:date"],
                href=value["xlink:href"],
                title=value["xlink:title"],
            )

        key = "meta:auto-reload"
        value = _value_delete(key)
        if value is not None:
            self.set_auto_reload(
                delay=value["meta:delay"],
                href=value["xlink:href"],
            )

        key = "meta:hyperlink-behaviour"
        value = _value_delete(key)
        if value is not None:
            self.set_hyperlink_behaviour(
                target_frame_name=value["office:target-frame-name"],
                show=value["xlink:show"],
            )

        key = "meta:user-defined"
        if key in data:
            value = data[key]
            if value is None:
                self.clear_user_defined_metadata()
            else:
                data_list = self._user_defined_metadata_list()
                current_dict = {d["meta:name"]: d for d in data_list}
                current_value = {d["meta:name"]: d for d in value}
                current_dict.update(current_value)
                new_ud = {
                    v["meta:name"]: v["value"]
                    for v in current_dict.values()
                    if v["value"] is not None
                }
                self.user_defined_metadata = new_ud  # type: ignore[assignment]

    def strip(
        self,
        generator: str = GENERATOR,
        creation_date: datetime | None = None,
    ) -> None:
        """Strip metadata to their minimal content.

        By default the new metadata values are:
            - meta:creation-date: use current time,
            - dc:date: use creation date,
            - meta:editing-duration: set to zero,
            - meta:editing-cycles: set to 1,
            - meta:generator: use odfdo generator string.
            - all meta:document-statistic values to 0.

        All user defined metadata are removed.

        Args:
            generator: String for the meta:generator field.
            creation_date: Datetime or None, meta:creation-date value.
        """

        self.body.clear()
        self.statistic = self._complete_stats({}, None)
        if creation_date is None:
            self.creation_date = datetime.now().replace(microsecond=0)
        else:
            self.creation_date = creation_date.replace(microsecond=0)
        self.date = self.creation_date
        self.editing_duration = timedelta(0)
        self.editing_cycles = 1
        self.generator = generator
        self.clear_user_defined_metadata()

_generator_modified instance-attribute

_generator_modified: bool = False

auto_reload property

auto_reload: MetaAutoReload | None

Get the MetaAutoReload “meta:auto-reload” element or None.

Returns:

Type Description
MetaAutoReload | None

A MetaAutoReload instance or None.

creation_date property writable

creation_date: datetime | None

Get or set the date and time when a document was created .

If provided datetime is None, use current time.

Returns: datetime (or None if inexistent)

description property writable

description: str | None

Get or set the description of a document .

Returns: str (or None if inexistent)

editing_cycles property writable

editing_cycles: int | None

Get or set the number of times a document has been edited .

When a document is created, this value is set to 1. Each time a document is saved, the editing-cycles number is incremented by 1.

Returns: int (or None if inexistent)

editing_duration property writable

editing_duration: timedelta | None

Get or set the total time spent editing a document .

Returns: timedelta (or None if inexistent)

generator property writable

generator: str | None

Get or set the signature of the software that generated this document.

Returns:

Type Description
str | None

str | None: The generator string, or None if inexistent.

Example::

>>> document.meta.generator
KOffice/2.0.0
>>> document.meta.generator = "Odfdo experiment"

get_comments class-attribute instance-attribute

get_comments = get_description

get_meta_body class-attribute instance-attribute

get_meta_body = _get_body
hyperlink_behaviour: MetaHyperlinkBehaviour | None

Get the MetaHyperlinkBehaviour “meta:hyperlink-behaviour” element or None.

Returns:

Type Description
MetaHyperlinkBehaviour | None

A MetaHyperlinkBehaviour instance or None.

initial_creator property writable

initial_creator: str | None

Get or set the initial creator of a document .

Returns: str (or None if inexistent)

keyword property writable

keyword: str | None

Get or set some keyword(s) keyword pertaining to a document .

Returns:

Type Description
str | None

str | None: The keyword string, or None if inexistent.

keywords class-attribute instance-attribute

keywords = keyword

language property writable

language: str | None

Get or set the default language of the document BUT only in the metadata, “dc:language”.

To set globally the default language, prefer the Document.language property.

Returns: str (or None if inexistent)

meta_body property

meta_body: Metadata

Return the body of the “meta.xml” part.

odf_office_version property

odf_office_version: str

Return the “office:version” value of the document.

print_date property writable

print_date: datetime | None

Get or set the date and time when a document when a document was last printed

If provided datetime is None, use current time.

Returns:

Type Description
datetime | None

datetime | None: The print date as a datetime object, or None if inexistent.

printed_by property writable

printed_by: str | None

Get or set the name of the last person who printed a document.

Returns:

Type Description
str | None

str | None: The printed by string, or None if inexistent.

set_comments class-attribute instance-attribute

set_comments = set_description

statistic property writable

statistic: dict[str, int] | None

Get or set the statistics about a document, “meta:document- statistic” tag.

Returns:

Type Description
dict[str, int] | None

dict[str, int] | None: The statistics dictionary, or None if inexistent.

Example::

>>> document.get_statistic():
{'meta:table-count': 1,
 'meta:image-count': 2,
 'meta:object-count': 3,
 'meta:page-count': 4,
 'meta:paragraph-count': 5,
 'meta:word-count': 6,
 'meta:character-count': 7,
 'meta:non-whitespace-character-count':3}

subject property writable

subject: str | None

Get or set the subject of a document .

Returns: str (or None if inexistent)

template property

template: MetaTemplate | None

Get the MetaTemplate “meta:template” element or None.

Returns:

Type Description
MetaTemplate | None

A MetaTemplate instance or None.

title property writable

title: str | None

Get or set the title of the document .

Returns: str (or None if inexistent)

user_defined_metadata property writable

user_defined_metadata: dict[
    str, Decimal | datetime | date | timedelta | bool | str
]

Get or set all additional user-defined metadata for a document.

Return a dict of str/value mapping.

Value types can be: Decimal, datetime, date, timedelta, bool or str.

__init__

__init__(*args: Any, **kwargs: Any) -> None

Initialize the Meta XML part.

This represents the meta.xml file within an ODF document, containing various document metadata.

Parameters:

Name Type Description Default
*args Any

Positional arguments passed to the parent XmlPart constructor.

()
**kwargs Any

Keyword arguments passed to the parent XmlPart constructor.

{}
Source code in odfdo/meta.py
55
56
57
58
59
60
61
62
63
64
65
66
def __init__(self, *args: Any, **kwargs: Any) -> None:
    """Initialize the Meta XML part.

    This represents the `meta.xml` file within an ODF document, containing
    various document metadata.

    Args:
        *args: Positional arguments passed to the parent `XmlPart` constructor.
        **kwargs: Keyword arguments passed to the parent `XmlPart` constructor.
    """
    super().__init__(*args, **kwargs)
    self._generator_modified: bool = False

_as_json_dict

_as_json_dict(full: bool = False) -> dict[str, Any]

Internal method to prepare metadata as a JSON-compatible dictionary.

This converts various Python types (datetime, timedelta, Decimal) into their string representations suitable for JSON serialization.

Parameters:

Name Type Description Default
full bool

If True, exports all keys including those with no value assigned.

False

Returns:

Type Description
dict[str, Any]

dict[str, Any]: A dictionary of metadata ready for JSON serialization.

Source code in odfdo/meta.py
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
def _as_json_dict(self, full: bool = False) -> dict[str, Any]:
    """Internal method to prepare metadata as a JSON-compatible dictionary.

    This converts various Python types (datetime, timedelta, Decimal) into
    their string representations suitable for JSON serialization.

    Args:
        full (bool): If True, exports all keys including those with no value assigned.

    Returns:
        dict[str, Any]: A dictionary of metadata ready for JSON serialization.
    """

    def _convert(data: dict[str, Any]) -> None:
        for key, val in data.items():
            if isinstance(val, datetime):
                data[key] = DateTime.encode(val)
            elif isinstance(val, timedelta):
                data[key] = Duration.encode(val)
            elif isinstance(val, Decimal):
                data[key] = json.loads(str(Decimal(val)))

    meta_data: dict[str, Any] = self.as_dict(full=full)
    user_defined = meta_data.get("meta:user-defined", [])
    for item in user_defined:
        _convert(item)
    meta_data["meta:user-defined"] = user_defined
    meta_template = meta_data.get("meta:template")
    if meta_template is not None:
        _convert(meta_template)
        meta_data["meta:template"] = meta_template
    reload = meta_data.get("meta:auto-reload")
    if reload is not None:
        _convert(reload)
        meta_data["meta:auto-reload"] = reload
    meta_data["meta:user-defined"] = user_defined

    _convert(meta_data)
    return meta_data

_complete_stats staticmethod

_complete_stats(
    current_stats: dict[str, int],
    imported_stats: dict[str, int] | None,
) -> dict[str, int]

Internal helper to merge and complete document statistics.

It takes current statistics and imported statistics, filling in missing values with 0 and prioritizing imported values.

Parameters:

Name Type Description Default
current_stats dict[str, int]

The current document statistics.

required
imported_stats dict[str, int] | None

The statistics to import, or None.

required

Returns:

Type Description
dict[str, int]

dict[str, int]: A merged dictionary of statistics.

Source code in odfdo/meta.py
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
@staticmethod
def _complete_stats(
    current_stats: dict[str, int],
    imported_stats: dict[str, int] | None,
) -> dict[str, int]:
    """Internal helper to merge and complete document statistics.

    It takes current statistics and imported statistics, filling in missing
    values with 0 and prioritizing imported values.

    Args:
        current_stats (dict[str, int]): The current document statistics.
        imported_stats (dict[str, int] | None): The statistics to import,
            or None.

    Returns:
        dict[str, int]: A merged dictionary of statistics.
    """
    if imported_stats is None:
        imported_stats = {}
        current_stats = {}
    new: dict[str, int] = {}
    for key in (
        "meta:table-count",
        "meta:image-count",
        "meta:object-count",
        "meta:page-count",
        "meta:paragraph-count",
        "meta:word-count",
        "meta:character-count",
        "meta:non-whitespace-character-count",
    ):
        new[key] = imported_stats.get(key, current_stats.get(key, 0))
    return new

_get_body

_get_body() -> Metadata

Internal method to get the root office:meta element.

Returns:

Name Type Description
Metadata Metadata

The office:meta element.

Source code in odfdo/meta.py
68
69
70
71
72
73
74
def _get_body(self) -> Metadata:
    """Internal method to get the root `office:meta` element.

    Returns:
        Metadata: The `office:meta` element.
    """
    return self.get_element("//office:meta")  # type: ignore[return-value]

_user_defined_metadata_by_name

_user_defined_metadata_by_name(
    name: str,
) -> MetaUserDefined | None

Internal helper to find a specific user-defined metadata element by name.

Parameters:

Name Type Description Default
name str

The name of the user-defined metadata field to find.

required

Returns:

Type Description
MetaUserDefined | None

MetaUserDefined | None: The MetaUserDefined element if found, otherwise None.

Source code in odfdo/meta.py
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
def _user_defined_metadata_by_name(self, name: str) -> MetaUserDefined | None:
    """Internal helper to find a specific user-defined metadata element by name.

    Args:
        name: The name of the user-defined metadata field to find.

    Returns:
        MetaUserDefined | None: The `MetaUserDefined` element if found,
            otherwise `None`.
    """
    for item in cast(
        list[MetaUserDefined], self.get_elements("//meta:user-defined")
    ):
        if item.name == name:
            return item
    return None

_user_defined_metadata_list

_user_defined_metadata_list() -> list[
    dict[
        str,
        Decimal
        | datetime
        | dtdate
        | timedelta
        | bool
        | str,
    ]
]

Internal helper to retrieve all user-defined metadata as a sorted list of dictionaries.

Returns:

Type Description
list[dict[str, Decimal | datetime | date | timedelta | bool | str]]

list[dict[str, Any]]: A sorted list of dictionaries, each representing a user-defined metadata field.

Source code in odfdo/meta.py
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
def _user_defined_metadata_list(
    self,
) -> list[dict[str, Decimal | datetime | dtdate | timedelta | bool | str]]:
    """Internal helper to retrieve all user-defined metadata as a sorted list of dictionaries.

    Returns:
        list[dict[str, Any]]: A sorted list of dictionaries, each
            representing a user-defined metadata field.
    """
    user_defined = [
        data.as_dict()
        for data in cast(
            list[MetaUserDefined], self.get_elements("//meta:user-defined")
        )
    ]
    return sorted(user_defined, key=itemgetter("meta:name"))

as_dict

as_dict(full: bool = False) -> dict[str, Any]

Return the metadata of the document as a Python dict.

if ‘full’ is True, export also the keys with no value assigned.

Parameters:

Name Type Description Default
full bool

If True, exports also the keys with no value assigned.

False

Returns:

Type Description
dict[str, Any]

The metadata of the document as a Python dict.

Source code in odfdo/meta.py
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
def as_dict(self, full: bool = False) -> dict[str, Any]:
    """Return the metadata of the document as a Python dict.

    if 'full' is True, export also the keys with no value assigned.

    Args:
        full: If True, exports also the keys with no value assigned.

    Returns:
        The metadata of the document as a Python dict.
    """

    def _stats() -> dict[str, int]:
        doc_stats = self.statistic
        if doc_stats is None:
            msg = "Document statistics not found"
            raise LookupError(msg)
        return {
            key: doc_stats.get(key, 0)
            for key in (
                "meta:table-count",
                "meta:image-count",
                "meta:object-count",
                "meta:page-count",
                "meta:paragraph-count",
                "meta:word-count",
                "meta:character-count",
                "meta:non-whitespace-character-count",
            )
        }

    def _meta_template() -> dict[str, Any] | None:
        template = self.template
        if template is None:
            return None
        return template.as_dict()

    def _meta_reload() -> dict[str, Any] | None:
        reload = self.auto_reload
        if reload is None:
            return None
        return reload.as_dict()

    def _meta_behaviour() -> dict[str, Any] | None:
        behaviour = self.hyperlink_behaviour
        if behaviour is None:
            return None
        return behaviour.as_dict()

    meta_data: dict[str, Any] = {
        "meta:creation-date": self.creation_date,
        "dc:date": self.date,
        "meta:editing-duration": self.editing_duration,
        "meta:editing-cycles": self.editing_cycles,
        "meta:document-statistic": _stats(),
        "meta:generator": self.generator,
        "dc:title": self.title,
        "dc:description": self.description,
        "dc:creator": self.creator,
        "meta:keyword": self.keyword,
        "dc:subject": self.subject,
        "dc:language": self.language,
        "meta:initial-creator": self.initial_creator,
        "meta:print-date": self.print_date,
        "meta:printed-by": self.printed_by,
        "meta:template": _meta_template(),
        "meta:auto-reload": _meta_reload(),
        "meta:hyperlink-behaviour": _meta_behaviour(),
        "meta:user-defined": self._user_defined_metadata_list(),
    }

    if not full:
        meta_data = {key: val for key, val in meta_data.items() if val}
    return meta_data

as_json

as_json(full: bool = False) -> str

Return the metadata of the document as a JSON string.

if ‘full’ is True, export also the keys with no value assigned.

Parameters:

Name Type Description Default
full bool

boolean

False

Returns:

Type Description
str

The metadata of the document as a JSON string.

Source code in odfdo/meta.py
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
def as_json(self, full: bool = False) -> str:
    """Return the metadata of the document as a JSON string.

    if 'full' is True, export also the keys with no value assigned.

    Args:
        full:  boolean

    Returns:
        The metadata of the document as a JSON string.
    """
    return json.dumps(
        self._as_json_dict(full=full),
        ensure_ascii=False,
        sort_keys=False,
        indent=4,
    )

as_text

as_text(no_user_defined_msg: str = '') -> str

Return meta information as text, with some formatting for printing.

Parameters:

Name Type Description Default
no_user_defined_msg str

customize the string when no user defined data is present.

''

Returns:

Type Description
str

The metadata of the document as a text.

Source code in odfdo/meta.py
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
def as_text(self, no_user_defined_msg: str = "") -> str:
    """Return meta information as text, with some formatting for
    printing.

    Args:
        no_user_defined_msg: customize the string when no user defined
            data is present.

    Returns:
        The metadata of the document as a text.
    """
    data = self._as_json_dict(full=False)
    result: list[str] = []

    def _append_info(name: str, key: str) -> None:
        value = data.get(key)
        if value:
            result.append(f"{name}: {value}")

    _append_info("Title", "dc:title")
    _append_info("Subject", "dc:subject")
    _append_info("Description", "dc:description")
    _append_info("Language", "dc:language")
    _append_info("Modification date", "dc:date")
    _append_info("Creation date", "meta:creation-date")
    _append_info("Creator", "dc:creator")
    _append_info("Initial creator", "meta:initial-creator")
    _append_info("Keyword", "meta:keyword")
    _append_info("Editing duration", "meta:editing-duration")
    _append_info("Editing cycles", "meta:editing-cycles")
    _append_info("Generator", "meta:generator")

    result.append("Statistic:")
    statistic = data.get("meta:document-statistic", {})
    for name, value in statistic.items():
        result.append(f"  - {name[5:].replace('-', ' ').capitalize()}: {value}")

    user_metadata = data.get("meta:user-defined", [])
    if user_metadata:
        msg = ""
    else:
        msg = f" {no_user_defined_msg}"
    result.append(f"User defined metadata:{msg}")
    for item in user_metadata:
        result.append(f"  - {item['meta:name']}: {item['value']}")

    return "\n".join(result)

clear_user_defined_metadata

clear_user_defined_metadata() -> None

Remove all user-defined metadata fields from the document.

Iteratively deletes all meta:user-defined elements.

Source code in odfdo/meta.py
874
875
876
877
878
879
880
881
882
883
884
def clear_user_defined_metadata(self) -> None:
    """Remove all user-defined metadata fields from the document.

    Iteratively deletes all `meta:user-defined` elements.
    """
    while True:
        element = self.get_element("//meta:user-defined")
        if isinstance(element, MetaUserDefined):
            element.delete()
            continue
        break

delete_user_defined_metadata_of_name

delete_user_defined_metadata_of_name(name: str) -> None

Delete all user-defined metadata fields with a specific name.

Parameters:

Name Type Description Default
name str

The name of the user-defined metadata field to delete.

required
Source code in odfdo/meta.py
972
973
974
975
976
977
978
979
980
981
982
def delete_user_defined_metadata_of_name(self, name: str) -> None:
    """Delete all user-defined metadata fields with a specific name.

    Args:
        name: The name of the user-defined metadata field to delete.
    """
    while True:
        metadata = self._user_defined_metadata_by_name(name)
        if not metadata:
            return
        metadata.delete()

from_dict

from_dict(data: dict[str, Any]) -> None

Set the metadata of the document from a Python dict.

The loaded metadata are merged with the existing metadata. If the new value of a key is None: - meta:creation-date: use current time, - dc:date: use creation date, - meta:editing-duration: set to zero, - meta:editing-cycles: set to 1, - meta:generator: use odfdo generator string. Other keys (not mandatory keys): remove key/value pair from metadata.

Parameters:

Name Type Description Default
data dict[str, Any]

A dictionary of metadata.

required
Source code in odfdo/meta.py
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
def from_dict(self, data: dict[str, Any]) -> None:
    """Set the metadata of the document from a Python dict.

    The loaded metadata are merged with the existing metadata.
    If the new value of a key is None:
        - meta:creation-date: use current time,
        - dc:date: use creation date,
        - meta:editing-duration: set to zero,
        - meta:editing-cycles: set to 1,
        - meta:generator: use odfdo generator string.
        Other keys (not mandatory keys): remove key/value pair from
        metadata.

    Args:
        data: A dictionary of metadata.
    """

    def _value_delete(key: str) -> Any:
        value = data.get(key, current.get(key))
        if value is None:
            child = self.get_element(f"//{key}")
            if child is not None:
                self.delete_element(child)
        return value

    current = self.as_dict()
    new_stats = self._complete_stats(
        current["meta:document-statistic"],
        data.get("meta:document-statistic", {}),
    )
    # mandatory
    self.statistic = new_stats

    key = "meta:creation-date"
    creation_date = data.get(key, current.get(key))
    if creation_date is None:
        creation_date = datetime.now().replace(microsecond=0)
    self.creation_date = creation_date

    key = "dc:date"
    dc_date = data.get(key, current.get(key))
    if dc_date is None:
        dc_date = creation_date
    if dc_date < creation_date:
        dc_date = creation_date
    max_editing = dc_date - creation_date
    self.date = dc_date

    key = "meta:editing-duration"
    editing_duration = data.get(key, current.get(key))
    if editing_duration is None:
        editing_duration = timedelta(0)
    if editing_duration > max_editing:
        editing_duration = max_editing
    self.editing_duration = editing_duration

    key = "meta:editing-cycles"
    editing_cycles = data.get(key, current.get(key))
    if editing_cycles is None:
        editing_cycles = 1
    self.editing_cycles = max(editing_cycles, 1)

    key = "meta:generator"
    generator = data.get(key, current.get(key))
    if not generator:
        generator = GENERATOR
    self.generator = generator

    # not mandatory values
    # - if not in imported: keep original value
    # - if imported is None: erase original value

    key = "dc:title"
    value = _value_delete(key)
    if value is not None:
        self.title = value

    key = "dc:description"
    value = _value_delete(key)
    if value is not None:
        self.description = value

    key = "dc:creator"
    value = _value_delete(key)
    if value is not None:
        self.creator = value

    key = "meta:keyword"
    value = _value_delete(key)
    if value is not None:
        self.keyword = value

    key = "dc:subject"
    value = _value_delete(key)
    if value is not None:
        self.subject = value

    key = "dc:language"
    value = _value_delete(key)
    if value is not None:
        self.language = value

    key = "meta:initial-creator"
    value = _value_delete(key)
    if value is not None:
        self.initial_creator = value

    key = "meta:print-date"
    value = _value_delete(key)
    if value is not None:
        self.print_date = value

    key = "meta:printed-by"
    value = _value_delete(key)
    if value is not None:
        self.printed_by = value

    key = "meta:template"
    value = _value_delete(key)
    if value is not None:
        self.set_template(
            date=value["meta:date"],
            href=value["xlink:href"],
            title=value["xlink:title"],
        )

    key = "meta:auto-reload"
    value = _value_delete(key)
    if value is not None:
        self.set_auto_reload(
            delay=value["meta:delay"],
            href=value["xlink:href"],
        )

    key = "meta:hyperlink-behaviour"
    value = _value_delete(key)
    if value is not None:
        self.set_hyperlink_behaviour(
            target_frame_name=value["office:target-frame-name"],
            show=value["xlink:show"],
        )

    key = "meta:user-defined"
    if key in data:
        value = data[key]
        if value is None:
            self.clear_user_defined_metadata()
        else:
            data_list = self._user_defined_metadata_list()
            current_dict = {d["meta:name"]: d for d in data_list}
            current_value = {d["meta:name"]: d for d in value}
            current_dict.update(current_value)
            new_ud = {
                v["meta:name"]: v["value"]
                for v in current_dict.values()
                if v["value"] is not None
            }
            self.user_defined_metadata = new_ud  # type: ignore[assignment]

get_auto_reload

get_auto_reload() -> MetaAutoReload | None

Get the MetaAutoReload “meta:auto-reload” element or None.

Returns:

Type Description
MetaAutoReload | None

A MetaAutoReload instance or None.

Source code in odfdo/meta.py
395
396
397
398
399
400
401
402
def get_auto_reload(self) -> MetaAutoReload | None:
    """Get the MetaAutoReload "meta:auto-reload" element or None.

    Returns:
        A MetaAutoReload instance or None.
    """
    element: MetaAutoReload | None = self.get_element("//meta:auto-reload")  # type: ignore[assignment]
    return element

get_creation_date

get_creation_date() -> datetime | None

Get the creation date of the document.

(Also available as “self.creation_date” property.)

Returns:

Type Description
datetime | None

datetime | None: The creation date as a datetime object, or None if inexistent.

Source code in odfdo/meta.py
282
283
284
285
286
287
288
289
290
291
292
293
294
def get_creation_date(self) -> datetime | None:
    """Get the creation date of the document.

    (Also available as "self.creation_date" property.)

    Returns:
        datetime | None: The creation date as a datetime object, or None if inexistent.
    """
    element = self.get_element("//meta:creation-date")
    if element is None:
        return None
    creation_date = element.text
    return DateTime.decode(creation_date)

get_description

get_description() -> str | None

Get the description of the document. Also known as comments.

(Also available as “self.description” property.)

Returns:

Type Description
str | None

str | None: The description string, or None if inexistent.

Source code in odfdo/meta.py
135
136
137
138
139
140
141
142
143
144
145
146
def get_description(self) -> str | None:
    """Get the description of the document. Also known as comments.

    (Also available as "self.description" property.)

    Returns:
        str | None: The description string, or None if inexistent.
    """
    element = self.get_element("//dc:description")
    if element is None:
        return None
    return element.text

get_editing_cycles

get_editing_cycles() -> int | None

Get the number of times the document was edited, as reported by the generator.

(Also available as “self.editing_cycles” property.)

Returns:

Type Description
int | None

int | None: The number of editing cycles as an integer, or None if inexistent.

Source code in odfdo/meta.py
633
634
635
636
637
638
639
640
641
642
643
644
645
646
def get_editing_cycles(self) -> int | None:
    """Get the number of times the document was edited, as reported by the
    generator.

    (Also available as "self.editing_cycles" property.)

    Returns:
        int | None: The number of editing cycles as an integer, or None if inexistent.
    """
    element = self.get_element("//meta:editing-cycles")
    if element is None:
        return None
    cycles = element.text
    return int(cycles)

get_editing_duration

get_editing_duration() -> timedelta | None

Get the time the document was edited, as reported by the generator.

(Also available as “self.editing_duration” property.)

Returns:

Type Description
timedelta | None

timedelta | None: The editing duration as a timedelta object, or None if inexistent.

Source code in odfdo/meta.py
590
591
592
593
594
595
596
597
598
599
600
601
602
def get_editing_duration(self) -> timedelta | None:
    """Get the time the document was edited, as reported by the generator.

    (Also available as "self.editing_duration" property.)

    Returns:
        timedelta | None: The editing duration as a timedelta object, or None if inexistent.
    """
    element = self.get_element("//meta:editing-duration")
    if element is None:
        return None
    duration = element.text
    return Duration.decode(duration)

get_generator

get_generator() -> str | None

Get the signature of the software that generated this document.

(Also available as “self.generator” property.)

Returns:

Type Description
str | None

str (or None if inexistent).

Example::

>>> document.meta.get_generator()
KOffice/2.0.0
Source code in odfdo/meta.py
710
711
712
713
714
715
716
717
718
719
720
721
722
723
def get_generator(self) -> str | None:
    """Get the signature of the software that generated this document.

    (Also available as "self.generator" property.)

    Returns:
        str (or None if inexistent).

    Example::

        >>> document.meta.get_generator()
        KOffice/2.0.0
    """
    return self.generator
get_hyperlink_behaviour() -> MetaHyperlinkBehaviour | None

Get the MetaHyperlinkBehaviour “meta:hyperlink-behaviour” element or None.

Returns:

Type Description
MetaHyperlinkBehaviour | None

A MetaHyperlinkBehaviour instance or None.

Source code in odfdo/meta.py
430
431
432
433
434
435
436
437
438
439
440
def get_hyperlink_behaviour(self) -> MetaHyperlinkBehaviour | None:
    """Get the MetaHyperlinkBehaviour "meta:hyperlink-behaviour" element or
    None.

    Returns:
        A MetaHyperlinkBehaviour instance or None.
    """
    element: MetaHyperlinkBehaviour | None = self.get_element(  # type: ignore[assignment]
        "//meta:hyperlink-behaviour"
    )
    return element

get_initial_creator

get_initial_creator() -> str | None

Get the first creator of the document.

(Also available as “self.initial_creator” property.)

Returns:

Type Description
str | None

str | None: The initial creator string, or None if inexistent.

Example::

>>> document.meta.get_initial_creator()
Unknown
Source code in odfdo/meta.py
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
def get_initial_creator(self) -> str | None:
    """Get the first creator of the document.

    (Also available as "self.initial_creator" property.)

    Returns:
        str | None: The initial creator string, or None if inexistent.

    Example::

        >>> document.meta.get_initial_creator()
        Unknown
    """
    element = self.get_element("//meta:initial-creator")
    if element is None:
        return None
    return element.text

get_keywords

get_keywords() -> str | None

Get the keywords of the document. Return the field as-is, without any assumption on the keyword separator.

(Also available as “self.keyword” and “self.keywords” property.)

Returns:

Type Description
str | None

str | None: The keywords string, or None if inexistent.

Source code in odfdo/meta.py
545
546
547
548
549
550
551
552
553
554
555
556
557
def get_keywords(self) -> str | None:
    """Get the keywords of the document. Return the field as-is, without
    any assumption on the keyword separator.

    (Also available as "self.keyword" and "self.keywords" property.)

    Returns:
        str | None: The keywords string, or None if inexistent.
    """
    element = self.get_element("//meta:keyword")
    if element is None:
        return None
    return element.text

get_language

get_language() -> str | None

Get the default language of the document BUT only from the metadata, “dc:language”.

Prefer the Document.get_language() function.

(Also available as “self.language” property.)

Returns:

Type Description
str | None

str | None: The language string, or None if inexistent.

Example::

>>> document.meta.get_language()
fr-FR
Source code in odfdo/meta.py
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
def get_language(self) -> str | None:
    """Get the default language of the document BUT only from the metadata,
    "dc:language".

    Prefer the Document.get_language() function.

    (Also available as "self.language" property.)

    Returns:
        str | None: The language string, or None if inexistent.

    Example::

        >>> document.meta.get_language()
        fr-FR
    """
    element = self.get_element("//dc:language")
    if element is None:
        return None
    return element.text

get_statistic

get_statistic() -> dict[str, int] | None

Get the statistics about a document, “meta:document-statistic” tag.

(Also available as “self.statistic” property.)

Returns:

Type Description
dict[str, int] | None

A dict (or None if inexistent).

Example::

>>> document.get_statistic():
{'meta:table-count': 1,
 'meta:image-count': 2,
 'meta:object-count': 3,
 'meta:page-count': 4,
 'meta:paragraph-count': 5,
 'meta:word-count': 6,
 'meta:character-count': 7,
 'meta:non-whitespace-character-count': 3}
Source code in odfdo/meta.py
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
def get_statistic(self) -> dict[str, int] | None:
    """Get the statistics about a document, "meta:document-statistic" tag.

    (Also available as "self.statistic" property.)

    Returns:
        A dict (or None if inexistent).

    Example::

        >>> document.get_statistic():
        {'meta:table-count': 1,
         'meta:image-count': 2,
         'meta:object-count': 3,
         'meta:page-count': 4,
         'meta:paragraph-count': 5,
         'meta:word-count': 6,
         'meta:character-count': 7,
         'meta:non-whitespace-character-count': 3}
    """
    element = self.get_element("//meta:document-statistic")
    if element is None:
        return None
    statistic = {}
    for key, value in element.attributes.items():
        statistic[to_str(key)] = int(value)
    return statistic

get_subject

get_subject() -> str | None

Get the subject of the document.

(Also available as “self.subject” property.)

Returns:

Type Description
str | None

str | None: The subject string, or None if inexistent.

Source code in odfdo/meta.py
179
180
181
182
183
184
185
186
187
188
189
190
def get_subject(self) -> str | None:
    """Get the subject of the document.

    (Also available as "self.subject" property.)

    Returns:
        str | None: The subject string, or None if inexistent.
    """
    element = self.get_element("//dc:subject")
    if element is None:
        return None
    return element.text

get_template

get_template() -> MetaTemplate | None

Get the MetaTemplate “meta:template” element or None.

Returns:

Type Description
MetaTemplate | None

A MetaTemplate instance or None.

Source code in odfdo/meta.py
355
356
357
358
359
360
361
362
def get_template(self) -> MetaTemplate | None:
    """Get the MetaTemplate "meta:template" element or None.

    Returns:
        A MetaTemplate instance or None.
    """
    element: MetaTemplate | None = self.get_element("//meta:template")  # type: ignore[assignment]
    return element

get_title

get_title() -> str | None

Get the title of the document.

This is not the first heading but the title metadata.

(Also available as “self.title” property.)

Returns:

Type Description
str | None

str | None: The title string, or None if inexistent.

Source code in odfdo/meta.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def get_title(self) -> str | None:
    """Get the title of the document.

    This is not the first heading but the title metadata.

    (Also available as "self.title" property.)

    Returns:
        str | None: The title string, or None if inexistent.
    """
    element = self.get_element("//dc:title")
    if element is None:
        return None
    return element.text

get_user_defined_metadata

get_user_defined_metadata() -> dict[
    str,
    Decimal | datetime | dtdate | timedelta | bool | str,
]

Get all additional user-defined metadata for a document.

(Also available as “self.user_defined_metadata” property.)

Returns:

Type Description
dict[str, Decimal | datetime | date | timedelta | bool | str]

A dict of str/value mapping.

Value types can be: Decimal, datetime, date, timedelta, bool or str.

Source code in odfdo/meta.py
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
def get_user_defined_metadata(
    self,
) -> dict[str, Decimal | datetime | dtdate | timedelta | bool | str]:
    """Get all additional user-defined metadata for a document.

    (Also available as "self.user_defined_metadata" property.)

    Returns:
       A dict of str/value mapping.

    Value types can be: Decimal, datetime, date, timedelta, bool or str.
    """
    return {
        data.name: data.value
        for data in cast(
            list[MetaUserDefined], self.get_elements("//meta:user-defined")
        )
    }

get_user_defined_metadata_of_name

get_user_defined_metadata_of_name(
    keyname: str,
) -> dict[str, Any] | None

Return the content of the user defined metadata of that name. Return None if no name matches or a dic of fields.

Parameters:

Name Type Description Default
keyname str

The name of the user-defined metadata field to find.

required

Returns:

Type Description
dict[str, Any] | None

dict[str, Any]: A dict with keys “name”, “value”, “value_type”, “text”.

Source code in odfdo/meta.py
921
922
923
924
925
926
927
928
929
930
931
932
933
934
def get_user_defined_metadata_of_name(self, keyname: str) -> dict[str, Any] | None:
    """Return the content of the user defined metadata of that name. Return
    None if no name matches or a dic of fields.

    Args:
        keyname: The name of the user-defined metadata field to find.

    Returns:
        dict[str, Any]: A dict with keys "name", "value", "value_type", "text".
    """
    item = self._user_defined_metadata_by_name(keyname)
    if item is None:
        return None
    return item.as_dict_full()

set_auto_reload

set_auto_reload(delay: timedelta, href: str = '') -> None

Set or replace the meta:auto-reload element.

This specifies whether a document is reloaded or replaced by another document after a specified period of time. Any existing meta:auto-reload element will be removed.

Parameters:

Name Type Description Default
delay timedelta

The time delay after which the document should auto-reload.

required
href str

The URL or path to the document to reload or replace with.

''
Source code in odfdo/meta.py
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
def set_auto_reload(self, delay: timedelta, href: str = "") -> None:
    """Set or replace the `meta:auto-reload` element.

    This specifies whether a document is reloaded or replaced by another
    document after a specified period of time. Any existing
    `meta:auto-reload` element will be removed.

    Args:
        delay: The time delay after which the document should auto-reload.
        href: The URL or path to the document to reload or replace with.
    """
    autoreload = MetaAutoReload(delay=delay, href=href)
    current = self.auto_reload
    if isinstance(current, MetaAutoReload):
        current.delete()
    self.body.append(autoreload)

set_creation_date

set_creation_date(date: datetime | None = None) -> None

Set the creation date of the document.

If provided datetime is None, use current time.

(Also available as “self.creation_date” property.)

Parameters:

Name Type Description Default
date datetime | None

The datetime object to set as the creation date.

None
Source code in odfdo/meta.py
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
def set_creation_date(self, date: datetime | None = None) -> None:
    """Set the creation date of the document.

    If provided datetime is None, use current time.

    (Also available as "self.creation_date" property.)

    Args:
        date: The datetime object to set as the creation date.
    """
    element = self.get_element("//meta:creation-date")
    if element is None:
        element = Element.from_tag("meta:creation-date")
        self.body.append(element)
    if date is None:
        date = datetime.now()
    element.text = DateTime.encode(date)

set_description

set_description(description: str) -> None

Set the description of the document. Also known as comments.

(Also available as “self.description” property.)

Parameters:

Name Type Description Default
description str

The description string to set.

required
Source code in odfdo/meta.py
151
152
153
154
155
156
157
158
159
160
161
162
163
def set_description(self, description: str) -> None:
    """Set the description of the document. Also known as comments.

    (Also available as "self.description" property.)

    Args:
        description: The description string to set.
    """
    element = self.get_element("//dc:description")
    if element is None:
        element = Element.from_tag("dc:description")
        self.body.append(element)
    element.text = description

set_editing_cycles

set_editing_cycles(cycles: int) -> None

Set the number of times the document was edited.

(Also available as “self.editing_cycles” property.)

Parameters:

Name Type Description Default
cycles int

The number of editing cycles to set.

required
Source code in odfdo/meta.py
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
def set_editing_cycles(self, cycles: int) -> None:
    """Set the number of times the document was edited.

    (Also available as "self.editing_cycles" property.)

    Args:
        cycles: The number of editing cycles to set.
    """
    if not isinstance(cycles, int):
        raise TypeError("cycles must be an int")
    if cycles < 1:
        raise ValueError("cycles must be a positive int")
    element = self.get_element("//meta:editing-cycles")
    if element is None:
        element = Element.from_tag("meta:editing-cycles")
        self.body.append(element)
    element.text = str(cycles)

set_editing_duration

set_editing_duration(duration: timedelta) -> None

Set the time the document was edited.

(Also available as “self.editing_duration” property.)

Parameters:

Name Type Description Default
duration timedelta

The timedelta object representing the editing duration.

required
Source code in odfdo/meta.py
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
def set_editing_duration(self, duration: timedelta) -> None:
    """Set the time the document was edited.

    (Also available as "self.editing_duration" property.)

    Args:
        duration: The timedelta object representing the editing duration.
    """
    if not isinstance(duration, timedelta):
        raise TypeError("duration must be a timedelta")
    element = self.get_element("//meta:editing-duration")
    if element is None:
        element = Element.from_tag("meta:editing-duration")
        self.body.append(element)
    element.text = Duration.encode(duration)

set_generator

set_generator(generator: str) -> None

Set the signature of the software that generated this document.

(Also available as “self.generator” property.)

Parameters:

Name Type Description Default
generator str

The generator string to set.

required

Example::

>>> document.meta.set_generator("Odfdo experiment")
Source code in odfdo/meta.py
725
726
727
728
729
730
731
732
733
734
735
736
737
def set_generator(self, generator: str) -> None:
    """Set the signature of the software that generated this document.

    (Also available as "self.generator" property.)

    Args:
        generator: The generator string to set.

    Example::

        >>> document.meta.set_generator("Odfdo experiment")
    """
    self.generator = generator

set_generator_default

set_generator_default() -> None

Set the signature of the software that generated this document to ourself.

Example::

>>> document.meta.set_generator_default()
Source code in odfdo/meta.py
739
740
741
742
743
744
745
746
747
748
def set_generator_default(self) -> None:
    """Set the signature of the software that generated this document to
    ourself.

    Example::

        >>> document.meta.set_generator_default()
    """
    if not self._generator_modified:
        self.generator = GENERATOR
set_hyperlink_behaviour(
    target_frame_name: str = "_blank", show: str = "replace"
) -> None

Set or replace the meta:hyperlink-behaviour element.

This specifies the default behavior for hyperlinks in a document. Any existing meta:hyperlink-behaviour element will be removed.

Parameters:

Name Type Description Default
target_frame_name str

The name of the target frame for the hyperlink. Defaults to “_blank” (new window/tab).

'_blank'
show str

Specifies how the target resource is presented. Defaults to “replace”.

'replace'
Source code in odfdo/meta.py
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
def set_hyperlink_behaviour(
    self,
    target_frame_name: str = "_blank",
    show: str = "replace",
) -> None:
    """Set or replace the `meta:hyperlink-behaviour` element.

    This specifies the default behavior for hyperlinks in a document.
    Any existing `meta:hyperlink-behaviour` element will be removed.

    Args:
        target_frame_name: The name of the target frame for the hyperlink.
            Defaults to "_blank" (new window/tab).
        show: Specifies how the target resource is presented.
            Defaults to "replace".
    """
    behaviour = MetaHyperlinkBehaviour(
        target_frame_name=target_frame_name, show=show
    )
    current = self.hyperlink_behaviour
    if isinstance(current, MetaHyperlinkBehaviour):
        current.delete()
    self.body.append(behaviour)

set_initial_creator

set_initial_creator(creator: str) -> None

Set the first creator of the document.

(Also available as “self.initial_creator” property.)

Parameters:

Name Type Description Default
creator str

The creator string to set.

required

Example::

>>> document.meta.set_initial_creator("Plato")
Source code in odfdo/meta.py
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
def set_initial_creator(self, creator: str) -> None:
    """Set the first creator of the document.

    (Also available as "self.initial_creator" property.)

    Args:
        creator: The creator string to set.

    Example::

        >>> document.meta.set_initial_creator("Plato")
    """
    element = self.get_element("//meta:initial-creator")
    if element is None:
        element = Element.from_tag("meta:initial-creator")
        self.body.append(element)
    element.text = creator

set_keywords

set_keywords(keywords: str) -> None

Set the keywords of the document. Although the name is plural, a str string is required, so join your list first.

(Also available as “self.keyword” and “self.keywords” property.)

Parameters:

Name Type Description Default
keywords str

The keywords string to set.

required
Source code in odfdo/meta.py
559
560
561
562
563
564
565
566
567
568
569
570
571
572
def set_keywords(self, keywords: str) -> None:
    """Set the keywords of the document. Although the name is plural, a str
    string is required, so join your list first.

    (Also available as "self.keyword" and "self.keywords" property.)

    Args:
        keywords: The keywords string to set.
    """
    element = self.get_element("//meta:keyword")
    if element is None:
        element = Element.from_tag("meta:keyword")
        self.body.append(element)
    element.text = keywords

set_language

set_language(language: str) -> None

Set the default language of the document BUT only in the metadata, “dc:language”.

To set globally the default language, prefer the Document.set_language() function.

(Also available as “self.language” property.)

Parameters:

Name Type Description Default
language str

The language string to set.

required

Example::

>>> document.meta.set_language('fr-FR')
Source code in odfdo/meta.py
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
def set_language(self, language: str) -> None:
    """Set the default language of the document BUT only in the metadata,
    "dc:language".

    To set globally the default language, prefer the
    Document.set_language() function.

    (Also available as "self.language" property.)

    Args:
        language: The language string to set.

    Example::

        >>> document.meta.set_language('fr-FR')
    """
    language = str(language)
    if not is_RFC3066(language):
        raise TypeError(
            'Language must be "xx" lang or "xx-YY" lang-COUNTRY code (RFC3066)'
        )
    element = self.get_element("//dc:language")
    if element is None:
        element = Element.from_tag("dc:language")
        self.body.append(element)
    element.text = language

set_statistic

set_statistic(statistic: dict[str, int]) -> None

Set the statistics about a document, “meta:document-statistic” tag.

(Also available as “self.statistic” property.)

Parameters:

Name Type Description Default
statistic dict[str, int]

The statistics dictionary to set.

required

Example::

>>> statistic = {'meta:table-count': 1,
                 'meta:image-count': 2,
                 'meta:object-count': 3,
                 'meta:page-count': 4,
                 'meta:paragraph-count': 5,
                 'meta:word-count': 6,
                 'meta:character-count': 7,
                 'meta:non-whitespace-character-count': 3}
>>> document.meta.set_statistic(statistic)
Source code in odfdo/meta.py
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
def set_statistic(self, statistic: dict[str, int]) -> None:
    """Set the statistics about a document, "meta:document-statistic" tag.

    (Also available as "self.statistic" property.)

    Args:
        statistic: The statistics dictionary to set.

    Example::

        >>> statistic = {'meta:table-count': 1,
                         'meta:image-count': 2,
                         'meta:object-count': 3,
                         'meta:page-count': 4,
                         'meta:paragraph-count': 5,
                         'meta:word-count': 6,
                         'meta:character-count': 7,
                         'meta:non-whitespace-character-count': 3}
        >>> document.meta.set_statistic(statistic)
    """
    if not isinstance(statistic, dict):
        raise TypeError("Statistic must be a dict")
    element = self.get_element("//meta:document-statistic")
    if element is None:
        element = Element.from_tag("meta:document-statistic")
        self.body.append(element)
    for key, value in statistic.items():
        try:
            ivalue = int(value)
        except ValueError as e:
            msg = f"Statistic value must be a int: {key}:{value!r}"
            raise TypeError(msg) from e
        element.set_attribute(to_str(key), str(ivalue))

set_subject

set_subject(subject: str) -> None

Set the subject of the document.

(Also available as “self.subject” property.)

Parameters:

Name Type Description Default
subject str

The subject string to set.

required
Source code in odfdo/meta.py
192
193
194
195
196
197
198
199
200
201
202
203
204
def set_subject(self, subject: str) -> None:
    """Set the subject of the document.

    (Also available as "self.subject" property.)

    Args:
        subject: The subject string to set.
    """
    element = self.get_element("//dc:subject")
    if element is None:
        element = Element.from_tag("dc:subject")
        self.body.append(element)
    element.text = subject

set_template

set_template(
    date: datetime | None = None,
    href: str = "",
    title: str = "",
) -> None

Set or replace the meta:template element.

This specifies the document template used to create the current document. Any existing meta:template element will be removed.

Parameters:

Name Type Description Default
date datetime | None

The date and time when the template was used.

None
href str

The URI for the document template (XLink).

''
title str

The title of the document template (XLink).

''
Source code in odfdo/meta.py
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
def set_template(
    self,
    date: datetime | None = None,
    href: str = "",
    title: str = "",
) -> None:
    """Set or replace the `meta:template` element.

    This specifies the document template used to create the current document.
    Any existing `meta:template` element will be removed.

    Args:
        date: The date and time when the template was used.
        href: The URI for the document template (XLink).
        title: The title of the document template (XLink).
    """
    template = MetaTemplate(date=date, href=href, title=title)
    current = self.template
    if isinstance(current, MetaTemplate):
        current.delete()
    self.body.append(template)

set_title

set_title(title: str) -> None

Set the title of the document.

This is not the first heading but the title metadata.

(Also available as “self.title” property.)

Parameters:

Name Type Description Default
title str

The title string to set.

required
Source code in odfdo/meta.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def set_title(self, title: str) -> None:
    """Set the title of the document.

    This is not the first heading but the title metadata.

    (Also available as "self.title" property.)

    Args:
        title: The title string to set.
    """
    element = self.get_element("//dc:title")
    if element is None:
        element = Element.from_tag("dc:title")
        self.body.append(element)
    element.text = title

set_user_defined_metadata

set_user_defined_metadata(
    name: str,
    value: bool
    | int
    | float
    | Decimal
    | datetime
    | date
    | str
    | timedelta
    | None,
) -> None

Set a user defined metadata of that name and value.

If value is None, any existing metadata of that name is deleted.

Parameters:

Name Type Description Default
name str

The name of the user-defined metadata field.

required
value bool | int | float | Decimal | datetime | date | str | timedelta | None

The value to set for the metadata field. Can be a boolean, int, float, Decimal, datetime, date, string, timedelta, or None for deletion.

required
Source code in odfdo/meta.py
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
def set_user_defined_metadata(
    self,
    name: str,
    value: bool
    | int
    | float
    | Decimal
    | datetime
    | dtdate
    | str
    | timedelta
    | None,
) -> None:
    """Set a user defined metadata of that name and value.

    If value is None, any existing metadata of that name is deleted.

    Args:
        name: The name of the user-defined metadata field.
        value: The value to set for the metadata field.
            Can be a boolean, int, float, Decimal, datetime, date, string,
            timedelta, or None for deletion.
    """
    if value is None:
        self.delete_user_defined_metadata_of_name(name)
        return
    value_type = MetaUserDefined._value_to_value_type(value)
    # Already the same element ?
    metadata = self._user_defined_metadata_by_name(name)
    if metadata is None:
        metadata = MetaUserDefined(name=name, value_type=value_type, value=value)
        self.body.append(metadata)
    else:
        metadata.value_type = value_type
        metadata.value = value

strip

strip(
    generator: str = GENERATOR,
    creation_date: datetime | None = None,
) -> None

Strip metadata to their minimal content.

All user defined metadata are removed.

Parameters:

Name Type Description Default
generator str

String for the meta:generator field.

GENERATOR
creation_date datetime | None

Datetime or None, meta:creation-date value.

None
Source code in odfdo/meta.py
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
def strip(
    self,
    generator: str = GENERATOR,
    creation_date: datetime | None = None,
) -> None:
    """Strip metadata to their minimal content.

    By default the new metadata values are:
        - meta:creation-date: use current time,
        - dc:date: use creation date,
        - meta:editing-duration: set to zero,
        - meta:editing-cycles: set to 1,
        - meta:generator: use odfdo generator string.
        - all meta:document-statistic values to 0.

    All user defined metadata are removed.

    Args:
        generator: String for the meta:generator field.
        creation_date: Datetime or None, meta:creation-date value.
    """

    self.body.clear()
    self.statistic = self._complete_stats({}, None)
    if creation_date is None:
        self.creation_date = datetime.now().replace(microsecond=0)
    else:
        self.creation_date = creation_date.replace(microsecond=0)
    self.date = self.creation_date
    self.editing_duration = timedelta(0)
    self.editing_cycles = 1
    self.generator = generator
    self.clear_user_defined_metadata()