Skip to content

omnipy.data.dataset

Typed dataset containers and dataset type predicates.

This module defines :class:Dataset, the core Omnipy container for named data items that all share the same model or nested dataset type. It also provides helper predicates for checking dataset instances and subclasses in a lenient way that works with the library's generic types.

CLASS DESCRIPTION
Dataset

Store named, typed data items in a dict-like container.

FUNCTION DESCRIPTION
is_dataset_instance

Return whether an object is a dataset instance.

is_dataset_subclass

Return whether a type form is a dataset subclass.

ATTRIBUTE DESCRIPTION
dict_t

Dataset

Bases: DatasetDisplayMixin, TaskDatasetMixin, DataClassBase, pyd.GenericModel, UserDict[str, _ModelOrDatasetT], Generic[_ModelOrDatasetT]


              flowchart BT
              omnipy.data.dataset.Dataset[Dataset]
              omnipy.data._mixins.display.DatasetDisplayMixin[DatasetDisplayMixin]
              omnipy.data._mixins.display.BaseDisplayMixin[BaseDisplayMixin]
              omnipy.data._mixins.task.TaskDatasetMixin[TaskDatasetMixin]
              omnipy.data._data_class_creator.DataClassBase[DataClassBase]

                              omnipy.data._mixins.display.DatasetDisplayMixin --> omnipy.data.dataset.Dataset
                                omnipy.data._mixins.display.BaseDisplayMixin --> omnipy.data._mixins.display.DatasetDisplayMixin
                

                omnipy.data._mixins.task.TaskDatasetMixin --> omnipy.data.dataset.Dataset
                
                omnipy.data._data_class_creator.DataClassBase --> omnipy.data.dataset.Dataset
                
                omnipy.util.pydantic.GenericModel --> omnipy.data.dataset.Dataset
                


              click omnipy.data.dataset.Dataset href "" "omnipy.data.dataset.Dataset"
              click omnipy.data._mixins.display.DatasetDisplayMixin href "" "omnipy.data._mixins.display.DatasetDisplayMixin"
              click omnipy.data._mixins.display.BaseDisplayMixin href "" "omnipy.data._mixins.display.BaseDisplayMixin"
              click omnipy.data._mixins.task.TaskDatasetMixin href "" "omnipy.data._mixins.task.TaskDatasetMixin"
              click omnipy.data._data_class_creator.DataClassBase href "" "omnipy.data._data_class_creator.DataClassBase"
            

Store named, typed data items in a dict-like container.

Dataset is Omnipy's core container for collections of data items that all conform to the same model type, or to the same nested dataset type. The class must be specialized before use, for example as Dataset[Model[list[int]]] or Dataset[MyModel].

Instances behave much like mutable dictionaries whose keys are data-file names and whose values are validated model or dataset objects. The validated backing contents live in :attr:data, while convenience methods such as :meth:from_data, :meth:to_data, :meth:to_json, and :meth:load expose plain-Python, JSON, and serialized representations.

Item access supports both ordinary dictionary-style keys and dataset-specific selectors such as integer positions, slices, and iterables of keys or positions. Singular selection returns one validated item; plural selection returns a new dataset of the same specialized class.

ATTRIBUTE DESCRIPTION
data

Mapping from data-file names to validated model or nested dataset instances.

TYPE: dict_t[str, _ModelOrDatasetT]

Example

from omnipy.data.model import Model Numbers = Dataset[Model[int]] Numbers({'one': 1}).to_data() {'one': 1}

CLASS DESCRIPTION
Config

Configure Pydantic behavior for dataset instances.

METHOD DESCRIPTION
__init__
absorb

Merge another dataset's contents into this dataset.

absorb_and_replace

Replace this dataset's contents with another dataset's contents.

as_multi_model_dataset

Return a multi-model view of this dataset.

browse

Opens the model or dataset in a browser, if possible.

clone_dataset_cls

Create a new dataset subclass based on this dataset class.

copy

Copy the dataset.

deepcopy_context

Delegate nested deepcopy bookkeeping to the shared data-class creator.

default_repr_to_terminal_str

Render the default display panel as terminal text.

dict

Return the dataset backing mapping as a plain dictionary.

do

Apply a callable placeholder to each item and collect the results in a new dataset.

failed_task_details

Return failure marker payloads keyed by dataset entry name.

from_data

Populate the dataset from plain Python contents.

from_json

Populate the dataset from per-item JSON strings.

full

Display the content of the Model or Dataset in full height.

get_type

Return the concrete item type stored by this dataset class.

json

Preview the data content of the Model or Dataset as JSON.

list

Displays a summary list of all models in the dataset.

load

Create a dataset and load serialized contents into it.

load_into

Load serialized contents into this dataset instance.

peek

Display a preview of the Model or Dataset content.

pending_task_details

Return pending task marker payloads keyed by dataset entry name.

save

Serialize the dataset to a .tar.gz archive and extract a directory copy.

to

Convert this dataset to another model or dataset class.

to_data

Return the dataset as plain Python contents.

to_json

Serialize each dataset item to JSON.

to_json_schema

Return a JSON schema for the dataset's serialized contents.

update_forward_refs

Try to update ForwardRefs on fields based on this Model, globalns and localns.

update_reactive_views
validate

Validate arbitrary input as an instance of this dataset class.

Source code in src/omnipy/data/dataset.py
 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
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
class Dataset(
        DatasetDisplayMixin,
        TaskDatasetMixin,
        DataClassBase,
        pyd.GenericModel,
        UserDict[str, _ModelOrDatasetT],
        Generic[_ModelOrDatasetT],
        metaclass=_DatasetMetaclass):
    """Store named, typed data items in a dict-like container.

    ``Dataset`` is Omnipy's core container for collections of data items that all conform to the
    same model type, or to the same nested dataset type. The class must be specialized before use,
    for example as ``Dataset[Model[list[int]]]`` or ``Dataset[MyModel]``.

    Instances behave much like mutable dictionaries whose keys are data-file names and whose values
    are validated model or dataset objects. The validated backing contents live in :attr:`data`,
    while convenience methods such as :meth:`from_data`, :meth:`to_data`, :meth:`to_json`, and
    :meth:`load` expose plain-Python, JSON, and serialized representations.

    Item access supports both ordinary dictionary-style keys and dataset-specific selectors such as
    integer positions, slices, and iterables of keys or positions. Singular selection returns one
    validated item; plural selection returns a new dataset of the same specialized class.

    Attributes:
        data: Mapping from data-file names to validated model or nested dataset instances.

    Example:
        >>> from omnipy.data.model import Model
        >>> Numbers = Dataset[Model[int]]
        >>> Numbers({'one': 1}).to_data()
        {'one': 1}

    """
    class Config:
        """Configure Pydantic behavior for dataset instances.

        The nested config enables assignment-time validation and permits arbitrary runtime types
        needed by Omnipy's dataset internals.

        Attributes:
            validate_assignment: Re-validate fields whenever attributes are reassigned.
            arbitrary_types_allowed: Permit non-Pydantic helper types in the model definition.
        """
        validate_assignment = True
        arbitrary_types_allowed = True

        # TODO: Use json serializer package from the pydantic config instead of 'json'

        # json_loads = orjson.loads
        # json_dumps = orjson_dumps

    if TYPE_CHECKING:
        data: dict_t[str, _ModelOrDatasetT] = pyd.Field(default={})

    else:

        # TODO: For pydantic v2, remove hack in Dataset to stop e.g.
        #       [{'a': 'b', 'c': 'd'}] to be coerced into {'a': 'c'} (remove
        #       first part of the union below, and edit get_type() and to_json_schema())
        data: list[dict_t[str, _ModelOrDatasetT]] | dict_t[str, _ModelOrDatasetT] = pyd.Field(
            default={})

    # data: dict[str, _ModelOrDatasetT] = pyd.Field(default={})

    def __class_getitem__(  # type: ignore[override]
        cls,
        params: type[_ModelOrDatasetT] | tuple[type[_ModelOrDatasetT]]
        | tuple[type[_ModelOrDatasetT], Any] | TypeVar
        | tuple[TypeVar, ...],
    ) -> Self:
        """Specialize the dataset class with a concrete model or nested dataset type.

        Args:
            params: The model type, dataset type, union of such types, or type variable used to
                parameterize the dataset.

        Returns:
            A specialized ``Dataset`` subclass bound to the supplied item type.

        Raises:
            TypeError: If the supplied type argument is not a supported model or dataset type.
        """
        # TODO: change model type to params: Type[Any] | tuple[Type[Any], ...]
        #       as in GenericModel.

        _params = cls._prepare_params(params)
        orig_params = cls._clean_type(_params)

        if cls == Dataset:
            for type_variant in split_to_union_variants(orig_params):
                from omnipy.data.model import is_model_subclass

                if (not isinstance(type_variant,
                                   (TypeVar, str)) and not is_model_subclass(type_variant)
                        and not is_dataset_subclass(type_variant)):
                    cls._raise_type_exception(f'Invalid model: {orig_params} ')
        else:
            if isinstance(orig_params, TypeVar):
                _params = get_default_if_typevar(orig_params)

        created_dataset = super().__class_getitem__(_params)
        cls._recursively_set_allow_none(created_dataset._get_data_field())
        cleanup_name_qualname_and_module(cls, created_dataset, orig_params)

        return cast(Self, created_dataset)

    @call_super_if_available(call_super_before_method=True)
    @classmethod
    def _clean_type(cls, _type: TypeForm) -> TypeForm:
        """Normalize a dataset item type before it is cached or exposed.

        Subclasses can override this hook to rewrite forward references or other type forms before
        the dataset stores them as its effective item type.

        Args:
            _type: Candidate model or dataset type form.

        Returns:
            The normalized type form.
        """
        return _type

    def __init__(  # noqa: C901
        self,
        value: Mapping[str, object] | Iterable[tuple[str, object]] | UndefinedType = Undefined,
        *,
        data: Mapping[str, object] | UndefinedType = Undefined,
        **kwargs: object,
    ) -> None:
        from omnipy.data.model import is_model_instance, is_pure_pydantic_model

        # TODO: Error message when forgetting parenthesis when creating Dataset should be improved.
        #       Unclear where this can be done, if anywhere? E.g.:
        #           a = Dataset[Model[int]]
        #           a['adsfas'] = 2
        #           Traceback (most recent call last):
        #             ...
        #           TypeError: 'ModelMetaclass' object does not support item assignment
        #
        # TODO: Disallow e.g.:
        #       Dataset[Model[str]](Model[int](5)) ==  Dataset[Model[str]](data=Model[int](5))
        #       == Dataset[Model[str]](data={'__root__': Model[str]('5')})

        super_kwargs = {}

        assert DATA_KEY not in kwargs, \
            ('Not allowed with "data" as kwargs key. Not sure how you managed this? Are you trying '
             'to break Dataset init on purpose?')

        if value != Undefined:
            assert data == Undefined, \
                'Not allowed to combine positional and "data" keyword argument'
            assert len(kwargs) == 0, \
                'Not allowed to combine positional and keyword arguments'
            super_kwargs[DATA_KEY] = value

        if data != Undefined:
            assert len(kwargs) == 0, \
                f"Not allowed to combine '{DATA_KEY}' with other keyword arguments"
            super_kwargs[DATA_KEY] = data

        if kwargs:
            if DATA_KEY not in super_kwargs:
                super_kwargs[DATA_KEY] = kwargs
                kwargs = {}

        _type = self.get_type()
        if _type == _ModelOrDatasetT:  # type: ignore[misc]
            self._raise_type_exception()

        def _validate_any_models_or_datasets(
                iterable_data: Iterable[tuple[str, object]]) -> tuple[dict, bool]:
            """Validate model or dataset instances found in iterable input data.

            Args:
                iterable_data: Iterable of ``(key, value)`` pairs supplied to dataset
                    initialization.

            Returns:
                A tuple containing the prepared mapping and a flag indicating whether any input
                values were already model or dataset instances.
            """

            prepared_data = {}
            _model_or_dataset_as_input: bool = False

            for key, val in iterable_data:
                if is_model_instance(val):
                    _model_or_dataset_as_input = True
                    prepared_data[key] = self._validate_value_for_data_file(key, val)
                else:
                    prepared_data[key] = val
            return prepared_data, _model_or_dataset_as_input

        model_or_dataset_as_input = False
        if DATA_KEY in super_kwargs:
            input_data = super_kwargs[DATA_KEY]
            for_type_check = input_data.content if is_model_instance(input_data) else input_data
            match for_type_check:
                case Dataset():
                    model_or_dataset_as_input = True
                    super_kwargs[DATA_KEY] = cast(Dataset, input_data).to_data()
                case _input_data if is_pure_pydantic_model(_input_data):
                    super_kwargs[DATA_KEY], model_or_dataset_as_input = (
                        _validate_any_models_or_datasets(_input_data.dict().items()))
                case Mapping():
                    super_kwargs[DATA_KEY], model_or_dataset_as_input = (
                        _validate_any_models_or_datasets(cast(Mapping, input_data).items()))
                case Iterable():
                    try:
                        super_kwargs[DATA_KEY], model_or_dataset_as_input = (
                            _validate_any_models_or_datasets(self._check_iterable(input_data)))
                    except (TypeError, ValueError) as e:
                        raise TypeError(
                            'Data object must be a mapping or an iterable of '
                            '(key, val) pairs',
                            self.__class__) from e

                case _:
                    ...

        self._init(super_kwargs, **kwargs)

        try:
            self._primary_validation(super_kwargs)
        except ValidationError:
            if model_or_dataset_as_input:
                self._secondary_validation_from_data(super_kwargs)
            else:
                raise

        if not self.__doc__:
            self._set_standard_field_description()

    def _primary_validation(self, super_kwargs):
        """Run the primary Pydantic validation pass for dataset initialization.

        Args:
            super_kwargs: Keyword arguments prepared for ``pydantic.GenericModel.__init__()``.

        Returns:
            ``None``.

        Raises:
            ValidationError: If the prepared dataset payload does not validate.
        """
        # Pydantic validation of super_kwargs
        super().__init__(**super_kwargs)

    def _secondary_validation_from_data(self, super_kwargs):
        """Retry initialization by parsing the prepared payload via ``from_data()``.

        Args:
            super_kwargs: Keyword arguments containing the prepared dataset payload.

        Raises:
            ValidationError: If parsing the prepared payload still fails validation.
        """
        super().__init__()
        self.from_data(super_kwargs[DATA_KEY])

    def _init(self, super_kwargs: dict_t[str, Any], **kwargs: Any) -> None:
        """Provide a subclass hook that runs before dataset validation.

        The base implementation is intentionally empty. Specialized datasets can override this hook
        to adjust initialization arguments before the primary validation pass runs.

        Args:
            super_kwargs: Keyword arguments prepared for the base Pydantic initializer.
            **kwargs: Remaining keyword arguments passed to dataset construction.

        """
        ...

    # TODO: Revise with pydantic v2: __deepcopy__ is not defined for Dataset and Model, as it is not
    #       supported by pydantic v1. BaseModel.copy(deep=True) does not support a deepcopy memo.
    #       So we instead make use of the builtin support for deepcopy, which seems to work fine.
    #       However, __deepcopy__ in pydantic v2 is probably more efficient due to the memo and
    #       the Rust backend.

    def __copy__(self):
        """Return a shallow copy of the dataset.

        The copied dataset receives a new top-level mapping while reusing the same validated item
        objects.

        Returns:
            A new dataset instance with a shallow copy of the backing mapping.
        """
        return self.copy(deep=False)

    def copy(self, *, deep: bool = False, **kwargs) -> Self:
        """Copy the dataset.

        Args:
            deep: Whether to deep-copy nested values as well as the dataset object.
            **kwargs: Additional keyword arguments forwarded to Pydantic's ``copy()``.

        Returns:
            A copied dataset instance of the same specialized class.
        """
        pydantic_copy = pyd.GenericModel.copy(self, deep=deep, **kwargs)
        if not deep:
            object.__setattr__(pydantic_copy, DATA_KEY, pydantic_copy.__dict__[DATA_KEY].copy())

        return pydantic_copy  # pyright: ignore [reportReturnType]

    @classmethod
    def clone_dataset_cls(cls,
                          new_dataset_cls_name: str,
                          model_cls: type[_NewModelT] | None = None) -> type[Self]:
        """Create a new dataset subclass based on this dataset class.

        Args:
            new_dataset_cls_name: Name of the generated dataset subclass.
            model_cls: Optional replacement item model for the generated subclass.

        Returns:
            A newly created dataset subclass.
        """
        if model_cls:
            generic_dataset_cls = cls.__bases__[0]
            new_base_cls = generic_dataset_cls[model_cls]  # type: ignore[index]
        else:
            new_base_cls = cls

        new_dataset_cls = type(new_dataset_cls_name, (new_base_cls,), {})
        return new_dataset_cls

    @classmethod
    def _get_data_field(cls) -> pyd.ModelField:
        """Return the Pydantic field object that stores dataset contents.

        Returns:
            The Pydantic model field representing the ``data`` attribute.
        """
        return cast(pyd.ModelField, cls.__fields__.get(DATA_KEY))

    @classmethod
    @functools.cache
    def get_type(cls) -> type[_ModelOrDatasetT]:
        """Return the concrete item type stored by this dataset class.

        Returns:
            The specialized model or nested dataset class used for every item in the dataset.
        """
        # Part of pydantic v1 hack to stop coercing of e.g.
        # [{'a': 'b', 'c': 'd'}] to {'a': 'c'}
        return cls._clean_type(cls._get_data_field().sub_fields[1].type_)  # type: ignore[index]
        # return cls._clean_type(cls._get_data_field().type_)

    @classmethod
    def _clean_type_caches(cls):
        cls.get_type.cache_clear()

    @staticmethod
    def _raise_type_exception(prefix_msg: str = '') -> None:
        """Raise the standard error for unspecialized dataset classes.

        Args:
            prefix_msg: Optional message prepended before the standard guidance text.

        Raises:
            TypeError: Always raised to explain how a dataset must be specialized.
        """
        msg = dedent("""\
            The Dataset class requires a concrete type (e.g. a Model class
            or a subclass) to be specified as a type hierarchy within
            brackets either directly, e.g.:

              model = Dataset[Model[list[int]]]()

            or indirectly in a subclass definition, e.g.:

              class MyNumberListDataset(Dataset[Model[list[int]]]): ...

            For anything other than the simplest cases, the definition of
            Model and Dataset subclasses is encouraged , e.g.:

              class MyNumberListModel(Model[list[int]]): ...
              class MyDataset(Dataset[MyNumberListModel]): ...

            Alternatively, a dataset can nest another dataset instead of a
            model, e.g.:

              class MyNestedDataset(Dataset[Dataset[Model[list[int]]]]): ...

            Note that at the bottom of the dataset nesting hierarchy, a
            Model class must always be specified.

            Unions of Model or Dataset classes are also supported, e.g.:

              model = Dataset[Model[int] | StrModel]()""")
        if prefix_msg:
            msg = prefix_msg + '\n\n' + msg
        raise TypeError(msg)

    def _set_standard_field_description(self) -> None:
        self.__fields__[DATA_KEY].field_info.description = self._get_standard_field_description()

    @classmethod
    def _get_standard_field_description(cls) -> str:
        """Return the default description text used for the dataset ``data`` field.

        Returns:
            The standard descriptive text for the dataset backing field.
        """
        return ('This class represents a dataset in the `omnipy` Python package and contains '
                'a set of named data items that follows the same data model. '
                'It is a statically typed specialization of the Dataset class according to a '
                'particular specialization of the Model class. Both main classes are wrapping '
                'the excellent Python package named `pydantic`.')

    if TYPE_CHECKING:  # noqa: C901

        # The code below is a hack needed because of a fundamental limitation of the current Python
        # typing syntax. There is no way (that we know of) to tell the type checkers that Model
        # objects can mimic the functionality of their type arguments, say that a Model[list] can
        # mimic a list. What we were aiming to do as a lesser hack was to tell to the type checkers
        # that the Model objects can be considered as inheriting from both the Model class
        # and the type argument class, e.g. Model[list] and list, but in a general way, using type
        # variables. As a workaround, we have to overload the Model.__new__ and Dataset.__getitem__
        # methods for the most important types.

        @overload
        def __getitem__(
            self: 'Dataset[Model[float]]',
            selector: str | int,
        ) -> Model_float:
            """Describe float-model item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected ``Model[float]`` item.
            """
            ...

        @overload
        def __getitem__(
            self: 'Dataset[Model[int]]',
            selector: str | int,
        ) -> Model_int:
            """Describe int-model item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected ``Model[int]`` item.
            """
            ...

        @overload
        def __getitem__(
            self: 'Dataset[Model[bool]]',
            selector: str | int,
        ) -> Model_bool:
            """Describe bool-model item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected ``Model[bool]`` item.
            """
            ...

        @overload
        def __getitem__(
            self: 'Dataset[Model[str]]',
            selector: str | int,
        ) -> Model_str:
            """Describe string-model item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected ``Model[str]`` item.
            """
            ...

        @overload
        def __getitem__(
            self: 'Dataset[Model[bytes]]',
            selector: str | int,
        ) -> Model_bytes:
            """Describe bytes-model item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected ``Model[bytes]`` item.
            """
            ...

        @overload
        def __getitem__(
            self: 'Dataset[Model[set[_ValT]]]',
            selector: str | int,
        ) -> Model_set[_ValT]:
            """Describe set-model item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected ``Model[set[_ValT]]`` item.
            """
            ...

        @overload
        def __getitem__(
            self: 'Dataset[Model[list[_ValT]]]',
            selector: str | int,
        ) -> Model_list[_ValT]:
            """Describe list-model item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected ``Model[list[_ValT]]`` item.
            """
            ...

        @overload
        def __getitem__(
            self: 'Dataset[Model[tuple[_ValT, ...]]]',
            selector: str | int,
        ) -> Model_tuple_same_type[_ValT]:
            """Describe homogeneous-tuple item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected ``Model[tuple[_ValT, ...]]`` item.
            """
            ...

        @overload
        def __getitem__(
            self: 'Dataset[Model[tuple[_ValT, _ValT2]]]',
            selector: str | int,
        ) -> Model_tuple_pair[_ValT, _ValT2]:
            """Describe pair-tuple item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected ``Model[tuple[_ValT, _ValT2]]`` item.
            """
            ...

        @overload
        def __getitem__(
            self: 'Dataset[Model[dict_t[_KeyT, _ValT]]]',
            selector: str | int,
        ) -> Model_dict[_KeyT, _ValT]:
            """Describe dict-model item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected ``Model[dict[_KeyT, _ValT]]`` item.
            """
            ...

        # For better typing of NestedDataset and similar. Will always type
        # as if a nested Dataset is returned, thus will be wrong for the
        # terminal Model case (only when multiple __getitem__ are chained,
        # e.g.:
        #   nested_dataset = Dataset[Dataset[Model[list[int]]]](...)
        #   nested_dataset['a'][0] = 5  # <- here the type checker will
        #                               #    think nested_dataset['a'] is a
        #                               #    Dataset, not a Model[list[int]]

        @overload
        def __getitem__(
            self: 'Dataset[Model[Dataset[_ModelT]]]',
            selector: str | int,
        ) -> Model_Dataset[_ModelT]:
            """Describe nested-dataset model access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected nested dataset model item.
            """
            ...

        @overload
        def __getitem__(
            self: 'Dataset[_DatasetT | _ModelT ]',
            selector: str | int,
        ) -> _DatasetT:
            """Describe union item access that narrows to a nested dataset.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected nested dataset instance.
            """
            ...

        @overload
        def __getitem__(
            self: 'Dataset[_DatasetT | _ModelT | _Model2T]',
            selector: str | int,
        ) -> _DatasetT:
            """Describe three-way union item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected nested dataset instance.
            """
            ...

        @overload
        def __getitem__(
            self: 'Dataset[_DatasetT | _ModelT | _Model2T | _Model3T]',
            selector: str | int,
        ) -> _DatasetT:
            """Describe four-way union item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected nested dataset instance.
            """
            ...

        @overload
        def __getitem__(
            self: 'Dataset[_DatasetT | _ModelT | _Model2T | _Model3T | _Model4T]',
            selector: str | int,
        ) -> _DatasetT:
            """Describe five-way union item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected nested dataset instance.
            """
            ...

        # Even though these two overloads overlap, they are needed in this
        # order to solve typing for both nested and regular Dataset cases.

        @overload
        def __getitem__(  # type: ignore[overload-overlap]
            self: 'Dataset[_ModelOrDatasetT]',
            selector: str | int,
        ) -> _ModelOrDatasetT:
            """Describe general singular item access for static type checkers.

            Args:
                selector: Data-file key or positional index selecting one item.

            Returns:
                The selected validated dataset item.
            """
            ...

        # The only thing that should really be needed – if Python type hints would have able to
        # describe that Model objects can dynamically inherit from their type arguments. This would
        # at least go some way towards what we really want, which is a way to describe exactly the
        # way Model objects mimic the functionality of their type arguments.
        #
        # @overload
        # def __getitem__(self, selector: str | int) -> _ModelOrDatasetT:
        #     ...

        @overload
        def __getitem__(self, selector: slice | Iterable[str | int]) -> Self:
            """Describe plural item selection for static type checkers.

            Args:
                selector: Slice or iterable selecting multiple items.

            Returns:
                A dataset of the same specialized class containing the selected items.
            """
            ...

    def __getitem__(
        self,
        selector: str | int | slice | Iterable[str | int],
    ) -> '_DatasetT | _ModelOrDatasetT | Model | Self':
        """Return one item or a selected subset of the dataset.

        Args:
            selector: A data-file key, positional index, slice, or iterable of keys and/or
                indices.

        Returns:
            The selected validated item for singular selection, or a new dataset containing the
            selected items for plural selection.
        """
        selected_keys = select_keys(selector, self.data)

        if selected_keys.singular:
            value: _ModelOrDatasetT | Self = self.data[selected_keys.keys[0]]
        else:
            value = self.__class__({key: self.data[key] for key in selected_keys.keys})

        return self._check_value(value)

    @call_super_if_available(call_super_before_method=True)
    def _check_value(self, value: Any) -> Any:
        """Post-process a selected value before returning it.

        Subclasses can override this hook to unwrap or adapt validated values returned from the
        dataset API.

        Args:
            value: Selected validated item or dataset subset.

        Returns:
            The value to expose to the caller.
        """
        return value

    def __delitem__(self, selector: str | int | slice | Iterable[str | int]) -> None:
        """Delete one or more items selected from the dataset.

        Args:
            selector: A data-file key, positional index, slice, or iterable of keys and/or
                indices.
        """
        selected_keys = select_keys(selector, self.data)

        if selected_keys.singular:
            del self.data[selected_keys.keys[0]]
        else:
            prev_data = copy(self.data)

            try:
                for key in selected_keys.keys:
                    del self.data[key]
            except Exception:
                self.data = prev_data
                raise

    @overload
    def __setitem__(self, selector: str | int, data_obj: object) -> None:
        """Describe singular assignment for static type checkers.

        Args:
            selector: Data-file key or positional index selecting one item.
            data_obj: Single value assigned to the selected item.

        """
        ...

    @overload
    def __setitem__(self,
                    selector: slice | Iterable[str | int],
                    data_obj: Mapping[str, object] | Iterable[object]) -> None:
        """Describe plural assignment for static type checkers.

        Args:
            selector: Slice or iterable selecting multiple items.
            data_obj: Mapping or iterable providing replacement values.

        """
        ...

    def __setitem__(
        self,
        selector: str | int | slice | Iterable[str | int],
        data_obj: object | Mapping[str, object] | Iterable[object],
    ) -> None:
        """Assign one or more items and validate them against the dataset type.

        Args:
            selector: A data-file key, positional index, slice, or iterable of keys and/or
                indices.
            data_obj: A single replacement item for singular selection, or mapping/iterable data
                for plural selection.

        Raises:
            TypeError: If plural assignment receives a value that is neither a mapping nor an
                iterable.
            ValidationError: If any assigned item fails dataset validation.
        """
        selected_keys = select_keys(selector, self.data)

        if selected_keys.singular:
            self._set_data_file_and_validate(selected_keys.keys[0],
                                             cast(_ModelOrDatasetT, data_obj))
        else:
            key_2_data_item: Key2DataItemType[object]
            index_2_data_items: Index2DataItemsType[object]

            if isinstance(data_obj, MutableMapping):
                key_2_data_item, index_2_data_items = \
                    prepare_selected_items_with_mapping_data(
                        selected_keys.keys, selected_keys.last_index,
                        cast(Mapping[str, object], data_obj),
                    )

            elif is_iterable(data_obj) and not isinstance(data_obj, (str, bytes)):
                key_2_data_item, index_2_data_items = \
                    prepare_selected_items_with_iterable_data(
                        selected_keys.keys, selected_keys.last_index, tuple(data_obj),
                        cast(Mapping[str, object], self.data),
                    )

            else:
                raise TypeError('Data object must be a mapping or an iterable')

            self._update_selected_items_with_data_items(key_2_data_item, index_2_data_items)

    def _update_selected_items_with_data_items(
        self,
        key_2_data_item: Key2DataItemType[object],
        index_2_data_item: Index2DataItemsType[object],
    ) -> None:
        """Apply prepared replacement values to the currently selected dataset items.

        Args:
            key_2_data_item: Replacement values keyed directly by data-file name.
            index_2_data_item: Replacement values keyed by positional index.

        Raises:
            ValidationError: If the updated dataset contents fail validation.
        """

        updated_mapping = create_updated_mapping(
            cast(MutableMapping[str, object], self.data), key_2_data_item,
            index_2_data_item)  # pyright: ignore [reportUndefinedVariable]
        self._replace_data_with_mapping(updated_mapping)

    def _replace_data_with_mapping(self, updated_mapping: MutableMapping[str, object]) -> None:
        """Replace the dataset contents atomically using a prepared mapping.

        Args:
            updated_mapping: Candidate full mapping to validate and install.

        Raises:
            ValidationError: If the replacement mapping does not validate for this dataset type.
        """
        prev_data = self.data
        try:
            self.absorb_and_replace(self.__class__(updated_mapping))
        except Exception:
            self.data = prev_data
            raise

    def _set_data_file_and_validate(self, key: str, val: _ModelOrDatasetT) -> None:
        """Assign one dataset item and roll back if validation fails.

        Args:
            key: Data-file name to insert or replace.
            val: Candidate validated or raw item value.

        Raises:
            ValidationError: If the inserted value does not validate for this dataset type.
        """
        has_prev_value = key in self.data
        if has_prev_value:
            prev_value = self.data[key]

        try:
            self.data[key] = val
            self._validate_data_file(key)
        except Exception:
            if has_prev_value:
                self.data[key] = prev_value
            else:
                del self.data[key]
            raise

    @classmethod
    def _check_iterable(cls, iterable: Iterable[Any]) -> Iterable[Any]:
        """Normalize iterable input into an iterator of ``(key, value)`` pairs.

        Args:
            iterable: Candidate outer iterable supplied as dataset input.

        Returns:
            An iterator yielding normalized ``(key, value)`` pairs.

        Raises:
            TypeError: If the iterable shape is incompatible with dataset initialization.
        """
        if isinstance(iterable, (str, bytes)):
            raise TypeError(
                'Outer data iterables cannot be strings or, '
                'bytes, got: {type(value)}', cls)

        def check_iterable_elements(iterable: Iterable) -> Iterator:
            """Validate and normalize each element of an outer dataset iterable.

            Args:
                iterable: Iterable whose elements should each describe one ``(key, value)`` pair.

            Returns:
                An iterator over normalized ``(key, value)`` pairs.

            Raises:
                TypeError: If any element is not a list-like or tuple-like key-value pair.
            """
            for el in iterable:
                if not isinstance(el, (tuple, list)):
                    raise TypeError(
                        'Inner data iterable elements must be '
                        '(key, val) pairs, as tuples or lists, '
                        f'not: {type(el)}',
                        cls)
                if isinstance(el, Mapping):
                    yield from el.items()
                else:
                    yield el

        return check_iterable_elements(iterable)

    @classmethod
    def validate(cls, value: Any) -> Self:
        """Validate arbitrary input as an instance of this dataset class.

        This method is primarily part of the Pydantic integration layer and preserves dataset
        validation behavior when iterables are accepted as input.

        Args:
            value: The value to validate.

        Returns:
            A validated dataset instance.
        """
        # TODO: Doublecheck if validate() method is still needed for pydantic v2

        # validate_cls_counts[cls.__name__] += 1
        if is_iterable(value) and not isinstance(value, Mapping):
            value = cls._check_iterable(value)

        return super().validate({'data': value})

    # TODO: Improve DRY of Model.update_forward_refs() and Dataset.update_forward_refs()
    @classmethod
    def update_forward_refs(
        cls,
        calling_module: str | None = None,
        prev_visited_classes: set[type] | None = None,
        **localns: Any,
    ) -> None:
        """
        Try to update ForwardRefs on fields based on this Model, globalns and localns.
        """

        from omnipy.data.model import is_model_subclass

        if prev_visited_classes is None:
            prev_visited_classes = set()
        elif cls in prev_visited_classes:
            return

        # Merge the namespaces of the Datasets's own module and the
        # calling module to the local namespace for evaluation of forward
        # references, which is necessary for cases where the Dataset is
        # defined in a different module than where it is used, e.g. when
        # the Dataset is defined in a library and used by a user in their
        # own code.
        if calling_module is None:
            calling_module = get_calling_module_name()
        own_module_ns, globalns = \
            build_own_module_and_global_namespace_for_forward_refs(cls, calling_module, **localns)

        prev_type = cls._get_data_field().type_

        super().update_forward_refs(**globalns)

        cls._get_data_field().type_ = evaluate_any_forward_refs_if_possible(prev_type, **globalns)
        if DATA_KEY in cls.__annotations__:
            cls.__annotations__[DATA_KEY] = evaluate_any_forward_refs_if_possible(
                cls.__annotations__[DATA_KEY], **globalns)

        cls._clean_type_caches()

        prev_visited_classes.add(cls)

        # Merge the Dataset's own module namespace into
        # localns before propagating. This is to allow Model classes and
        # pydantic-generated parametrized base classes (which have
        # __module__='omnipy.data.dataset' rather than the defining
        # module) to still resolve forward refs that only exist
        # in the defining module's namespace.

        extra_ns: dict[str, Any] = {}
        extra_ns.update(own_module_ns)
        extra_ns.update(localns)

        # Propagate update_forward_refs to parent Dataset classes but
        # retaining the same calling module. This is needed to ensure the
        # correct context is used to resolve forward references in complex
        # inheritance hierarchies.
        #
        # We explicitly call `update_forward_refs` on immediate parent
        # classes (`__bases__`) instead of relying solely on
        # `super().update_forward_refs()`. This is because `super()`
        # inside this classmethod resolves relative to `Dataset` in the MRO,
        # silently bypassing custom logic on any intermediate `Dataset`
        # subclasses. Explicitly propagating through `__bases__` ensures
        # that class-level setups are correctly applied to all parents
        # exactly once, efficiently preventing redundant updates.
        for base in cls.__bases__:
            if is_dataset_subclass(base) and base is not Dataset:
                base.update_forward_refs(
                    calling_module=calling_module,
                    prev_visited_classes=prev_visited_classes,
                    **extra_ns,
                )

        # As above, but now propagate update_forward_refs to the types of
        # the Dataset (e.g. the Model).
        for type_variant in split_to_union_variants(cls.get_type()):
            if is_dataset_subclass(type_variant) or is_model_subclass(type_variant):
                type_variant.update_forward_refs(
                    calling_module=calling_module,
                    prev_visited_classes=prev_visited_classes,
                    **extra_ns,
                )

        cls.__name__ = remove_forward_ref_notation(cls.__name__)
        cls.__qualname__ = remove_forward_ref_notation(cls.__qualname__)

    def _validate_data_file(self, data_file: str) -> None:
        """Validate one stored dataset item in place.

        Args:
            data_file: Key of the item that should be revalidated.

        Raises:
            ValidationError: If the stored item does not validate for this dataset type.
        """
        from omnipy.data.model import is_model_instance

        val = self.data[data_file]
        if is_model_instance(val):
            self.data[data_file] = self._validate_value_for_data_file(data_file, val)
        else:
            self._force_full_validation()

    @staticmethod
    def _basic_validation_func(type_variant: 'type[Model | Dataset]',
                               value: UndefinedType | object) -> _ModelOrDatasetT:
        """Construct one candidate model or dataset during validation.

        Args:
            type_variant: Candidate model or dataset class to instantiate.
            value: Raw value passed to the candidate class constructor.

        Returns:
            The validated model or dataset instance.

        Raises:
            ValidationError: If construction of the candidate type fails validation.
            TypeError: If the candidate type cannot be constructed from ``value``.
            ValueError: If the candidate type rejects ``value`` semantically.
        """
        return cast(_ModelOrDatasetT, type_variant(value))  # type: ignore[arg-type]

    @classmethod
    def _validate_value_for_data_file(
        cls,
        data_file: str,
        value: UndefinedType | object,
        validation_func: (
            'Callable[[type[Model | Dataset], UndefinedType | object], _ModelOrDatasetT]'
        ) = _basic_validation_func,
    ) -> _ModelOrDatasetT:
        """Validate one data-file value against all allowed dataset item variants.

        Args:
            data_file: Key associated with the candidate item.
            value: Raw value to validate.
            validation_func: Callable used to try construction for each allowed type variant.

        Returns:
            The first validated model or dataset instance accepted by the allowed type variants.

        Raises:
            ValidationError: If all candidate type variants reject the value.
        """
        errors = []
        for type_variant in split_to_union_variants(cls.get_type()):
            try:
                return validation_func(cast('type[Model | Dataset]', type_variant), value)
            except (ValidationError, ValueError, TypeError) as exp:
                errors.append(exp)
        assert errors
        raise ValidationError([pyd.ErrorWrapper(exc, loc=data_file) for exc in errors], cls)

    def _force_full_validation(self):
        """Trigger assignment-based validation for the full dataset mapping.

        Raises:
            ValidationError: If any stored item fails full dataset validation.
        """
        self.data = self.data  # Triggers pydantic validation, as validate_assignment=True

    @override
    def __iter__(self) -> Iterator[str]:  # type: ignore[override]
        """Iterate over dataset keys.

        Returns:
            An iterator over data-file names in the backing mapping.
        """
        return UserDict.__iter__(self)

    def __setattr__(self, attr: str, value: Any) -> None:
        """Restrict attribute assignment to declared dataset fields and properties.

        Args:
            attr: Attribute name being assigned.
            value: Value to store on the dataset instance.

        Raises:
            RuntimeError: If assignment targets an undeclared extra attribute.
        """
        if attr in self.__dict__ or attr == DATA_KEY or attr.startswith('__'):
            super().__setattr__(attr, value)
        elif attr == 'repr_state':
            prop = getattr(self.__class__, attr)
            prop.__set__(self, value)
        else:
            raise RuntimeError('Dataset does not allow setting of extra attributes')

    @pyd.root_validator
    def _parse_root_object(
        cls,
        root_obj: dict_t[str, dict_t[str, _ModelOrDatasetT]],
    ) -> Any:  # noqa
        """Pre-validate the root dataset object before normal field parsing.

        Args:
            cls: Dataset class performing validation.
            root_obj: Root object containing the ``data`` field to normalize.

        Returns:
            A root object whose ``data`` field has normalized values.

        Raises:
            AssertionError: If the root object does not contain the ``data`` field.
            ValidationError: If ``None`` values cannot be parsed by any allowed item type.
        """
        assert DATA_KEY in root_obj
        data_dict = root_obj[DATA_KEY]
        for data_file, val in data_dict.items():
            if val is None:

                def validation_by_parse_obj(
                    type_variant: 'type[Model | Dataset]',
                    value: UndefinedType | object,
                ) -> _ModelOrDatasetT:
                    """Parse a raw value with ``parse_obj()`` for one candidate type.

                    Args:
                        type_variant: Candidate model or dataset class to parse with.
                        value: Raw value to parse.

                    Returns:
                        The parsed model or dataset instance.
                    """
                    return cast(_ModelOrDatasetT, type_variant.parse_obj(value))

                data_dict[data_file] = cls._validate_value_for_data_file(
                    data_file,
                    val,
                    validation_by_parse_obj,
                )

        return {DATA_KEY: data_dict}

    def to(self, model_or_dataset_cls: type[_OtherModelOrDatasetT]) -> '_OtherModelOrDatasetT':
        """Convert this dataset to another model or dataset class.

        Args:
            model_or_dataset_cls: Target model or dataset class that can be constructed from this
                dataset.

        Returns:
            An instance of the requested target class.
        """
        return model_or_dataset_cls(self)

    def do(self, placeholder: F) -> 'Dataset[_ModelOrDatasetT]':
        """Apply a callable placeholder to each item and collect the results in a new dataset.

        Args:
            placeholder: Callable wrapper used to transform each validated dataset item.

        Returns:
            A new dataset of the same class containing the transformed items.
        """
        new_dataset = self.__class__()
        for data_file, val in self.items():
            new_dataset[data_file] = placeholder(val)
        return new_dataset

    def to_data(self) -> dict_t[str, Any]:
        """Return the dataset as plain Python contents.

        Returns:
            A mapping from data-file name to plain Python data extracted from each validated item.
        """
        return {key: self._check_value(val) for key, val in self.dict(by_alias=True).items()}

    def dict(self, **kwargs) -> dict_t[str, Any]:
        """Return the dataset backing mapping as a plain dictionary.

        Args:
            **kwargs: Keyword arguments forwarded to Pydantic's ``dict()`` implementation.

        Returns:
            The serialized value of the dataset's ``data`` field.
        """
        return super().dict(**kwargs)[DATA_KEY]

    def from_data(self,
                  data: Mapping[str, Any] | Iterable[tuple[str, Any]],
                  update: bool = True) -> None:
        """Populate the dataset from plain Python contents.

        Args:
            data: Mapping or iterable of ``(key, value)`` pairs to parse into validated items.
            update: Whether to merge into existing contents instead of replacing them first.
        """
        def callback_func(type_variant: 'Model | Dataset', content: Any):
            """Populate one item instance from plain Python content.

            Args:
                type_variant: Newly created model or dataset instance to populate.
                content: Plain Python content to load into the instance.

            """
            type_variant.from_data(content)

        self._from_dict_with_callback(data, update, callback_func)

    def _from_dict_with_callback(self,
                                 data: Mapping[str, Any] | Iterable[tuple[str, Any]],
                                 update: bool,
                                 callback_func: 'Callable[[Model | Dataset, Any], None]'):
        """Populate the dataset by applying a callback to fresh item instances.

        Args:
            data: Mapping or iterable of ``(key, value)`` pairs to ingest.
            update: Whether to merge with current contents instead of clearing first.
            callback_func: Callback that populates one newly created item instance from raw input.

        Raises:
            ValidationError: If any generated item fails dataset validation.
        """
        if isinstance(data, dict):
            data_as_dict: dict[str, Any] = data  # pyright: ignore [reportAssignmentType]
        else:
            data_as_dict = dict(data)

        if not update:
            self.clear()

        for data_file, content in data_as_dict.items():
            # TODO: Redefine from_data() also as classmethods on Model and
            #       Dataset. Here, we could then do
            #       type_variant.from_data(content) instead of creating a
            #       new instance and then calling from_data() on it.
            #       Instance-level from_data() should however also be kept,
            #       as it is useful in many cases. Note: Classmethod
            #       from_data() should still first create an empty instance
            #       and then call instance-level from_data() on it, to avoid
            #       issues with __init__ arguments (when e.g. 'self', 'value',
            #       'data' is used as keys in the data).

            def validation_by_callback_func(
                type_variant: 'type[Model | Dataset]',
                value: UndefinedType | object,
            ) -> _ModelOrDatasetT:
                """Create one validated item by invoking the provided callback.

                Args:
                    type_variant: Candidate model or dataset class to instantiate.
                    value: Raw value to hand to the callback.

                Returns:
                    A populated item instance accepted by the dataset type.
                """
                new_instance = type_variant()
                callback_func(new_instance, value)
                return cast(_ModelOrDatasetT, new_instance)

            self.data[data_file] = self._validate_value_for_data_file(
                data_file,
                content,
                validation_by_callback_func,
            )

    def absorb(self, other: 'Dataset'):
        """Merge another dataset's contents into this dataset.

        Args:
            other: Dataset whose plain-Python contents should be added or overwrite matching keys.
        """
        self.from_data(other.to_data(), update=True)

    def absorb_and_replace(self, other: 'Dataset'):
        """Replace this dataset's contents with another dataset's contents.

        Args:
            other: Dataset whose contents should replace the current contents.
        """
        self.from_data(other.to_data(), update=False)

    def to_json(self, pretty=True) -> dict_t[str, str]:
        """Serialize each dataset item to JSON.

        Args:
            pretty: Whether to pretty-print the JSON for each item.

        Returns:
            A mapping from data-file name to JSON string.
        """
        result = {}

        for key, val in self.data.items():
            result[key] = val.to_json(pretty=pretty)

        return result

    def from_json(self,
                  data: Mapping[str, str] | Iterable[tuple[str, str]],
                  update: bool = True) -> None:
        """Populate the dataset from per-item JSON strings.

        Args:
            data: Mapping or iterable of ``(key, json_string)`` pairs.
            update: Whether to merge into existing contents instead of replacing them first.
        """
        def callback_func(type_variant: 'Model | Dataset', content: Any):
            """Populate one item instance from a JSON string.

            Args:
                type_variant: Newly created model or dataset instance to populate.
                content: JSON content to load into the instance.

            """
            type_variant.from_json(content)

        self._from_dict_with_callback(data, update, callback_func)

    # @classmethod
    # def get_type_args(cls):
    #     return cls.__fields__.get(DATA_KEY).type_
    #
    #
    # @classmethod
    # def create_from_json(cls, data: str, tuple[str]]):
    #     if isinstance(data, tuple):
    #         data = data[0]
    #
    #     obj = cls()
    #     obj.from_json(data, update=False)
    #     return obj
    #
    # def __reduce__(self):
    #     return self.__class__.create_from_json, (self.to_json(),)

    @classmethod
    def to_json_schema(cls, pretty: bool = True) -> str | dict_t[str, str]:
        """Return a JSON schema for the dataset's serialized contents.

        Args:
            pretty: Whether to return pretty-printed JSON text instead of compact JSON text.

        Returns:
            A JSON schema string describing the dataset contents.
        """
        result = {}
        clean_dataset = super(Dataset, Dataset).__class_getitem__(cls.get_type())
        schema = clean_dataset.schema()
        for key, val in schema['properties'][DATA_KEY].items():
            # Remove the first part of the type definition of 'data', added
            # as a hack to stop coercing of e.g. [{'a': 'b', 'c': 'd'}]
            # to {'a': 'c'}
            if key == 'anyOf':
                result['type'] = 'object'
                result['additionalProperties'] = {
                    '$ref': '#/definitions/' + pyd.normalize_name(clean_dataset.get_type().__name__)
                }
            else:
                result[key] = val

        result['title'] = clean_dataset.__name__
        result['definitions'] = schema['definitions']

        for model_desc in result['definitions'].values():
            if 'orig_model' in model_desc:
                del model_desc['orig_model']

        if pretty:
            return cls._pretty_print_json(result)
        else:
            return json.dumps(result)

    @staticmethod
    def _pretty_print_json(json_content: Any) -> str:
        """Render JSON-serializable content as indented JSON text.

        Args:
            json_content: JSON-serializable object to pretty-print.

        Returns:
            Indented JSON text.
        """
        return json.dumps(json_content, indent=2)

    def save(self, path: str):
        """Serialize the dataset to a ``.tar.gz`` archive and extract a directory copy.

        Args:
            path: Destination path with or without the ``.tar.gz`` suffix.
        """
        serializer_registry = self._get_serializer_registry()

        parsed_dataset, serializer = serializer_registry.auto_detect_tar_file_serializer(self)

        if serializer is None:
            print(f'Unable to find a serializer for dataset with data type "{type(self)}". '
                  f'Will abort saving...')
        else:
            if not path.endswith('.tar.gz'):
                out_tar_gz_path = f'{path}.tar.gz'

            print(f'Writing dataset as a gzipped tarpack to "{os.path.abspath(out_tar_gz_path)}"')

            with open(out_tar_gz_path, 'wb') as out_tar_gz_file:
                out_tar_gz_file.write(serializer.serialize(parsed_dataset))

            directory = os.path.abspath(out_tar_gz_path[:-7])
            if not os.path.exists(directory):
                os.makedirs(directory)

            tar = tarfile.open(out_tar_gz_path)
            print(f'Extracting content to directory "{os.path.abspath(out_tar_gz_path[:-7])}"')
            tar.extractall(path=directory)
            tar.close()

    @classmethod
    def load(
        cls,
        paths_or_urls: IsPathsOrUrlsOneOrMoreOrNone = None,
        by_file_suffix: bool = False,
        as_mime_type: None | str = None,
        **kwargs: IsPathOrUrl,
    ) -> Self | asyncio.Task[Self]:
        """Create a dataset and load serialized contents into it.

        Args:
            paths_or_urls: Path, URL, iterable of paths or URLs, or dataset/model of HTTP URLs to
                load from.
            by_file_suffix: Whether serializer lookup should prefer file-suffix detection.
            as_mime_type: Optional MIME type hint for HTTP loading.
            **kwargs: Alternate keyed path or URL arguments when ``paths_or_urls`` is omitted.

        Returns:
            A loaded dataset, or an ``asyncio.Task`` when called inside a running event loop.
        """
        dataset = cls()
        return dataset.load_into(
            paths_or_urls, by_file_suffix=by_file_suffix, as_mime_type=as_mime_type, **kwargs)

    def load_into(
        self,
        paths_or_urls: IsPathsOrUrlsOneOrMoreOrNone = None,
        by_file_suffix: bool = False,
        as_mime_type: None | str = None,
        **kwargs: IsPathOrUrl,
    ) -> Self | asyncio.Task[Self]:
        """Load serialized contents into this dataset instance.

        Args:
            paths_or_urls: Path, URL, iterable of paths or URLs, or dataset/model of HTTP URLs to
                load from.
            by_file_suffix: Whether serializer lookup should prefer file-suffix detection.
            as_mime_type: Optional MIME type hint for HTTP loading.
            **kwargs: Alternate keyed path or URL arguments when ``paths_or_urls`` is omitted.

        Returns:
            This dataset instance after loading, or an ``asyncio.Task`` when called inside a
            running event loop.

        Raises:
            AssertionError: If the input forms are combined incorrectly.
            TypeError: If ``paths_or_urls`` has an unsupported type.
            NotImplementedError: If keyed local-path loading is requested.
        """
        from omnipy.components.remote.datasets import HttpUrlDataset
        from omnipy.components.remote.models import HttpUrlModel

        if paths_or_urls is None:
            assert len(kwargs) > 0, 'No paths or urls specified'
            paths_or_urls = kwargs
        else:
            assert len(kwargs) == 0, 'No keyword arguments allowed when paths_or_urls is specified'

        match paths_or_urls:
            case HttpUrlDataset():
                return self._load_http_urls(paths_or_urls, as_mime_type=as_mime_type)

            case HttpUrlModel():
                return self._load_http_urls(
                    HttpUrlDataset({str(paths_or_urls): paths_or_urls}),
                    as_mime_type=as_mime_type,
                )

            case str():
                try:
                    http_url_dataset = HttpUrlDataset({paths_or_urls: paths_or_urls})
                except ValidationError:
                    return self._load_paths([paths_or_urls], by_file_suffix)
                return self._load_http_urls(http_url_dataset, as_mime_type=as_mime_type)

            case Mapping():
                try:
                    http_url_dataset = HttpUrlDataset(paths_or_urls)
                except ValidationError as exp:
                    raise NotImplementedError(
                        'Loading files with specified keys is not yet '
                        'implemented, as only tar.gz file import is '
                        'supported until serializers have been refactored.') from exp
                return self._load_http_urls(http_url_dataset, as_mime_type=as_mime_type)

            case Iterable():
                path_or_url_iterable = paths_or_urls
                try:
                    http_url_dataset = HttpUrlDataset(
                        zip(path_or_url_iterable, path_or_url_iterable))
                except ValidationError:
                    return self._load_paths(path_or_url_iterable, by_file_suffix)
                return self._load_http_urls(http_url_dataset, as_mime_type=as_mime_type)
            case _:
                raise TypeError(f'"paths_or_urls" argument is of incorrect type. Type '
                                f'{type(paths_or_urls)} is not supported.')

    def _load_http_urls(
        self,
        http_url_dataset: IsHttpUrlDataset,
        as_mime_type: None | str = None,
    ) -> Self | asyncio.Task[Self]:
        """Load dataset contents from one or more HTTP URLs.

        Args:
            http_url_dataset: Dataset of HTTP URLs keyed by data-file name.
            as_mime_type: Optional MIME type hint passed to the remote loading task.

        Returns:
            This dataset instance after loading, or an ``asyncio.Task`` in an active event loop.
        """
        from omnipy.components.remote.helpers import RateLimitingClientSession
        from omnipy.components.remote.tasks import get_auto_from_api_endpoint, get_retry_client

        hosts: defaultdict[str, list[int]] = defaultdict(list)
        for i, url in enumerate(http_url_dataset.values()):
            hosts[url.host].append(i)

        async def load_all(as_mime_type: None | str = None) -> 'Dataset[_ModelOrDatasetT]':
            """Fetch all grouped HTTP URLs asynchronously.

            Args:
                as_mime_type: Optional MIME type hint forwarded to the remote fetch task.

            Returns:
                This dataset instance after all remote loads complete.
            """
            tasks = []

            # TODO: Manage ClientConnectionResetError in Dataset._load_http_urls
            for host in hosts:
                host_config = self.config.http.for_host[host]
                async with RateLimitingClientSession(
                        host_config.requests_per_time_period,
                        host_config.time_period_in_secs) as client_session:
                    async with get_retry_client(
                            client_session=client_session,
                            retry_http_statuses=host_config.retry_http_statuses,
                            retry_attempts=host_config.retry_attempts,
                            retry_backoff_strategy=host_config.retry_backoff_strategy
                    ) as retry_client:
                        indices = hosts[host]
                        # fetch_task = get_auto_from_api_endpoint
                        # if as_mime_type:
                        #     match as_mime_type:
                        #         case 'application/json':
                        #             fetch_task = get_json_from_api_endpoint
                        #         case 'text/plain':
                        #             fetch_task = get_str_from_api_endpoint
                        #         case 'application/octet-stream' | _:
                        #             fetch_task = get_bytes_from_api_endpoint

                        ret = get_auto_from_api_endpoint.refine(
                            output_dataset_param='output_dataset').run(
                                http_url_dataset[indices],
                                retry_client=retry_client,
                                output_dataset=self,
                                as_mime_type=as_mime_type)

                        if not isinstance(ret, asyncio.Task):
                            assert inspect.iscoroutine(ret)
                            task = asyncio.create_task(ret)
                        else:
                            task = ret

                        tasks.append(task)

                        while not task.done():
                            await asyncio.sleep(ASYNC_LOAD_SLEEP_TIME)

            await asyncio.gather(*tasks)
            return self

        loop, loop_is_running = get_event_loop_and_check_if_loop_is_running()

        if loop and loop_is_running:
            return loop.create_task(load_all(as_mime_type=as_mime_type))
        else:
            return asyncio.run(load_all(as_mime_type=as_mime_type))

    def _load_paths(self, path_or_urls: Iterable[str], by_file_suffix: bool) -> Self:
        """Load dataset contents from local tar files or directories.

        Args:
            path_or_urls: Iterable of local filesystem paths to load from.
            by_file_suffix: Whether serializer selection should use file-suffix detection.

        Returns:
            This dataset instance after all paths have been loaded.

        Raises:
            RuntimeError: If no serializer can load one of the provided paths.
        """
        for path_or_url in path_or_urls:
            serializer_registry = self._get_serializer_registry()
            tar_gz_file_path = self._ensure_tar_gz_file(path_or_url)

            if by_file_suffix:
                loaded_dataset = \
                    serializer_registry.load_from_tar_file_path_based_on_file_suffix(
                        self, tar_gz_file_path, self)
            else:
                loaded_dataset = \
                    serializer_registry.load_from_tar_file_path_based_on_dataset_cls(
                        self, tar_gz_file_path, self, any_file_suffix=True)
            if loaded_dataset is not None:
                self.absorb(loaded_dataset)
                continue
            else:
                raise RuntimeError('Unable to load from serializer')
        return self

    @staticmethod
    def _ensure_tar_gz_file(path: str):
        """Return a ``.tar.gz`` path, creating an archive when needed.

        Args:
            path: Existing file or directory path, optionally already ending in ``.tar.gz``.

        Returns:
            Path to an existing or newly created ``.tar.gz`` archive.

        Raises:
            AssertionError: If the provided path does not exist.
        """
        assert os.path.exists(path), f'No file or directory at {path}'

        if not path.endswith('.tar.gz'):
            tar_gz_file_path = path + '.tar.gz'
            if not os.path.isfile(tar_gz_file_path):
                print(f'Creating compressed file {os.path.abspath(tar_gz_file_path)} from '
                      f'the content of "{os.path.abspath(path)}"')

                with tarfile.open(tar_gz_file_path, 'w:gz') as tar:
                    if os.path.isdir(path):
                        for fn in sorted(os.listdir(path)):
                            p = os.path.join(path, fn)
                            tar.add(p, arcname=fn)
                    elif os.path.isfile(path):
                        tar.add(path, arcname=os.path.basename(path))
            return tar_gz_file_path

        return path

    @staticmethod
    def _get_serializer_registry():
        """Return the global serializer registry used for dataset I/O.

        Returns:
            The serializer registry singleton from :mod:`omnipy.components`.
        """
        from omnipy.components import get_serializer_registry
        return get_serializer_registry()

    def as_multi_model_dataset(self) -> 'IsMultiModelDataset[_ModelOrDatasetT]':
        """Return a multi-model view of this dataset.

        Returns:
            A ``MultiModelDataset`` initialized with the same item type and current contents.
        """
        from omnipy.data.multi import MultiModelDataset

        multi_model_dataset = MultiModelDataset[self.get_type()]()
        for data_file in self:
            multi_model_dataset.data[data_file] = self.data[data_file]
        return multi_model_dataset

    def __eq__(self, other: object) -> bool:
        """Compare datasets by specialized class and contents.

        Args:
            other: Object to compare against.

        Returns:
            ``True`` when both objects are datasets of the same specialized class with equal
            validated contents.
        """
        # return self.__class__ == other.__class__ and super().__eq__(other)
        return isinstance(other, Dataset) \
            and self.__class__ == other.__class__ \
            and self.data == other.data \
            and self.to_data() == other.to_data()  # last is probably unnecessary, but just in case

    def __repr_args__(self):
        """Return key-value pairs used by Pydantic when building ``repr()`` output.

        Returns:
            A list of ``(key, value)`` pairs formatted for concise dataset representation.
        """
        from omnipy.data.model import is_model_instance

        return [(k, v.content) if is_model_instance(v) else (k, v) for k, v in self.data.items()]

available_data property

available_data: Self

Return a same-type copy containing only successfully available data entries.

config property

config: IsDataConfig

Return the data configuration shared by the owning data-class family.

RETURNS DESCRIPTION
IsDataConfig

Shared configuration object used by related models and datasets.

TYPE: IsDataConfig

data class-attribute instance-attribute

data: dict_t[str, _ModelOrDatasetT] = pyd.Field(default={})

failed_data property

failed_data: Self

Return a same-type copy containing only entries whose producing task failed.

pending_data property

pending_data: Self

Return a same-type copy containing only entries still waiting on task results.

reactive_objects property

reactive_objects: IsReactiveObjects | None

Return the reactive-object registry attached to this data-class family.

snapshot_holder property

Return the snapshot holder coordinating copy-based change tracking.

Config

Configure Pydantic behavior for dataset instances.

The nested config enables assignment-time validation and permits arbitrary runtime types needed by Omnipy's dataset internals.

ATTRIBUTE DESCRIPTION
validate_assignment

Re-validate fields whenever attributes are reassigned.

arbitrary_types_allowed

Permit non-Pydantic helper types in the model definition.

Source code in src/omnipy/data/dataset.py
class Config:
    """Configure Pydantic behavior for dataset instances.

    The nested config enables assignment-time validation and permits arbitrary runtime types
    needed by Omnipy's dataset internals.

    Attributes:
        validate_assignment: Re-validate fields whenever attributes are reassigned.
        arbitrary_types_allowed: Permit non-Pydantic helper types in the model definition.
    """
    validate_assignment = True
    arbitrary_types_allowed = True

arbitrary_types_allowed class-attribute instance-attribute

arbitrary_types_allowed = True

validate_assignment class-attribute instance-attribute

validate_assignment = True

__init__

__init__(
    value: Mapping[str, object] | Iterable[tuple[str, object]] | UndefinedType = Undefined,
    *,
    data: Mapping[str, object] | UndefinedType = Undefined,
    **kwargs: object,
) -> None
Source code in src/omnipy/data/dataset.py
def __init__(  # noqa: C901
    self,
    value: Mapping[str, object] | Iterable[tuple[str, object]] | UndefinedType = Undefined,
    *,
    data: Mapping[str, object] | UndefinedType = Undefined,
    **kwargs: object,
) -> None:
    from omnipy.data.model import is_model_instance, is_pure_pydantic_model

    # TODO: Error message when forgetting parenthesis when creating Dataset should be improved.
    #       Unclear where this can be done, if anywhere? E.g.:
    #           a = Dataset[Model[int]]
    #           a['adsfas'] = 2
    #           Traceback (most recent call last):
    #             ...
    #           TypeError: 'ModelMetaclass' object does not support item assignment
    #
    # TODO: Disallow e.g.:
    #       Dataset[Model[str]](Model[int](5)) ==  Dataset[Model[str]](data=Model[int](5))
    #       == Dataset[Model[str]](data={'__root__': Model[str]('5')})

    super_kwargs = {}

    assert DATA_KEY not in kwargs, \
        ('Not allowed with "data" as kwargs key. Not sure how you managed this? Are you trying '
         'to break Dataset init on purpose?')

    if value != Undefined:
        assert data == Undefined, \
            'Not allowed to combine positional and "data" keyword argument'
        assert len(kwargs) == 0, \
            'Not allowed to combine positional and keyword arguments'
        super_kwargs[DATA_KEY] = value

    if data != Undefined:
        assert len(kwargs) == 0, \
            f"Not allowed to combine '{DATA_KEY}' with other keyword arguments"
        super_kwargs[DATA_KEY] = data

    if kwargs:
        if DATA_KEY not in super_kwargs:
            super_kwargs[DATA_KEY] = kwargs
            kwargs = {}

    _type = self.get_type()
    if _type == _ModelOrDatasetT:  # type: ignore[misc]
        self._raise_type_exception()

    def _validate_any_models_or_datasets(
            iterable_data: Iterable[tuple[str, object]]) -> tuple[dict, bool]:
        """Validate model or dataset instances found in iterable input data.

        Args:
            iterable_data: Iterable of ``(key, value)`` pairs supplied to dataset
                initialization.

        Returns:
            A tuple containing the prepared mapping and a flag indicating whether any input
            values were already model or dataset instances.
        """

        prepared_data = {}
        _model_or_dataset_as_input: bool = False

        for key, val in iterable_data:
            if is_model_instance(val):
                _model_or_dataset_as_input = True
                prepared_data[key] = self._validate_value_for_data_file(key, val)
            else:
                prepared_data[key] = val
        return prepared_data, _model_or_dataset_as_input

    model_or_dataset_as_input = False
    if DATA_KEY in super_kwargs:
        input_data = super_kwargs[DATA_KEY]
        for_type_check = input_data.content if is_model_instance(input_data) else input_data
        match for_type_check:
            case Dataset():
                model_or_dataset_as_input = True
                super_kwargs[DATA_KEY] = cast(Dataset, input_data).to_data()
            case _input_data if is_pure_pydantic_model(_input_data):
                super_kwargs[DATA_KEY], model_or_dataset_as_input = (
                    _validate_any_models_or_datasets(_input_data.dict().items()))
            case Mapping():
                super_kwargs[DATA_KEY], model_or_dataset_as_input = (
                    _validate_any_models_or_datasets(cast(Mapping, input_data).items()))
            case Iterable():
                try:
                    super_kwargs[DATA_KEY], model_or_dataset_as_input = (
                        _validate_any_models_or_datasets(self._check_iterable(input_data)))
                except (TypeError, ValueError) as e:
                    raise TypeError(
                        'Data object must be a mapping or an iterable of '
                        '(key, val) pairs',
                        self.__class__) from e

            case _:
                ...

    self._init(super_kwargs, **kwargs)

    try:
        self._primary_validation(super_kwargs)
    except ValidationError:
        if model_or_dataset_as_input:
            self._secondary_validation_from_data(super_kwargs)
        else:
            raise

    if not self.__doc__:
        self._set_standard_field_description()

absorb

absorb(other: Dataset)

Merge another dataset's contents into this dataset.

PARAMETER DESCRIPTION
other

Dataset whose plain-Python contents should be added or overwrite matching keys.

TYPE: Dataset

Source code in src/omnipy/data/dataset.py
def absorb(self, other: 'Dataset'):
    """Merge another dataset's contents into this dataset.

    Args:
        other: Dataset whose plain-Python contents should be added or overwrite matching keys.
    """
    self.from_data(other.to_data(), update=True)

absorb_and_replace

absorb_and_replace(other: Dataset)

Replace this dataset's contents with another dataset's contents.

PARAMETER DESCRIPTION
other

Dataset whose contents should replace the current contents.

TYPE: Dataset

Source code in src/omnipy/data/dataset.py
def absorb_and_replace(self, other: 'Dataset'):
    """Replace this dataset's contents with another dataset's contents.

    Args:
        other: Dataset whose contents should replace the current contents.
    """
    self.from_data(other.to_data(), update=False)

as_multi_model_dataset

as_multi_model_dataset() -> IsMultiModelDataset[_ModelOrDatasetT]

Return a multi-model view of this dataset.

RETURNS DESCRIPTION
IsMultiModelDataset[_ModelOrDatasetT]

A MultiModelDataset initialized with the same item type and current contents.

Source code in src/omnipy/data/dataset.py
def as_multi_model_dataset(self) -> 'IsMultiModelDataset[_ModelOrDatasetT]':
    """Return a multi-model view of this dataset.

    Returns:
        A ``MultiModelDataset`` initialized with the same item type and current contents.
    """
    from omnipy.data.multi import MultiModelDataset

    multi_model_dataset = MultiModelDataset[self.get_type()]()
    for data_file in self:
        multi_model_dataset.data[data_file] = self.data[data_file]
    return multi_model_dataset

browse

browse(
    *,
    width: pyd.NonNegativeInt | None = None,
    height: pyd.NonNegativeInt | None = None,
    tab: pyd.NonNegativeInt = 4,
    indent: pyd.NonNegativeInt = 2,
    printer: PrettyPrinterLib.Literals = "auto",
    syntax: SyntaxLanguageSpec.Literals | str = "auto",
    freedom: pyd.NonNegativeFloat | None = 2.5,
    debug: bool = False,
    ui: UserInterfaceType.Literals = "auto",
    system: DisplayColorSystem.Literals = "auto",
    style: AllColorStyles.Literals | str = "auto",
    dark: typing.Literal["auto", True, False] = "auto",
    bg: bool = False,
    fonts: tuple[str, ...] = ("Menlo", "DejaVu Sans Mono", "Consolas", "Courier New", "monospace"),
    font_size: pyd.NonNegativeFloat | None = 14,
    font_weight: pyd.NonNegativeInt | None = 400,
    line_height: pyd.NonNegativeFloat | None = 1.25,
    h_overflow: HorizontalOverflowMode.Literals = "ellipsis",
    v_overflow: VerticalOverflowMode.Literals = "ellipsis_bottom",
    panel: PanelDesign.Literals = "table",
    title_at_top: bool = True,
    max_title_height: MaxTitleHeight.Literals = -1,
    min_panel_width: pyd.NonNegativeInt = 3,
    min_crop_width: pyd.NonNegativeInt = 33,
    use_min_crop_width: bool = False,
    max_panels_hor: pyd.NonNegativeInt | None = 9,
    max_nesting_depth: pyd.NonNegativeInt | None = 3,
    justify: Justify.Literals = "left",
) -> None

Opens the model or dataset in a browser, if possible.

For models, this is a detailed view of the model's content, and for datasets this is a detailed view of each model contained in the dataset, one model per browser tab.

PARAMETER DESCRIPTION
width

Width in characters of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

height

Height in lines of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

tab

Number of spaces to use for each tab.

TYPE: NonNegativeInt DEFAULT: 4

indent

Number of spaces to use for each indentation level.

TYPE: NonNegativeInt DEFAULT: 2

printer

Library to use for pretty printing.

TYPE: PrettyPrinterLib.Literals DEFAULT: 'auto'

syntax

Syntax language for code highlighting. Supported lexers are defined in SyntaxLanguageSpec. For non-supported styles, the user can specify a string with the Pygments lexer name. For this to work, the lexer must be registered in the Pygments library.

TYPE: SyntaxLanguageSpec.Literals | str DEFAULT: 'auto'

freedom

Parameter that controls the level of freedom for formatted text to follow the geometry of the frame size (=total available area) in a proportional manner. If the proportional freedom is 0 (the lowest), then the output area must not in any case be proportionally wider that the frame (i.e. a 16/9 frame will only produce output that is 16/9 or narrower). Larger values of proportional freedom allow the output to be proportionally wider than the total available frame, to a degree that relates to the size difference between the frame and the content (larger difference gives more freedom). The default value of 2.5 is a good compromise between readability/aesthetics and good use of the screen estate. If None, the freedom is unlimited (i.e. proportionality is not taken into account at all).

TYPE: float | None DEFAULT: 2.5

debug

When True, enables additional debugging information in the output, such as the hierarchy of the Model objects. Currently, only Python pretty printers support debug=True. Hence, enabling debug mode will automatically set the printer to the default Python pretty printer if the printer config value is not already set.

TYPE: bool DEFAULT: False

ui

Type of user interface for which the output should being prepared. The user interface describes the technical solutions available for interacting with the user, encompassing the support available for displaying output as well as how the user interacts with the library (including the type of interactive interpreter used, if any).

TYPE: UserInterfaceType.Literals DEFAULT: 'auto'

system

Color system to use for terminal output. The default is AUTO, which automatically detects the color system based on particular environment variables. If color capabilities are not detected, the output will be in black and white. If the color system of a modern consoles/terminal is not auto-detected (which is the case for e.g. the PyCharm console), the user might want to set the color system manually to ANSI_RGB to force color output.

TYPE: ColorSystem.Literals DEFAULT: 'auto'

style

Color style/theme for syntax highlighting and other display elements. Supported styles are defined in AllColorStyles. For non-supported styles, the user can specify a string with the Pygments style name. For this to work, the style must be registered in the Pygments library. If style is AUTO or any of the other RecommendedColorStyles, the style is automatically selected from the RecommendedColorStyles based on the detected user interface, the color system, and whether the background is dark or not.

TYPE: AllColorStyles.Literals | str DEFAULT: 'auto'

dark

Whether the background color of the output is dark. This is used to determine the appropriate color scheme for syntax highlighting. The default is AUTO, which automatically tries to detect whether the background is dark. Capability of auto-detection depends on the user interface.

TYPE: DarkBackground.Literals DEFAULT: 'auto'

bg

If False, uses transparent background for the output. In the case of terminal output, the background color will be the current background color of the terminal. For HTML output, the background color will be automatically set to pure black or pure white, depending on the luminosity of the foreground color.

TYPE: bool DEFAULT: False

fonts

Font families to use in HTML output, in order of preference (empty tuple for browser default).

TYPE: Tuple[str, ...] DEFAULT: ('Menlo', 'DejaVu Sans Mono', 'Consolas', 'Courier New', 'monospace')

font_size

Font size in pixels for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 14

font_weight

Font weight for HTML output (None for browser default).

TYPE: NonNegativeInt | None DEFAULT: 400

line_height

Line height multiplier for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 1.25

h_overflow

How to handle text that exceeds the width.

TYPE: HorizontalOverflowMode.Literals DEFAULT: 'ellipsis'

v_overflow

How to handle text that exceeds the height.

TYPE: VerticalOverflowMode.Literals DEFAULT: 'ellipsis_bottom'

panel

Visual design of the panel used as container for the output. Only TABLE is currently supported, which displays the output in a table-like grid.

TYPE: PanelDesign.Literals DEFAULT: 'table'

title_at_top

Whether panel titles will be displayed over the panel content (True) or below the content (False)

TYPE: bool DEFAULT: True

max_title_height

Maximum height of the panel title. If AUTO, the height is determined by the content of the title, up to a maximum of two lines. If ZERO, the title is not displayed at all. If ONE or TWO, the title is displayed with a fixed height of max one or two lines, respectively.

TYPE: MaxTitleHeight.Literals DEFAULT: -1

min_panel_width

Minimum width in characters per panel.

TYPE: NonNegativeInt DEFAULT: 3

min_crop_width

Minimum cropping width in characters for panels in cases where more than one panel are to be displayed. This is for instance used to calculate the number of models to display in a Dataset peek(). Only applied if use_min_crop_width is set to True. min_crop_width must be equal to or larger than min_panel_width.

TYPE: NonNegativeInt DEFAULT: 33

use_min_crop_width

Whether the min_crop_width value should be considered in cases where more than one panel are to be displayed, potentially reducing the number of displayed panels.

TYPE: bool DEFAULT: False

max_panels_hor

Maximum number of panels to display horizontally side-by-side at the top level. This value also acts as a ceiling for nested panels; nested panels cannot exceed this limit even if the constant MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED is set to a higher value. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 9

max_nesting_depth

Maximum levels of nested panels to display. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 3

justify

Justification mode for the panel if inside a layout panel. This is only used for the panel content.

TYPE: Justify.Literals DEFAULT: 'left'

Source code in src/omnipy/data/_mixins/display.py
def browse(self, **kwargs) -> None:
    # %% Original docstring (managed by expand_docstr_macros.py) %%
    # {{BROWSE_SUMMARY}}
    #
    # {{BROWSE_DESCRIPTION}}
    #
    # {{DISPLAY_METHOD_ARGS}}
    #
    """Opens the model or dataset in a browser, if possible.

    For models, this is a detailed view of the model's content,
    and for datasets this is a detailed view of each model
    contained in the dataset, one model per browser tab.

    Args:
        width (NonNegativeInt | None):
            Width in characters of the output area (None for
            auto-detect based on available display dimensions).
        height (NonNegativeInt | None):
            Height in lines of the output area (None for
            auto-detect based on available display dimensions).
        tab (NonNegativeInt):
            Number of spaces to use for each tab.
        indent (NonNegativeInt):
            Number of spaces to use for each indentation level.
        printer (PrettyPrinterLib.Literals):
            Library to use for pretty printing.
        syntax (SyntaxLanguageSpec.Literals | str):
            Syntax language for code highlighting. Supported
            lexers are defined in SyntaxLanguageSpec. For
            non-supported styles, the user can specify a string
            with the Pygments lexer name. For this to work, the
            lexer must be registered in the Pygments library.
        freedom (float | None):
            Parameter that controls the level of freedom for
            formatted text to follow the geometry of the frame
            size (=total available area) in a proportional manner.
            If the proportional freedom is 0 (the lowest), then
            the output area must not in any case be proportionally
            wider that the frame (i.e. a 16/9 frame will only
            produce output that is 16/9 or narrower). Larger
            values of proportional freedom allow the output to be
            proportionally wider than the total available frame,
            to a degree that relates to the size difference
            between the frame and the content (larger difference
            gives more freedom). The default value of 2.5 is a
            good compromise between readability/aesthetics and
            good use of the screen estate. If None, the freedom is
            unlimited (i.e. proportionality is not taken into
            account at all).
        debug (bool):
            When True, enables additional debugging information in
            the output, such as the hierarchy of the Model
            objects. Currently, only Python pretty printers support
            debug=True. Hence, enabling debug mode will
            automatically set the printer to the default Python
            pretty printer if the `printer` config value is not
            already set.
        ui (UserInterfaceType.Literals):
            Type of user interface for which the output should
            being prepared. The user interface describes the
            technical solutions available for interacting with the
            user, encompassing the support available for
            displaying output as well as how the user interacts
            with the library (including the type of interactive
            interpreter used, if any).
        system (ColorSystem.Literals):
            Color system to use for terminal output. The default
            is `AUTO`, which automatically detects the color
            system based on particular environment variables. If
            color capabilities are not detected, the output will
            be in black and white. If the color system of a modern
            consoles/terminal is not auto-detected (which is the
            case for e.g. the PyCharm console), the user might
            want to set the color system manually to ANSI_RGB to
            force color output.
        style (AllColorStyles.Literals | str):
            Color style/theme for syntax highlighting and other
            display elements. Supported styles are defined in
            AllColorStyles. For non-supported styles, the user can
            specify a string with the Pygments style name. For this to
            work, the style must be registered in the Pygments
            library. If style is `AUTO` or any of the other
            RecommendedColorStyles, the style is automatically
            selected from the RecommendedColorStyles based on the
            detected user interface, the color system, and whether the
            background is dark or not.
        dark (DarkBackground.Literals):
            Whether the background color of the output is dark.
            This is used to determine the appropriate color scheme
            for syntax highlighting. The default is AUTO, which
            automatically tries to detect whether the background
            is dark. Capability of auto-detection depends on the
            user interface.
        bg (bool):
            If False, uses transparent background for the output.
            In the case of terminal output, the background color
            will be the current background color of the terminal.
            For HTML output, the background color will be
            automatically set to pure black or pure white,
            depending on the luminosity of the foreground color.
        fonts (Tuple[str, ...]):
            Font families to use in HTML output, in order of
            preference (empty tuple for browser default).
        font_size (NonNegativeFloat | None):
            Font size in pixels for HTML output (None for browser
            default).
        font_weight (NonNegativeInt | None):
            Font weight for HTML output (None for browser
            default).
        line_height (NonNegativeFloat | None):
            Line height multiplier for HTML output (None for
            browser default).
        h_overflow (HorizontalOverflowMode.Literals):
            How to handle text that exceeds the width.
        v_overflow (VerticalOverflowMode.Literals):
            How to handle text that exceeds the height.
        panel (PanelDesign.Literals):
            Visual design of the panel used as container for the
            output. Only `TABLE` is currently supported, which
            displays the output in a table-like grid.
        title_at_top (bool):
            Whether panel titles will be displayed over the panel
            content (True) or below the content (False)
        max_title_height (MaxTitleHeight.Literals):
            Maximum height of the panel title. If `AUTO`, the
            height is determined by the content of the title, up
            to a maximum of two lines. If `ZERO`, the title is not
            displayed at all. If `ONE` or `TWO`, the title is
            displayed with a fixed height of max one or two lines,
            respectively.
        min_panel_width (NonNegativeInt):
            Minimum width in characters per panel.
        min_crop_width (NonNegativeInt):
            Minimum cropping width in characters for panels in
            cases where more than one panel are to be displayed.
            This is for instance used to calculate the number of
            models to display in a Dataset peek(). Only applied if
            `use_min_crop_width` is set to `True`.
            `min_crop_width` must be equal to or larger than
            `min_panel_width`.
        use_min_crop_width (bool):
            Whether the `min_crop_width` value should be
            considered in cases where more than one panel are to
            be displayed, potentially reducing the number of
            displayed panels.
        max_panels_hor (NonNegativeInt | None):
            Maximum number of panels to display horizontally
            side-by-side at the top level. This value also acts as
            a ceiling for nested panels; nested panels cannot
            exceed this limit even if the constant
            `MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED` is set to a
            higher value. If None, there is no limit.
        max_nesting_depth (NonNegativeInt | None):
            Maximum levels of nested panels to display. If None,
            there is no limit.
        justify (Justify.Literals):
            Justification mode for the panel if inside a layout
            panel. This is only used for the panel content.
    """
    self._browse(**kwargs)

clone_dataset_cls classmethod

clone_dataset_cls(
    new_dataset_cls_name: str, model_cls: type[_NewModelT] | None = None
) -> type[Self]

Create a new dataset subclass based on this dataset class.

PARAMETER DESCRIPTION
new_dataset_cls_name

Name of the generated dataset subclass.

TYPE: str

model_cls

Optional replacement item model for the generated subclass.

TYPE: type[_NewModelT] | None DEFAULT: None

RETURNS DESCRIPTION
type[Self]

A newly created dataset subclass.

Source code in src/omnipy/data/dataset.py
@classmethod
def clone_dataset_cls(cls,
                      new_dataset_cls_name: str,
                      model_cls: type[_NewModelT] | None = None) -> type[Self]:
    """Create a new dataset subclass based on this dataset class.

    Args:
        new_dataset_cls_name: Name of the generated dataset subclass.
        model_cls: Optional replacement item model for the generated subclass.

    Returns:
        A newly created dataset subclass.
    """
    if model_cls:
        generic_dataset_cls = cls.__bases__[0]
        new_base_cls = generic_dataset_cls[model_cls]  # type: ignore[index]
    else:
        new_base_cls = cls

    new_dataset_cls = type(new_dataset_cls_name, (new_base_cls,), {})
    return new_dataset_cls

copy

copy(*, deep: bool = False, **kwargs) -> Self

Copy the dataset.

PARAMETER DESCRIPTION
deep

Whether to deep-copy nested values as well as the dataset object.

TYPE: bool DEFAULT: False

**kwargs

Additional keyword arguments forwarded to Pydantic's copy().

DEFAULT: {}

RETURNS DESCRIPTION
Self

A copied dataset instance of the same specialized class.

Source code in src/omnipy/data/dataset.py
def copy(self, *, deep: bool = False, **kwargs) -> Self:
    """Copy the dataset.

    Args:
        deep: Whether to deep-copy nested values as well as the dataset object.
        **kwargs: Additional keyword arguments forwarded to Pydantic's ``copy()``.

    Returns:
        A copied dataset instance of the same specialized class.
    """
    pydantic_copy = pyd.GenericModel.copy(self, deep=deep, **kwargs)
    if not deep:
        object.__setattr__(pydantic_copy, DATA_KEY, pydantic_copy.__dict__[DATA_KEY].copy())

    return pydantic_copy  # pyright: ignore [reportReturnType]

deepcopy_context

deepcopy_context(
    top_level_entry_func: Callable[[], None], top_level_exit_func: Callable[[], None]
) -> ContextManager[int]

Delegate nested deepcopy bookkeeping to the shared data-class creator.

PARAMETER DESCRIPTION
top_level_entry_func

Callback run when entering the outermost deepcopy context.

TYPE: Callable[[], None]

top_level_exit_func

Callback run when leaving the outermost deepcopy context.

TYPE: Callable[[], None]

RETURNS DESCRIPTION
ContextManager[int]

A context manager yielding the current deepcopy nesting depth.

Source code in src/omnipy/data/_data_class_creator.py
def deepcopy_context(
    self,
    top_level_entry_func: Callable[[], None],
    top_level_exit_func: Callable[[], None],
) -> ContextManager[int]:
    """Delegate nested deepcopy bookkeeping to the shared data-class creator.

    Args:
        top_level_entry_func: Callback run when entering the outermost deepcopy context.
        top_level_exit_func: Callback run when leaving the outermost deepcopy context.

    Returns:
        A context manager yielding the current deepcopy nesting depth.
    """

    return self.__class__.data_class_creator.deepcopy_context(top_level_entry_func,
                                                              top_level_exit_func)

default_repr_to_terminal_str

default_repr_to_terminal_str(ui_type: TerminalOutputUserInterfaceType.Literals) -> str

Render the default display panel as terminal text.

PARAMETER DESCRIPTION
ui_type

Terminal-oriented user interface to render for.

TYPE: TerminalOutputUserInterfaceType.Literals

RETURNS DESCRIPTION
str

The fully rendered string representation for repr()-style terminal output.

Source code in src/omnipy/data/_mixins/display.py
def default_repr_to_terminal_str(
    self,
    ui_type: TerminalOutputUserInterfaceType.Literals,
) -> str:
    """Render the default display panel as terminal text.

    Args:
        ui_type: Terminal-oriented user interface to render for.

    Returns:
        The fully rendered string representation for ``repr()``-style
        terminal output.
    """
    return self._display_according_to_ui_type(
        ui_type=ui_type,
        return_output_if_str=True,
        output_method=self._default_panel,
    )

dict

dict(**kwargs) -> dict_t[str, Any]

Return the dataset backing mapping as a plain dictionary.

PARAMETER DESCRIPTION
**kwargs

Keyword arguments forwarded to Pydantic's dict() implementation.

DEFAULT: {}

RETURNS DESCRIPTION
dict_t[str, Any]

The serialized value of the dataset's data field.

Source code in src/omnipy/data/dataset.py
def dict(self, **kwargs) -> dict_t[str, Any]:
    """Return the dataset backing mapping as a plain dictionary.

    Args:
        **kwargs: Keyword arguments forwarded to Pydantic's ``dict()`` implementation.

    Returns:
        The serialized value of the dataset's ``data`` field.
    """
    return super().dict(**kwargs)[DATA_KEY]

do

do(placeholder: F) -> Dataset[_ModelOrDatasetT]

Apply a callable placeholder to each item and collect the results in a new dataset.

PARAMETER DESCRIPTION
placeholder

Callable wrapper used to transform each validated dataset item.

TYPE: F

RETURNS DESCRIPTION
Dataset[_ModelOrDatasetT]

A new dataset of the same class containing the transformed items.

Source code in src/omnipy/data/dataset.py
def do(self, placeholder: F) -> 'Dataset[_ModelOrDatasetT]':
    """Apply a callable placeholder to each item and collect the results in a new dataset.

    Args:
        placeholder: Callable wrapper used to transform each validated dataset item.

    Returns:
        A new dataset of the same class containing the transformed items.
    """
    new_dataset = self.__class__()
    for data_file, val in self.items():
        new_dataset[data_file] = placeholder(val)
    return new_dataset

failed_task_details

failed_task_details() -> dict[str, IsFailedData]

Return failure marker payloads keyed by dataset entry name.

Source code in src/omnipy/data/_mixins/task.py
def failed_task_details(self) -> dict[str, IsFailedData]:
    """Return failure marker payloads keyed by dataset entry name."""

    self_with_data = cast(HasData, self)
    return {  # pyright: ignore [reportReturnType]
        key: val for key, val in self_with_data.data.items() if isinstance(val, FailedData)
    }

from_data

from_data(data: Mapping[str, Any] | Iterable[tuple[str, Any]], update: bool = True) -> None

Populate the dataset from plain Python contents.

PARAMETER DESCRIPTION
data

Mapping or iterable of (key, value) pairs to parse into validated items.

TYPE: Mapping[str, Any] | Iterable[tuple[str, Any]]

update

Whether to merge into existing contents instead of replacing them first.

TYPE: bool DEFAULT: True

Source code in src/omnipy/data/dataset.py
def from_data(self,
              data: Mapping[str, Any] | Iterable[tuple[str, Any]],
              update: bool = True) -> None:
    """Populate the dataset from plain Python contents.

    Args:
        data: Mapping or iterable of ``(key, value)`` pairs to parse into validated items.
        update: Whether to merge into existing contents instead of replacing them first.
    """
    def callback_func(type_variant: 'Model | Dataset', content: Any):
        """Populate one item instance from plain Python content.

        Args:
            type_variant: Newly created model or dataset instance to populate.
            content: Plain Python content to load into the instance.

        """
        type_variant.from_data(content)

    self._from_dict_with_callback(data, update, callback_func)

from_json

from_json(data: Mapping[str, str] | Iterable[tuple[str, str]], update: bool = True) -> None

Populate the dataset from per-item JSON strings.

PARAMETER DESCRIPTION
data

Mapping or iterable of (key, json_string) pairs.

TYPE: Mapping[str, str] | Iterable[tuple[str, str]]

update

Whether to merge into existing contents instead of replacing them first.

TYPE: bool DEFAULT: True

Source code in src/omnipy/data/dataset.py
def from_json(self,
              data: Mapping[str, str] | Iterable[tuple[str, str]],
              update: bool = True) -> None:
    """Populate the dataset from per-item JSON strings.

    Args:
        data: Mapping or iterable of ``(key, json_string)`` pairs.
        update: Whether to merge into existing contents instead of replacing them first.
    """
    def callback_func(type_variant: 'Model | Dataset', content: Any):
        """Populate one item instance from a JSON string.

        Args:
            type_variant: Newly created model or dataset instance to populate.
            content: JSON content to load into the instance.

        """
        type_variant.from_json(content)

    self._from_dict_with_callback(data, update, callback_func)

full

full(
    *,
    width: pyd.NonNegativeInt | None = None,
    height: pyd.NonNegativeInt | None = None,
    tab: pyd.NonNegativeInt = 4,
    indent: pyd.NonNegativeInt = 2,
    printer: PrettyPrinterLib.Literals = "auto",
    syntax: SyntaxLanguageSpec.Literals | str = "auto",
    freedom: pyd.NonNegativeFloat | None = 2.5,
    debug: bool = False,
    ui: UserInterfaceType.Literals = "auto",
    system: DisplayColorSystem.Literals = "auto",
    style: AllColorStyles.Literals | str = "auto",
    dark: typing.Literal["auto", True, False] = "auto",
    bg: bool = False,
    fonts: tuple[str, ...] = ("Menlo", "DejaVu Sans Mono", "Consolas", "Courier New", "monospace"),
    font_size: pyd.NonNegativeFloat | None = 14,
    font_weight: pyd.NonNegativeInt | None = 400,
    line_height: pyd.NonNegativeFloat | None = 1.25,
    h_overflow: HorizontalOverflowMode.Literals = "ellipsis",
    v_overflow: VerticalOverflowMode.Literals = "ellipsis_bottom",
    panel: PanelDesign.Literals = "table",
    title_at_top: bool = True,
    max_title_height: MaxTitleHeight.Literals = -1,
    min_panel_width: pyd.NonNegativeInt = 3,
    min_crop_width: pyd.NonNegativeInt = 33,
    use_min_crop_width: bool = False,
    max_panels_hor: pyd.NonNegativeInt | None = 9,
    max_nesting_depth: pyd.NonNegativeInt | None = 3,
    justify: Justify.Literals = "left",
) -> Element | None

Display the content of the Model or Dataset in full height.

full() is a shorthand for peek(height=None) for both models and datasets. Both full-height views are automatically limited in width by the available display dimensions.

PARAMETER DESCRIPTION
width

Width in characters of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

height

Height in lines of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

tab

Number of spaces to use for each tab.

TYPE: NonNegativeInt DEFAULT: 4

indent

Number of spaces to use for each indentation level.

TYPE: NonNegativeInt DEFAULT: 2

printer

Library to use for pretty printing.

TYPE: PrettyPrinterLib.Literals DEFAULT: 'auto'

syntax

Syntax language for code highlighting. Supported lexers are defined in SyntaxLanguageSpec. For non-supported styles, the user can specify a string with the Pygments lexer name. For this to work, the lexer must be registered in the Pygments library.

TYPE: SyntaxLanguageSpec.Literals | str DEFAULT: 'auto'

freedom

Parameter that controls the level of freedom for formatted text to follow the geometry of the frame size (=total available area) in a proportional manner. If the proportional freedom is 0 (the lowest), then the output area must not in any case be proportionally wider that the frame (i.e. a 16/9 frame will only produce output that is 16/9 or narrower). Larger values of proportional freedom allow the output to be proportionally wider than the total available frame, to a degree that relates to the size difference between the frame and the content (larger difference gives more freedom). The default value of 2.5 is a good compromise between readability/aesthetics and good use of the screen estate. If None, the freedom is unlimited (i.e. proportionality is not taken into account at all).

TYPE: float | None DEFAULT: 2.5

debug

When True, enables additional debugging information in the output, such as the hierarchy of the Model objects. Currently, only Python pretty printers support debug=True. Hence, enabling debug mode will automatically set the printer to the default Python pretty printer if the printer config value is not already set.

TYPE: bool DEFAULT: False

ui

Type of user interface for which the output should being prepared. The user interface describes the technical solutions available for interacting with the user, encompassing the support available for displaying output as well as how the user interacts with the library (including the type of interactive interpreter used, if any).

TYPE: UserInterfaceType.Literals DEFAULT: 'auto'

system

Color system to use for terminal output. The default is AUTO, which automatically detects the color system based on particular environment variables. If color capabilities are not detected, the output will be in black and white. If the color system of a modern consoles/terminal is not auto-detected (which is the case for e.g. the PyCharm console), the user might want to set the color system manually to ANSI_RGB to force color output.

TYPE: ColorSystem.Literals DEFAULT: 'auto'

style

Color style/theme for syntax highlighting and other display elements. Supported styles are defined in AllColorStyles. For non-supported styles, the user can specify a string with the Pygments style name. For this to work, the style must be registered in the Pygments library. If style is AUTO or any of the other RecommendedColorStyles, the style is automatically selected from the RecommendedColorStyles based on the detected user interface, the color system, and whether the background is dark or not.

TYPE: AllColorStyles.Literals | str DEFAULT: 'auto'

dark

Whether the background color of the output is dark. This is used to determine the appropriate color scheme for syntax highlighting. The default is AUTO, which automatically tries to detect whether the background is dark. Capability of auto-detection depends on the user interface.

TYPE: DarkBackground.Literals DEFAULT: 'auto'

bg

If False, uses transparent background for the output. In the case of terminal output, the background color will be the current background color of the terminal. For HTML output, the background color will be automatically set to pure black or pure white, depending on the luminosity of the foreground color.

TYPE: bool DEFAULT: False

fonts

Font families to use in HTML output, in order of preference (empty tuple for browser default).

TYPE: Tuple[str, ...] DEFAULT: ('Menlo', 'DejaVu Sans Mono', 'Consolas', 'Courier New', 'monospace')

font_size

Font size in pixels for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 14

font_weight

Font weight for HTML output (None for browser default).

TYPE: NonNegativeInt | None DEFAULT: 400

line_height

Line height multiplier for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 1.25

h_overflow

How to handle text that exceeds the width.

TYPE: HorizontalOverflowMode.Literals DEFAULT: 'ellipsis'

v_overflow

How to handle text that exceeds the height.

TYPE: VerticalOverflowMode.Literals DEFAULT: 'ellipsis_bottom'

panel

Visual design of the panel used as container for the output. Only TABLE is currently supported, which displays the output in a table-like grid.

TYPE: PanelDesign.Literals DEFAULT: 'table'

title_at_top

Whether panel titles will be displayed over the panel content (True) or below the content (False)

TYPE: bool DEFAULT: True

max_title_height

Maximum height of the panel title. If AUTO, the height is determined by the content of the title, up to a maximum of two lines. If ZERO, the title is not displayed at all. If ONE or TWO, the title is displayed with a fixed height of max one or two lines, respectively.

TYPE: MaxTitleHeight.Literals DEFAULT: -1

min_panel_width

Minimum width in characters per panel.

TYPE: NonNegativeInt DEFAULT: 3

min_crop_width

Minimum cropping width in characters for panels in cases where more than one panel are to be displayed. This is for instance used to calculate the number of models to display in a Dataset peek(). Only applied if use_min_crop_width is set to True. min_crop_width must be equal to or larger than min_panel_width.

TYPE: NonNegativeInt DEFAULT: 33

use_min_crop_width

Whether the min_crop_width value should be considered in cases where more than one panel are to be displayed, potentially reducing the number of displayed panels.

TYPE: bool DEFAULT: False

max_panels_hor

Maximum number of panels to display horizontally side-by-side at the top level. This value also acts as a ceiling for nested panels; nested panels cannot exceed this limit even if the constant MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED is set to a higher value. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 9

max_nesting_depth

Maximum levels of nested panels to display. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 3

justify

Justification mode for the panel if inside a layout panel. This is only used for the panel content.

TYPE: Justify.Literals DEFAULT: 'left'

RETURNS DESCRIPTION
Element | None

If the UI type is Jupyter running in browser, the method returns a ReactivelyResizingHtml element which is a Jupyter widget to display HTML output in the browser. Otherwise, the method returns None.

Note

Any default argument value is overridden by the corresponding value in the relevant subsection of the UserInterfaceConfig.

Source code in src/omnipy/data/_mixins/display.py
def full(self, **kwargs) -> 'Element | None':
    # %% Original docstring (managed by expand_docstr_macros.py) %%
    # {{FULL_SUMMARY}}
    #
    # {{FULL_DESCRIPTION}}
    #
    # {{DISPLAY_METHOD_ARGS}}
    #
    # {{DISPLAY_METHOD_RETURNS}}
    #
    # {{DISPLAY_METHOD_NOTE}}
    #
    #
    """Display the content of the Model or Dataset in full height.

    `full()` is a shorthand for `peek(height=None)` for both
    models and datasets. Both full-height views are automatically
    limited in width by the available display dimensions.

    Args:
        width (NonNegativeInt | None):
            Width in characters of the output area (None for
            auto-detect based on available display dimensions).
        height (NonNegativeInt | None):
            Height in lines of the output area (None for
            auto-detect based on available display dimensions).
        tab (NonNegativeInt):
            Number of spaces to use for each tab.
        indent (NonNegativeInt):
            Number of spaces to use for each indentation level.
        printer (PrettyPrinterLib.Literals):
            Library to use for pretty printing.
        syntax (SyntaxLanguageSpec.Literals | str):
            Syntax language for code highlighting. Supported
            lexers are defined in SyntaxLanguageSpec. For
            non-supported styles, the user can specify a string
            with the Pygments lexer name. For this to work, the
            lexer must be registered in the Pygments library.
        freedom (float | None):
            Parameter that controls the level of freedom for
            formatted text to follow the geometry of the frame
            size (=total available area) in a proportional manner.
            If the proportional freedom is 0 (the lowest), then
            the output area must not in any case be proportionally
            wider that the frame (i.e. a 16/9 frame will only
            produce output that is 16/9 or narrower). Larger
            values of proportional freedom allow the output to be
            proportionally wider than the total available frame,
            to a degree that relates to the size difference
            between the frame and the content (larger difference
            gives more freedom). The default value of 2.5 is a
            good compromise between readability/aesthetics and
            good use of the screen estate. If None, the freedom is
            unlimited (i.e. proportionality is not taken into
            account at all).
        debug (bool):
            When True, enables additional debugging information in
            the output, such as the hierarchy of the Model
            objects. Currently, only Python pretty printers support
            debug=True. Hence, enabling debug mode will
            automatically set the printer to the default Python
            pretty printer if the `printer` config value is not
            already set.
        ui (UserInterfaceType.Literals):
            Type of user interface for which the output should
            being prepared. The user interface describes the
            technical solutions available for interacting with the
            user, encompassing the support available for
            displaying output as well as how the user interacts
            with the library (including the type of interactive
            interpreter used, if any).
        system (ColorSystem.Literals):
            Color system to use for terminal output. The default
            is `AUTO`, which automatically detects the color
            system based on particular environment variables. If
            color capabilities are not detected, the output will
            be in black and white. If the color system of a modern
            consoles/terminal is not auto-detected (which is the
            case for e.g. the PyCharm console), the user might
            want to set the color system manually to ANSI_RGB to
            force color output.
        style (AllColorStyles.Literals | str):
            Color style/theme for syntax highlighting and other
            display elements. Supported styles are defined in
            AllColorStyles. For non-supported styles, the user can
            specify a string with the Pygments style name. For this to
            work, the style must be registered in the Pygments
            library. If style is `AUTO` or any of the other
            RecommendedColorStyles, the style is automatically
            selected from the RecommendedColorStyles based on the
            detected user interface, the color system, and whether the
            background is dark or not.
        dark (DarkBackground.Literals):
            Whether the background color of the output is dark.
            This is used to determine the appropriate color scheme
            for syntax highlighting. The default is AUTO, which
            automatically tries to detect whether the background
            is dark. Capability of auto-detection depends on the
            user interface.
        bg (bool):
            If False, uses transparent background for the output.
            In the case of terminal output, the background color
            will be the current background color of the terminal.
            For HTML output, the background color will be
            automatically set to pure black or pure white,
            depending on the luminosity of the foreground color.
        fonts (Tuple[str, ...]):
            Font families to use in HTML output, in order of
            preference (empty tuple for browser default).
        font_size (NonNegativeFloat | None):
            Font size in pixels for HTML output (None for browser
            default).
        font_weight (NonNegativeInt | None):
            Font weight for HTML output (None for browser
            default).
        line_height (NonNegativeFloat | None):
            Line height multiplier for HTML output (None for
            browser default).
        h_overflow (HorizontalOverflowMode.Literals):
            How to handle text that exceeds the width.
        v_overflow (VerticalOverflowMode.Literals):
            How to handle text that exceeds the height.
        panel (PanelDesign.Literals):
            Visual design of the panel used as container for the
            output. Only `TABLE` is currently supported, which
            displays the output in a table-like grid.
        title_at_top (bool):
            Whether panel titles will be displayed over the panel
            content (True) or below the content (False)
        max_title_height (MaxTitleHeight.Literals):
            Maximum height of the panel title. If `AUTO`, the
            height is determined by the content of the title, up
            to a maximum of two lines. If `ZERO`, the title is not
            displayed at all. If `ONE` or `TWO`, the title is
            displayed with a fixed height of max one or two lines,
            respectively.
        min_panel_width (NonNegativeInt):
            Minimum width in characters per panel.
        min_crop_width (NonNegativeInt):
            Minimum cropping width in characters for panels in
            cases where more than one panel are to be displayed.
            This is for instance used to calculate the number of
            models to display in a Dataset peek(). Only applied if
            `use_min_crop_width` is set to `True`.
            `min_crop_width` must be equal to or larger than
            `min_panel_width`.
        use_min_crop_width (bool):
            Whether the `min_crop_width` value should be
            considered in cases where more than one panel are to
            be displayed, potentially reducing the number of
            displayed panels.
        max_panels_hor (NonNegativeInt | None):
            Maximum number of panels to display horizontally
            side-by-side at the top level. This value also acts as
            a ceiling for nested panels; nested panels cannot
            exceed this limit even if the constant
            `MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED` is set to a
            higher value. If None, there is no limit.
        max_nesting_depth (NonNegativeInt | None):
            Maximum levels of nested panels to display. If None,
            there is no limit.
        justify (Justify.Literals):
            Justification mode for the panel if inside a layout
            panel. This is only used for the panel content.

    Returns:
        If the UI type is Jupyter running in browser, the
        method returns a ReactivelyResizingHtml element which
        is a Jupyter widget to display HTML output in the
        browser. Otherwise, the method returns None.

    Note:
        Any default argument value is overridden by the
        corresponding value in the relevant subsection of the
        UserInterfaceConfig.

    """
    return self._display_according_to_ui_type(
        ui_type=self._extract_ui_type(**kwargs),
        return_output_if_str=False,
        output_method=self._full,
        **kwargs)

get_type cached classmethod

get_type() -> type[_ModelOrDatasetT]

Return the concrete item type stored by this dataset class.

RETURNS DESCRIPTION
type[_ModelOrDatasetT]

The specialized model or nested dataset class used for every item in the dataset.

Source code in src/omnipy/data/dataset.py
@classmethod
@functools.cache
def get_type(cls) -> type[_ModelOrDatasetT]:
    """Return the concrete item type stored by this dataset class.

    Returns:
        The specialized model or nested dataset class used for every item in the dataset.
    """
    # Part of pydantic v1 hack to stop coercing of e.g.
    # [{'a': 'b', 'c': 'd'}] to {'a': 'c'}
    return cls._clean_type(cls._get_data_field().sub_fields[1].type_)  # type: ignore[index]

json

json(
    *,
    width: pyd.NonNegativeInt | None = None,
    height: pyd.NonNegativeInt | None = None,
    tab: pyd.NonNegativeInt = 4,
    indent: pyd.NonNegativeInt = 2,
    printer: PrettyPrinterLib.Literals = "auto",
    syntax: SyntaxLanguageSpec.Literals | str = "auto",
    freedom: pyd.NonNegativeFloat | None = 2.5,
    debug: bool = False,
    ui: UserInterfaceType.Literals = "auto",
    system: DisplayColorSystem.Literals = "auto",
    style: AllColorStyles.Literals | str = "auto",
    dark: typing.Literal["auto", True, False] = "auto",
    bg: bool = False,
    fonts: tuple[str, ...] = ("Menlo", "DejaVu Sans Mono", "Consolas", "Courier New", "monospace"),
    font_size: pyd.NonNegativeFloat | None = 14,
    font_weight: pyd.NonNegativeInt | None = 400,
    line_height: pyd.NonNegativeFloat | None = 1.25,
    h_overflow: HorizontalOverflowMode.Literals = "ellipsis",
    v_overflow: VerticalOverflowMode.Literals = "ellipsis_bottom",
    panel: PanelDesign.Literals = "table",
    title_at_top: bool = True,
    max_title_height: MaxTitleHeight.Literals = -1,
    min_panel_width: pyd.NonNegativeInt = 3,
    min_crop_width: pyd.NonNegativeInt = 33,
    use_min_crop_width: bool = False,
    max_panels_hor: pyd.NonNegativeInt | None = 9,
    max_nesting_depth: pyd.NonNegativeInt | None = 3,
    justify: Justify.Literals = "left",
) -> Element | None

Preview the data content of the Model or Dataset as JSON.

In contrast to e.g. peek(), json() displays the "data content" of the Model or Dataset, i.e. the content as plain Python objects, potentially converted from the internal data structure. This plain data is formatted in JSON (for compactness). Hence json() represents a the basic compatibility layer of all Omnipy Model or Dataset objects. The view is automatically limited by the available display dimensions.

PARAMETER DESCRIPTION
width

Width in characters of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

height

Height in lines of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

tab

Number of spaces to use for each tab.

TYPE: NonNegativeInt DEFAULT: 4

indent

Number of spaces to use for each indentation level.

TYPE: NonNegativeInt DEFAULT: 2

printer

Library to use for pretty printing.

TYPE: PrettyPrinterLib.Literals DEFAULT: 'auto'

syntax

Syntax language for code highlighting. Supported lexers are defined in SyntaxLanguageSpec. For non-supported styles, the user can specify a string with the Pygments lexer name. For this to work, the lexer must be registered in the Pygments library.

TYPE: SyntaxLanguageSpec.Literals | str DEFAULT: 'auto'

freedom

Parameter that controls the level of freedom for formatted text to follow the geometry of the frame size (=total available area) in a proportional manner. If the proportional freedom is 0 (the lowest), then the output area must not in any case be proportionally wider that the frame (i.e. a 16/9 frame will only produce output that is 16/9 or narrower). Larger values of proportional freedom allow the output to be proportionally wider than the total available frame, to a degree that relates to the size difference between the frame and the content (larger difference gives more freedom). The default value of 2.5 is a good compromise between readability/aesthetics and good use of the screen estate. If None, the freedom is unlimited (i.e. proportionality is not taken into account at all).

TYPE: float | None DEFAULT: 2.5

debug

When True, enables additional debugging information in the output, such as the hierarchy of the Model objects. Currently, only Python pretty printers support debug=True. Hence, enabling debug mode will automatically set the printer to the default Python pretty printer if the printer config value is not already set.

TYPE: bool DEFAULT: False

ui

Type of user interface for which the output should being prepared. The user interface describes the technical solutions available for interacting with the user, encompassing the support available for displaying output as well as how the user interacts with the library (including the type of interactive interpreter used, if any).

TYPE: UserInterfaceType.Literals DEFAULT: 'auto'

system

Color system to use for terminal output. The default is AUTO, which automatically detects the color system based on particular environment variables. If color capabilities are not detected, the output will be in black and white. If the color system of a modern consoles/terminal is not auto-detected (which is the case for e.g. the PyCharm console), the user might want to set the color system manually to ANSI_RGB to force color output.

TYPE: ColorSystem.Literals DEFAULT: 'auto'

style

Color style/theme for syntax highlighting and other display elements. Supported styles are defined in AllColorStyles. For non-supported styles, the user can specify a string with the Pygments style name. For this to work, the style must be registered in the Pygments library. If style is AUTO or any of the other RecommendedColorStyles, the style is automatically selected from the RecommendedColorStyles based on the detected user interface, the color system, and whether the background is dark or not.

TYPE: AllColorStyles.Literals | str DEFAULT: 'auto'

dark

Whether the background color of the output is dark. This is used to determine the appropriate color scheme for syntax highlighting. The default is AUTO, which automatically tries to detect whether the background is dark. Capability of auto-detection depends on the user interface.

TYPE: DarkBackground.Literals DEFAULT: 'auto'

bg

If False, uses transparent background for the output. In the case of terminal output, the background color will be the current background color of the terminal. For HTML output, the background color will be automatically set to pure black or pure white, depending on the luminosity of the foreground color.

TYPE: bool DEFAULT: False

fonts

Font families to use in HTML output, in order of preference (empty tuple for browser default).

TYPE: Tuple[str, ...] DEFAULT: ('Menlo', 'DejaVu Sans Mono', 'Consolas', 'Courier New', 'monospace')

font_size

Font size in pixels for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 14

font_weight

Font weight for HTML output (None for browser default).

TYPE: NonNegativeInt | None DEFAULT: 400

line_height

Line height multiplier for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 1.25

h_overflow

How to handle text that exceeds the width.

TYPE: HorizontalOverflowMode.Literals DEFAULT: 'ellipsis'

v_overflow

How to handle text that exceeds the height.

TYPE: VerticalOverflowMode.Literals DEFAULT: 'ellipsis_bottom'

panel

Visual design of the panel used as container for the output. Only TABLE is currently supported, which displays the output in a table-like grid.

TYPE: PanelDesign.Literals DEFAULT: 'table'

title_at_top

Whether panel titles will be displayed over the panel content (True) or below the content (False)

TYPE: bool DEFAULT: True

max_title_height

Maximum height of the panel title. If AUTO, the height is determined by the content of the title, up to a maximum of two lines. If ZERO, the title is not displayed at all. If ONE or TWO, the title is displayed with a fixed height of max one or two lines, respectively.

TYPE: MaxTitleHeight.Literals DEFAULT: -1

min_panel_width

Minimum width in characters per panel.

TYPE: NonNegativeInt DEFAULT: 3

min_crop_width

Minimum cropping width in characters for panels in cases where more than one panel are to be displayed. This is for instance used to calculate the number of models to display in a Dataset peek(). Only applied if use_min_crop_width is set to True. min_crop_width must be equal to or larger than min_panel_width.

TYPE: NonNegativeInt DEFAULT: 33

use_min_crop_width

Whether the min_crop_width value should be considered in cases where more than one panel are to be displayed, potentially reducing the number of displayed panels.

TYPE: bool DEFAULT: False

max_panels_hor

Maximum number of panels to display horizontally side-by-side at the top level. This value also acts as a ceiling for nested panels; nested panels cannot exceed this limit even if the constant MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED is set to a higher value. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 9

max_nesting_depth

Maximum levels of nested panels to display. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 3

justify

Justification mode for the panel if inside a layout panel. This is only used for the panel content.

TYPE: Justify.Literals DEFAULT: 'left'

RETURNS DESCRIPTION
Element | None

If the UI type is Jupyter running in browser, the method returns a ReactivelyResizingHtml element which is a Jupyter widget to display HTML output in the browser. Otherwise, the method returns None.

Note

Any default argument value is overridden by the corresponding value in the relevant subsection of the UserInterfaceConfig.

Source code in src/omnipy/data/_mixins/display.py
def json(self, **kwargs) -> None:
    # %% Original docstring (managed by expand_docstr_macros.py) %%
    # {{JSON_SUMMARY}}
    #
    # {{JSON_DESCRIPTION}}
    #
    # {{DISPLAY_METHOD_ARGS}}
    #
    # {{DISPLAY_METHOD_RETURNS}}
    #
    # {{DISPLAY_METHOD_NOTE}}
    #
    """Preview the data content of the Model or Dataset as JSON.

    In contrast to e.g. `peek()`, `json()` displays the "data
    content" of the Model or Dataset, i.e. the content as plain
    Python objects, potentially converted from the internal data
    structure. This plain data is formatted in JSON (for
    compactness). Hence `json()` represents a the basic
    compatibility layer of all Omnipy Model or Dataset objects.
    The view is automatically limited by the available display
    dimensions.

    Args:
        width (NonNegativeInt | None):
            Width in characters of the output area (None for
            auto-detect based on available display dimensions).
        height (NonNegativeInt | None):
            Height in lines of the output area (None for
            auto-detect based on available display dimensions).
        tab (NonNegativeInt):
            Number of spaces to use for each tab.
        indent (NonNegativeInt):
            Number of spaces to use for each indentation level.
        printer (PrettyPrinterLib.Literals):
            Library to use for pretty printing.
        syntax (SyntaxLanguageSpec.Literals | str):
            Syntax language for code highlighting. Supported
            lexers are defined in SyntaxLanguageSpec. For
            non-supported styles, the user can specify a string
            with the Pygments lexer name. For this to work, the
            lexer must be registered in the Pygments library.
        freedom (float | None):
            Parameter that controls the level of freedom for
            formatted text to follow the geometry of the frame
            size (=total available area) in a proportional manner.
            If the proportional freedom is 0 (the lowest), then
            the output area must not in any case be proportionally
            wider that the frame (i.e. a 16/9 frame will only
            produce output that is 16/9 or narrower). Larger
            values of proportional freedom allow the output to be
            proportionally wider than the total available frame,
            to a degree that relates to the size difference
            between the frame and the content (larger difference
            gives more freedom). The default value of 2.5 is a
            good compromise between readability/aesthetics and
            good use of the screen estate. If None, the freedom is
            unlimited (i.e. proportionality is not taken into
            account at all).
        debug (bool):
            When True, enables additional debugging information in
            the output, such as the hierarchy of the Model
            objects. Currently, only Python pretty printers support
            debug=True. Hence, enabling debug mode will
            automatically set the printer to the default Python
            pretty printer if the `printer` config value is not
            already set.
        ui (UserInterfaceType.Literals):
            Type of user interface for which the output should
            being prepared. The user interface describes the
            technical solutions available for interacting with the
            user, encompassing the support available for
            displaying output as well as how the user interacts
            with the library (including the type of interactive
            interpreter used, if any).
        system (ColorSystem.Literals):
            Color system to use for terminal output. The default
            is `AUTO`, which automatically detects the color
            system based on particular environment variables. If
            color capabilities are not detected, the output will
            be in black and white. If the color system of a modern
            consoles/terminal is not auto-detected (which is the
            case for e.g. the PyCharm console), the user might
            want to set the color system manually to ANSI_RGB to
            force color output.
        style (AllColorStyles.Literals | str):
            Color style/theme for syntax highlighting and other
            display elements. Supported styles are defined in
            AllColorStyles. For non-supported styles, the user can
            specify a string with the Pygments style name. For this to
            work, the style must be registered in the Pygments
            library. If style is `AUTO` or any of the other
            RecommendedColorStyles, the style is automatically
            selected from the RecommendedColorStyles based on the
            detected user interface, the color system, and whether the
            background is dark or not.
        dark (DarkBackground.Literals):
            Whether the background color of the output is dark.
            This is used to determine the appropriate color scheme
            for syntax highlighting. The default is AUTO, which
            automatically tries to detect whether the background
            is dark. Capability of auto-detection depends on the
            user interface.
        bg (bool):
            If False, uses transparent background for the output.
            In the case of terminal output, the background color
            will be the current background color of the terminal.
            For HTML output, the background color will be
            automatically set to pure black or pure white,
            depending on the luminosity of the foreground color.
        fonts (Tuple[str, ...]):
            Font families to use in HTML output, in order of
            preference (empty tuple for browser default).
        font_size (NonNegativeFloat | None):
            Font size in pixels for HTML output (None for browser
            default).
        font_weight (NonNegativeInt | None):
            Font weight for HTML output (None for browser
            default).
        line_height (NonNegativeFloat | None):
            Line height multiplier for HTML output (None for
            browser default).
        h_overflow (HorizontalOverflowMode.Literals):
            How to handle text that exceeds the width.
        v_overflow (VerticalOverflowMode.Literals):
            How to handle text that exceeds the height.
        panel (PanelDesign.Literals):
            Visual design of the panel used as container for the
            output. Only `TABLE` is currently supported, which
            displays the output in a table-like grid.
        title_at_top (bool):
            Whether panel titles will be displayed over the panel
            content (True) or below the content (False)
        max_title_height (MaxTitleHeight.Literals):
            Maximum height of the panel title. If `AUTO`, the
            height is determined by the content of the title, up
            to a maximum of two lines. If `ZERO`, the title is not
            displayed at all. If `ONE` or `TWO`, the title is
            displayed with a fixed height of max one or two lines,
            respectively.
        min_panel_width (NonNegativeInt):
            Minimum width in characters per panel.
        min_crop_width (NonNegativeInt):
            Minimum cropping width in characters for panels in
            cases where more than one panel are to be displayed.
            This is for instance used to calculate the number of
            models to display in a Dataset peek(). Only applied if
            `use_min_crop_width` is set to `True`.
            `min_crop_width` must be equal to or larger than
            `min_panel_width`.
        use_min_crop_width (bool):
            Whether the `min_crop_width` value should be
            considered in cases where more than one panel are to
            be displayed, potentially reducing the number of
            displayed panels.
        max_panels_hor (NonNegativeInt | None):
            Maximum number of panels to display horizontally
            side-by-side at the top level. This value also acts as
            a ceiling for nested panels; nested panels cannot
            exceed this limit even if the constant
            `MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED` is set to a
            higher value. If None, there is no limit.
        max_nesting_depth (NonNegativeInt | None):
            Maximum levels of nested panels to display. If None,
            there is no limit.
        justify (Justify.Literals):
            Justification mode for the panel if inside a layout
            panel. This is only used for the panel content.

    Returns:
        If the UI type is Jupyter running in browser, the
        method returns a ReactivelyResizingHtml element which
        is a Jupyter widget to display HTML output in the
        browser. Otherwise, the method returns None.

    Note:
        Any default argument value is overridden by the
        corresponding value in the relevant subsection of the
        UserInterfaceConfig.
    """
    return self._display_according_to_ui_type(
        ui_type=self._extract_ui_type(**kwargs),
        return_output_if_str=False,
        output_method=self._json,
        **kwargs)

list

list(
    *,
    width: pyd.NonNegativeInt | None = None,
    height: pyd.NonNegativeInt | None = None,
    tab: pyd.NonNegativeInt = 4,
    indent: pyd.NonNegativeInt = 2,
    printer: PrettyPrinterLib.Literals = "auto",
    syntax: SyntaxLanguageSpec.Literals | str = "auto",
    freedom: pyd.NonNegativeFloat | None = 2.5,
    debug: bool = False,
    ui: UserInterfaceType.Literals = "auto",
    system: DisplayColorSystem.Literals = "auto",
    style: AllColorStyles.Literals | str = "auto",
    dark: typing.Literal["auto", True, False] = "auto",
    bg: bool = False,
    fonts: tuple[str, ...] = ("Menlo", "DejaVu Sans Mono", "Consolas", "Courier New", "monospace"),
    font_size: pyd.NonNegativeFloat | None = 14,
    font_weight: pyd.NonNegativeInt | None = 400,
    line_height: pyd.NonNegativeFloat | None = 1.25,
    h_overflow: HorizontalOverflowMode.Literals = "ellipsis",
    v_overflow: VerticalOverflowMode.Literals = "ellipsis_bottom",
    panel: PanelDesign.Literals = "table",
    title_at_top: bool = True,
    max_title_height: MaxTitleHeight.Literals = -1,
    min_panel_width: pyd.NonNegativeInt = 3,
    min_crop_width: pyd.NonNegativeInt = 33,
    use_min_crop_width: bool = False,
    max_panels_hor: pyd.NonNegativeInt | None = 9,
    max_nesting_depth: pyd.NonNegativeInt | None = 3,
    justify: Justify.Literals = "left",
) -> Element | None

Displays a summary list of all models in the dataset.

The summary list includes a number of key properties for each model, including data file names, types, lengths, and sizes in memory. The output is automatically limited by the available display dimensions.

PARAMETER DESCRIPTION
width

Width in characters of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

height

Height in lines of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

tab

Number of spaces to use for each tab.

TYPE: NonNegativeInt DEFAULT: 4

indent

Number of spaces to use for each indentation level.

TYPE: NonNegativeInt DEFAULT: 2

printer

Library to use for pretty printing.

TYPE: PrettyPrinterLib.Literals DEFAULT: 'auto'

syntax

Syntax language for code highlighting. Supported lexers are defined in SyntaxLanguageSpec. For non-supported styles, the user can specify a string with the Pygments lexer name. For this to work, the lexer must be registered in the Pygments library.

TYPE: SyntaxLanguageSpec.Literals | str DEFAULT: 'auto'

freedom

Parameter that controls the level of freedom for formatted text to follow the geometry of the frame size (=total available area) in a proportional manner. If the proportional freedom is 0 (the lowest), then the output area must not in any case be proportionally wider that the frame (i.e. a 16/9 frame will only produce output that is 16/9 or narrower). Larger values of proportional freedom allow the output to be proportionally wider than the total available frame, to a degree that relates to the size difference between the frame and the content (larger difference gives more freedom). The default value of 2.5 is a good compromise between readability/aesthetics and good use of the screen estate. If None, the freedom is unlimited (i.e. proportionality is not taken into account at all).

TYPE: float | None DEFAULT: 2.5

debug

When True, enables additional debugging information in the output, such as the hierarchy of the Model objects. Currently, only Python pretty printers support debug=True. Hence, enabling debug mode will automatically set the printer to the default Python pretty printer if the printer config value is not already set.

TYPE: bool DEFAULT: False

ui

Type of user interface for which the output should being prepared. The user interface describes the technical solutions available for interacting with the user, encompassing the support available for displaying output as well as how the user interacts with the library (including the type of interactive interpreter used, if any).

TYPE: UserInterfaceType.Literals DEFAULT: 'auto'

system

Color system to use for terminal output. The default is AUTO, which automatically detects the color system based on particular environment variables. If color capabilities are not detected, the output will be in black and white. If the color system of a modern consoles/terminal is not auto-detected (which is the case for e.g. the PyCharm console), the user might want to set the color system manually to ANSI_RGB to force color output.

TYPE: ColorSystem.Literals DEFAULT: 'auto'

style

Color style/theme for syntax highlighting and other display elements. Supported styles are defined in AllColorStyles. For non-supported styles, the user can specify a string with the Pygments style name. For this to work, the style must be registered in the Pygments library. If style is AUTO or any of the other RecommendedColorStyles, the style is automatically selected from the RecommendedColorStyles based on the detected user interface, the color system, and whether the background is dark or not.

TYPE: AllColorStyles.Literals | str DEFAULT: 'auto'

dark

Whether the background color of the output is dark. This is used to determine the appropriate color scheme for syntax highlighting. The default is AUTO, which automatically tries to detect whether the background is dark. Capability of auto-detection depends on the user interface.

TYPE: DarkBackground.Literals DEFAULT: 'auto'

bg

If False, uses transparent background for the output. In the case of terminal output, the background color will be the current background color of the terminal. For HTML output, the background color will be automatically set to pure black or pure white, depending on the luminosity of the foreground color.

TYPE: bool DEFAULT: False

fonts

Font families to use in HTML output, in order of preference (empty tuple for browser default).

TYPE: Tuple[str, ...] DEFAULT: ('Menlo', 'DejaVu Sans Mono', 'Consolas', 'Courier New', 'monospace')

font_size

Font size in pixels for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 14

font_weight

Font weight for HTML output (None for browser default).

TYPE: NonNegativeInt | None DEFAULT: 400

line_height

Line height multiplier for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 1.25

h_overflow

How to handle text that exceeds the width.

TYPE: HorizontalOverflowMode.Literals DEFAULT: 'ellipsis'

v_overflow

How to handle text that exceeds the height.

TYPE: VerticalOverflowMode.Literals DEFAULT: 'ellipsis_bottom'

panel

Visual design of the panel used as container for the output. Only TABLE is currently supported, which displays the output in a table-like grid.

TYPE: PanelDesign.Literals DEFAULT: 'table'

title_at_top

Whether panel titles will be displayed over the panel content (True) or below the content (False)

TYPE: bool DEFAULT: True

max_title_height

Maximum height of the panel title. If AUTO, the height is determined by the content of the title, up to a maximum of two lines. If ZERO, the title is not displayed at all. If ONE or TWO, the title is displayed with a fixed height of max one or two lines, respectively.

TYPE: MaxTitleHeight.Literals DEFAULT: -1

min_panel_width

Minimum width in characters per panel.

TYPE: NonNegativeInt DEFAULT: 3

min_crop_width

Minimum cropping width in characters for panels in cases where more than one panel are to be displayed. This is for instance used to calculate the number of models to display in a Dataset peek(). Only applied if use_min_crop_width is set to True. min_crop_width must be equal to or larger than min_panel_width.

TYPE: NonNegativeInt DEFAULT: 33

use_min_crop_width

Whether the min_crop_width value should be considered in cases where more than one panel are to be displayed, potentially reducing the number of displayed panels.

TYPE: bool DEFAULT: False

max_panels_hor

Maximum number of panels to display horizontally side-by-side at the top level. This value also acts as a ceiling for nested panels; nested panels cannot exceed this limit even if the constant MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED is set to a higher value. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 9

max_nesting_depth

Maximum levels of nested panels to display. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 3

justify

Justification mode for the panel if inside a layout panel. This is only used for the panel content.

TYPE: Justify.Literals DEFAULT: 'left'

RETURNS DESCRIPTION
Element | None

If the UI type is Jupyter running in browser, the method returns a ReactivelyResizingHtml element which is a Jupyter widget to display HTML output in the browser. Otherwise, the method returns None.

Note

Any default argument value is overridden by the corresponding value in the relevant subsection of the UserInterfaceConfig.

Source code in src/omnipy/data/_mixins/display.py
def list(self, **kwargs) -> 'Element | None':
    # %% Original docstring (managed by expand_docstr_macros.py) %%
    # {{LIST_SUMMARY}}
    #
    # {{LIST_DESCRIPTION}}
    #
    # {{DISPLAY_METHOD_ARGS}}
    #
    # {{DISPLAY_METHOD_RETURNS}}
    #
    # {{DISPLAY_METHOD_NOTE}}
    #
    """Displays a summary list of all models in the dataset.

    The summary list includes a number of key properties for each
    model, including data file names, types, lengths, and sizes in
    memory. The output is automatically limited by the available
    display dimensions.

    Args:
        width (NonNegativeInt | None):
            Width in characters of the output area (None for
            auto-detect based on available display dimensions).
        height (NonNegativeInt | None):
            Height in lines of the output area (None for
            auto-detect based on available display dimensions).
        tab (NonNegativeInt):
            Number of spaces to use for each tab.
        indent (NonNegativeInt):
            Number of spaces to use for each indentation level.
        printer (PrettyPrinterLib.Literals):
            Library to use for pretty printing.
        syntax (SyntaxLanguageSpec.Literals | str):
            Syntax language for code highlighting. Supported
            lexers are defined in SyntaxLanguageSpec. For
            non-supported styles, the user can specify a string
            with the Pygments lexer name. For this to work, the
            lexer must be registered in the Pygments library.
        freedom (float | None):
            Parameter that controls the level of freedom for
            formatted text to follow the geometry of the frame
            size (=total available area) in a proportional manner.
            If the proportional freedom is 0 (the lowest), then
            the output area must not in any case be proportionally
            wider that the frame (i.e. a 16/9 frame will only
            produce output that is 16/9 or narrower). Larger
            values of proportional freedom allow the output to be
            proportionally wider than the total available frame,
            to a degree that relates to the size difference
            between the frame and the content (larger difference
            gives more freedom). The default value of 2.5 is a
            good compromise between readability/aesthetics and
            good use of the screen estate. If None, the freedom is
            unlimited (i.e. proportionality is not taken into
            account at all).
        debug (bool):
            When True, enables additional debugging information in
            the output, such as the hierarchy of the Model
            objects. Currently, only Python pretty printers support
            debug=True. Hence, enabling debug mode will
            automatically set the printer to the default Python
            pretty printer if the `printer` config value is not
            already set.
        ui (UserInterfaceType.Literals):
            Type of user interface for which the output should
            being prepared. The user interface describes the
            technical solutions available for interacting with the
            user, encompassing the support available for
            displaying output as well as how the user interacts
            with the library (including the type of interactive
            interpreter used, if any).
        system (ColorSystem.Literals):
            Color system to use for terminal output. The default
            is `AUTO`, which automatically detects the color
            system based on particular environment variables. If
            color capabilities are not detected, the output will
            be in black and white. If the color system of a modern
            consoles/terminal is not auto-detected (which is the
            case for e.g. the PyCharm console), the user might
            want to set the color system manually to ANSI_RGB to
            force color output.
        style (AllColorStyles.Literals | str):
            Color style/theme for syntax highlighting and other
            display elements. Supported styles are defined in
            AllColorStyles. For non-supported styles, the user can
            specify a string with the Pygments style name. For this to
            work, the style must be registered in the Pygments
            library. If style is `AUTO` or any of the other
            RecommendedColorStyles, the style is automatically
            selected from the RecommendedColorStyles based on the
            detected user interface, the color system, and whether the
            background is dark or not.
        dark (DarkBackground.Literals):
            Whether the background color of the output is dark.
            This is used to determine the appropriate color scheme
            for syntax highlighting. The default is AUTO, which
            automatically tries to detect whether the background
            is dark. Capability of auto-detection depends on the
            user interface.
        bg (bool):
            If False, uses transparent background for the output.
            In the case of terminal output, the background color
            will be the current background color of the terminal.
            For HTML output, the background color will be
            automatically set to pure black or pure white,
            depending on the luminosity of the foreground color.
        fonts (Tuple[str, ...]):
            Font families to use in HTML output, in order of
            preference (empty tuple for browser default).
        font_size (NonNegativeFloat | None):
            Font size in pixels for HTML output (None for browser
            default).
        font_weight (NonNegativeInt | None):
            Font weight for HTML output (None for browser
            default).
        line_height (NonNegativeFloat | None):
            Line height multiplier for HTML output (None for
            browser default).
        h_overflow (HorizontalOverflowMode.Literals):
            How to handle text that exceeds the width.
        v_overflow (VerticalOverflowMode.Literals):
            How to handle text that exceeds the height.
        panel (PanelDesign.Literals):
            Visual design of the panel used as container for the
            output. Only `TABLE` is currently supported, which
            displays the output in a table-like grid.
        title_at_top (bool):
            Whether panel titles will be displayed over the panel
            content (True) or below the content (False)
        max_title_height (MaxTitleHeight.Literals):
            Maximum height of the panel title. If `AUTO`, the
            height is determined by the content of the title, up
            to a maximum of two lines. If `ZERO`, the title is not
            displayed at all. If `ONE` or `TWO`, the title is
            displayed with a fixed height of max one or two lines,
            respectively.
        min_panel_width (NonNegativeInt):
            Minimum width in characters per panel.
        min_crop_width (NonNegativeInt):
            Minimum cropping width in characters for panels in
            cases where more than one panel are to be displayed.
            This is for instance used to calculate the number of
            models to display in a Dataset peek(). Only applied if
            `use_min_crop_width` is set to `True`.
            `min_crop_width` must be equal to or larger than
            `min_panel_width`.
        use_min_crop_width (bool):
            Whether the `min_crop_width` value should be
            considered in cases where more than one panel are to
            be displayed, potentially reducing the number of
            displayed panels.
        max_panels_hor (NonNegativeInt | None):
            Maximum number of panels to display horizontally
            side-by-side at the top level. This value also acts as
            a ceiling for nested panels; nested panels cannot
            exceed this limit even if the constant
            `MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED` is set to a
            higher value. If None, there is no limit.
        max_nesting_depth (NonNegativeInt | None):
            Maximum levels of nested panels to display. If None,
            there is no limit.
        justify (Justify.Literals):
            Justification mode for the panel if inside a layout
            panel. This is only used for the panel content.

    Returns:
        If the UI type is Jupyter running in browser, the
        method returns a ReactivelyResizingHtml element which
        is a Jupyter widget to display HTML output in the
        browser. Otherwise, the method returns None.

    Note:
        Any default argument value is overridden by the
        corresponding value in the relevant subsection of the
        UserInterfaceConfig.
    """

    return self._display_according_to_ui_type(
        ui_type=self._extract_ui_type(**kwargs),
        return_output_if_str=False,
        output_method=self._list,
        **kwargs,
    )

load classmethod

load(
    paths_or_urls: IsPathsOrUrlsOneOrMoreOrNone = None,
    by_file_suffix: bool = False,
    as_mime_type: None | str = None,
    **kwargs: IsPathOrUrl,
) -> Self | asyncio.Task[Self]

Create a dataset and load serialized contents into it.

PARAMETER DESCRIPTION
paths_or_urls

Path, URL, iterable of paths or URLs, or dataset/model of HTTP URLs to load from.

TYPE: IsPathsOrUrlsOneOrMoreOrNone DEFAULT: None

by_file_suffix

Whether serializer lookup should prefer file-suffix detection.

TYPE: bool DEFAULT: False

as_mime_type

Optional MIME type hint for HTTP loading.

TYPE: None | str DEFAULT: None

**kwargs

Alternate keyed path or URL arguments when paths_or_urls is omitted.

TYPE: IsPathOrUrl DEFAULT: {}

RETURNS DESCRIPTION
Self | asyncio.Task[Self]

A loaded dataset, or an asyncio.Task when called inside a running event loop.

Source code in src/omnipy/data/dataset.py
@classmethod
def load(
    cls,
    paths_or_urls: IsPathsOrUrlsOneOrMoreOrNone = None,
    by_file_suffix: bool = False,
    as_mime_type: None | str = None,
    **kwargs: IsPathOrUrl,
) -> Self | asyncio.Task[Self]:
    """Create a dataset and load serialized contents into it.

    Args:
        paths_or_urls: Path, URL, iterable of paths or URLs, or dataset/model of HTTP URLs to
            load from.
        by_file_suffix: Whether serializer lookup should prefer file-suffix detection.
        as_mime_type: Optional MIME type hint for HTTP loading.
        **kwargs: Alternate keyed path or URL arguments when ``paths_or_urls`` is omitted.

    Returns:
        A loaded dataset, or an ``asyncio.Task`` when called inside a running event loop.
    """
    dataset = cls()
    return dataset.load_into(
        paths_or_urls, by_file_suffix=by_file_suffix, as_mime_type=as_mime_type, **kwargs)

load_into

load_into(
    paths_or_urls: IsPathsOrUrlsOneOrMoreOrNone = None,
    by_file_suffix: bool = False,
    as_mime_type: None | str = None,
    **kwargs: IsPathOrUrl,
) -> Self | asyncio.Task[Self]

Load serialized contents into this dataset instance.

PARAMETER DESCRIPTION
paths_or_urls

Path, URL, iterable of paths or URLs, or dataset/model of HTTP URLs to load from.

TYPE: IsPathsOrUrlsOneOrMoreOrNone DEFAULT: None

by_file_suffix

Whether serializer lookup should prefer file-suffix detection.

TYPE: bool DEFAULT: False

as_mime_type

Optional MIME type hint for HTTP loading.

TYPE: None | str DEFAULT: None

**kwargs

Alternate keyed path or URL arguments when paths_or_urls is omitted.

TYPE: IsPathOrUrl DEFAULT: {}

RETURNS DESCRIPTION
Self | asyncio.Task[Self]

This dataset instance after loading, or an asyncio.Task when called inside a running event loop.

RAISES DESCRIPTION
AssertionError

If the input forms are combined incorrectly.

TypeError

If paths_or_urls has an unsupported type.

NotImplementedError

If keyed local-path loading is requested.

Source code in src/omnipy/data/dataset.py
def load_into(
    self,
    paths_or_urls: IsPathsOrUrlsOneOrMoreOrNone = None,
    by_file_suffix: bool = False,
    as_mime_type: None | str = None,
    **kwargs: IsPathOrUrl,
) -> Self | asyncio.Task[Self]:
    """Load serialized contents into this dataset instance.

    Args:
        paths_or_urls: Path, URL, iterable of paths or URLs, or dataset/model of HTTP URLs to
            load from.
        by_file_suffix: Whether serializer lookup should prefer file-suffix detection.
        as_mime_type: Optional MIME type hint for HTTP loading.
        **kwargs: Alternate keyed path or URL arguments when ``paths_or_urls`` is omitted.

    Returns:
        This dataset instance after loading, or an ``asyncio.Task`` when called inside a
        running event loop.

    Raises:
        AssertionError: If the input forms are combined incorrectly.
        TypeError: If ``paths_or_urls`` has an unsupported type.
        NotImplementedError: If keyed local-path loading is requested.
    """
    from omnipy.components.remote.datasets import HttpUrlDataset
    from omnipy.components.remote.models import HttpUrlModel

    if paths_or_urls is None:
        assert len(kwargs) > 0, 'No paths or urls specified'
        paths_or_urls = kwargs
    else:
        assert len(kwargs) == 0, 'No keyword arguments allowed when paths_or_urls is specified'

    match paths_or_urls:
        case HttpUrlDataset():
            return self._load_http_urls(paths_or_urls, as_mime_type=as_mime_type)

        case HttpUrlModel():
            return self._load_http_urls(
                HttpUrlDataset({str(paths_or_urls): paths_or_urls}),
                as_mime_type=as_mime_type,
            )

        case str():
            try:
                http_url_dataset = HttpUrlDataset({paths_or_urls: paths_or_urls})
            except ValidationError:
                return self._load_paths([paths_or_urls], by_file_suffix)
            return self._load_http_urls(http_url_dataset, as_mime_type=as_mime_type)

        case Mapping():
            try:
                http_url_dataset = HttpUrlDataset(paths_or_urls)
            except ValidationError as exp:
                raise NotImplementedError(
                    'Loading files with specified keys is not yet '
                    'implemented, as only tar.gz file import is '
                    'supported until serializers have been refactored.') from exp
            return self._load_http_urls(http_url_dataset, as_mime_type=as_mime_type)

        case Iterable():
            path_or_url_iterable = paths_or_urls
            try:
                http_url_dataset = HttpUrlDataset(
                    zip(path_or_url_iterable, path_or_url_iterable))
            except ValidationError:
                return self._load_paths(path_or_url_iterable, by_file_suffix)
            return self._load_http_urls(http_url_dataset, as_mime_type=as_mime_type)
        case _:
            raise TypeError(f'"paths_or_urls" argument is of incorrect type. Type '
                            f'{type(paths_or_urls)} is not supported.')

peek

peek(
    *,
    width: pyd.NonNegativeInt | None = None,
    height: pyd.NonNegativeInt | None = None,
    tab: pyd.NonNegativeInt = 4,
    indent: pyd.NonNegativeInt = 2,
    printer: PrettyPrinterLib.Literals = "auto",
    syntax: SyntaxLanguageSpec.Literals | str = "auto",
    freedom: pyd.NonNegativeFloat | None = 2.5,
    debug: bool = False,
    ui: UserInterfaceType.Literals = "auto",
    system: DisplayColorSystem.Literals = "auto",
    style: AllColorStyles.Literals | str = "auto",
    dark: typing.Literal["auto", True, False] = "auto",
    bg: bool = False,
    fonts: tuple[str, ...] = ("Menlo", "DejaVu Sans Mono", "Consolas", "Courier New", "monospace"),
    font_size: pyd.NonNegativeFloat | None = 14,
    font_weight: pyd.NonNegativeInt | None = 400,
    line_height: pyd.NonNegativeFloat | None = 1.25,
    h_overflow: HorizontalOverflowMode.Literals = "ellipsis",
    v_overflow: VerticalOverflowMode.Literals = "ellipsis_bottom",
    panel: PanelDesign.Literals = "table",
    title_at_top: bool = True,
    max_title_height: MaxTitleHeight.Literals = -1,
    min_panel_width: pyd.NonNegativeInt = 3,
    min_crop_width: pyd.NonNegativeInt = 33,
    use_min_crop_width: bool = False,
    max_panels_hor: pyd.NonNegativeInt | None = 9,
    max_nesting_depth: pyd.NonNegativeInt | None = 3,
    justify: Justify.Literals = "left",
) -> Element | None

Display a preview of the Model or Dataset content.

For Model instances, peek() displays a preview of the model's content. For Dataset instances, peek() displays a side-by-side view of each model contained in the dataset. Both views are automatically limited by the available display dimensions.

PARAMETER DESCRIPTION
width

Width in characters of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

height

Height in lines of the output area (None for auto-detect based on available display dimensions).

TYPE: NonNegativeInt | None DEFAULT: None

tab

Number of spaces to use for each tab.

TYPE: NonNegativeInt DEFAULT: 4

indent

Number of spaces to use for each indentation level.

TYPE: NonNegativeInt DEFAULT: 2

printer

Library to use for pretty printing.

TYPE: PrettyPrinterLib.Literals DEFAULT: 'auto'

syntax

Syntax language for code highlighting. Supported lexers are defined in SyntaxLanguageSpec. For non-supported styles, the user can specify a string with the Pygments lexer name. For this to work, the lexer must be registered in the Pygments library.

TYPE: SyntaxLanguageSpec.Literals | str DEFAULT: 'auto'

freedom

Parameter that controls the level of freedom for formatted text to follow the geometry of the frame size (=total available area) in a proportional manner. If the proportional freedom is 0 (the lowest), then the output area must not in any case be proportionally wider that the frame (i.e. a 16/9 frame will only produce output that is 16/9 or narrower). Larger values of proportional freedom allow the output to be proportionally wider than the total available frame, to a degree that relates to the size difference between the frame and the content (larger difference gives more freedom). The default value of 2.5 is a good compromise between readability/aesthetics and good use of the screen estate. If None, the freedom is unlimited (i.e. proportionality is not taken into account at all).

TYPE: float | None DEFAULT: 2.5

debug

When True, enables additional debugging information in the output, such as the hierarchy of the Model objects. Currently, only Python pretty printers support debug=True. Hence, enabling debug mode will automatically set the printer to the default Python pretty printer if the printer config value is not already set.

TYPE: bool DEFAULT: False

ui

Type of user interface for which the output should being prepared. The user interface describes the technical solutions available for interacting with the user, encompassing the support available for displaying output as well as how the user interacts with the library (including the type of interactive interpreter used, if any).

TYPE: UserInterfaceType.Literals DEFAULT: 'auto'

system

Color system to use for terminal output. The default is AUTO, which automatically detects the color system based on particular environment variables. If color capabilities are not detected, the output will be in black and white. If the color system of a modern consoles/terminal is not auto-detected (which is the case for e.g. the PyCharm console), the user might want to set the color system manually to ANSI_RGB to force color output.

TYPE: ColorSystem.Literals DEFAULT: 'auto'

style

Color style/theme for syntax highlighting and other display elements. Supported styles are defined in AllColorStyles. For non-supported styles, the user can specify a string with the Pygments style name. For this to work, the style must be registered in the Pygments library. If style is AUTO or any of the other RecommendedColorStyles, the style is automatically selected from the RecommendedColorStyles based on the detected user interface, the color system, and whether the background is dark or not.

TYPE: AllColorStyles.Literals | str DEFAULT: 'auto'

dark

Whether the background color of the output is dark. This is used to determine the appropriate color scheme for syntax highlighting. The default is AUTO, which automatically tries to detect whether the background is dark. Capability of auto-detection depends on the user interface.

TYPE: DarkBackground.Literals DEFAULT: 'auto'

bg

If False, uses transparent background for the output. In the case of terminal output, the background color will be the current background color of the terminal. For HTML output, the background color will be automatically set to pure black or pure white, depending on the luminosity of the foreground color.

TYPE: bool DEFAULT: False

fonts

Font families to use in HTML output, in order of preference (empty tuple for browser default).

TYPE: Tuple[str, ...] DEFAULT: ('Menlo', 'DejaVu Sans Mono', 'Consolas', 'Courier New', 'monospace')

font_size

Font size in pixels for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 14

font_weight

Font weight for HTML output (None for browser default).

TYPE: NonNegativeInt | None DEFAULT: 400

line_height

Line height multiplier for HTML output (None for browser default).

TYPE: NonNegativeFloat | None DEFAULT: 1.25

h_overflow

How to handle text that exceeds the width.

TYPE: HorizontalOverflowMode.Literals DEFAULT: 'ellipsis'

v_overflow

How to handle text that exceeds the height.

TYPE: VerticalOverflowMode.Literals DEFAULT: 'ellipsis_bottom'

panel

Visual design of the panel used as container for the output. Only TABLE is currently supported, which displays the output in a table-like grid.

TYPE: PanelDesign.Literals DEFAULT: 'table'

title_at_top

Whether panel titles will be displayed over the panel content (True) or below the content (False)

TYPE: bool DEFAULT: True

max_title_height

Maximum height of the panel title. If AUTO, the height is determined by the content of the title, up to a maximum of two lines. If ZERO, the title is not displayed at all. If ONE or TWO, the title is displayed with a fixed height of max one or two lines, respectively.

TYPE: MaxTitleHeight.Literals DEFAULT: -1

min_panel_width

Minimum width in characters per panel.

TYPE: NonNegativeInt DEFAULT: 3

min_crop_width

Minimum cropping width in characters for panels in cases where more than one panel are to be displayed. This is for instance used to calculate the number of models to display in a Dataset peek(). Only applied if use_min_crop_width is set to True. min_crop_width must be equal to or larger than min_panel_width.

TYPE: NonNegativeInt DEFAULT: 33

use_min_crop_width

Whether the min_crop_width value should be considered in cases where more than one panel are to be displayed, potentially reducing the number of displayed panels.

TYPE: bool DEFAULT: False

max_panels_hor

Maximum number of panels to display horizontally side-by-side at the top level. This value also acts as a ceiling for nested panels; nested panels cannot exceed this limit even if the constant MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED is set to a higher value. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 9

max_nesting_depth

Maximum levels of nested panels to display. If None, there is no limit.

TYPE: NonNegativeInt | None DEFAULT: 3

justify

Justification mode for the panel if inside a layout panel. This is only used for the panel content.

TYPE: Justify.Literals DEFAULT: 'left'

RETURNS DESCRIPTION
Element | None

If the UI type is Jupyter running in browser, the method returns a ReactivelyResizingHtml element which is a Jupyter widget to display HTML output in the browser. Otherwise, the method returns None.

Note

Any default argument value is overridden by the corresponding value in the relevant subsection of the UserInterfaceConfig.

Source code in src/omnipy/data/_mixins/display.py
def peek(self, **kwargs) -> 'Element | None':
    # %% Original docstring (managed by expand_docstr_macros.py) %%
    # {{PEEK_SUMMARY}}
    #
    # {{PEEK_DESCRIPTION}}
    #
    # {{DISPLAY_METHOD_ARGS}}
    #
    # {{DISPLAY_METHOD_RETURNS}}
    #
    # {{DISPLAY_METHOD_NOTE}}
    #
    """Display a preview of the Model or Dataset content.

    For Model instances, `peek()` displays a preview of the
    model's content. For Dataset instances, `peek()` displays a
    side-by-side view of each model contained in the dataset. Both
    views are automatically limited by the available display
    dimensions.

    Args:
        width (NonNegativeInt | None):
            Width in characters of the output area (None for
            auto-detect based on available display dimensions).
        height (NonNegativeInt | None):
            Height in lines of the output area (None for
            auto-detect based on available display dimensions).
        tab (NonNegativeInt):
            Number of spaces to use for each tab.
        indent (NonNegativeInt):
            Number of spaces to use for each indentation level.
        printer (PrettyPrinterLib.Literals):
            Library to use for pretty printing.
        syntax (SyntaxLanguageSpec.Literals | str):
            Syntax language for code highlighting. Supported
            lexers are defined in SyntaxLanguageSpec. For
            non-supported styles, the user can specify a string
            with the Pygments lexer name. For this to work, the
            lexer must be registered in the Pygments library.
        freedom (float | None):
            Parameter that controls the level of freedom for
            formatted text to follow the geometry of the frame
            size (=total available area) in a proportional manner.
            If the proportional freedom is 0 (the lowest), then
            the output area must not in any case be proportionally
            wider that the frame (i.e. a 16/9 frame will only
            produce output that is 16/9 or narrower). Larger
            values of proportional freedom allow the output to be
            proportionally wider than the total available frame,
            to a degree that relates to the size difference
            between the frame and the content (larger difference
            gives more freedom). The default value of 2.5 is a
            good compromise between readability/aesthetics and
            good use of the screen estate. If None, the freedom is
            unlimited (i.e. proportionality is not taken into
            account at all).
        debug (bool):
            When True, enables additional debugging information in
            the output, such as the hierarchy of the Model
            objects. Currently, only Python pretty printers support
            debug=True. Hence, enabling debug mode will
            automatically set the printer to the default Python
            pretty printer if the `printer` config value is not
            already set.
        ui (UserInterfaceType.Literals):
            Type of user interface for which the output should
            being prepared. The user interface describes the
            technical solutions available for interacting with the
            user, encompassing the support available for
            displaying output as well as how the user interacts
            with the library (including the type of interactive
            interpreter used, if any).
        system (ColorSystem.Literals):
            Color system to use for terminal output. The default
            is `AUTO`, which automatically detects the color
            system based on particular environment variables. If
            color capabilities are not detected, the output will
            be in black and white. If the color system of a modern
            consoles/terminal is not auto-detected (which is the
            case for e.g. the PyCharm console), the user might
            want to set the color system manually to ANSI_RGB to
            force color output.
        style (AllColorStyles.Literals | str):
            Color style/theme for syntax highlighting and other
            display elements. Supported styles are defined in
            AllColorStyles. For non-supported styles, the user can
            specify a string with the Pygments style name. For this to
            work, the style must be registered in the Pygments
            library. If style is `AUTO` or any of the other
            RecommendedColorStyles, the style is automatically
            selected from the RecommendedColorStyles based on the
            detected user interface, the color system, and whether the
            background is dark or not.
        dark (DarkBackground.Literals):
            Whether the background color of the output is dark.
            This is used to determine the appropriate color scheme
            for syntax highlighting. The default is AUTO, which
            automatically tries to detect whether the background
            is dark. Capability of auto-detection depends on the
            user interface.
        bg (bool):
            If False, uses transparent background for the output.
            In the case of terminal output, the background color
            will be the current background color of the terminal.
            For HTML output, the background color will be
            automatically set to pure black or pure white,
            depending on the luminosity of the foreground color.
        fonts (Tuple[str, ...]):
            Font families to use in HTML output, in order of
            preference (empty tuple for browser default).
        font_size (NonNegativeFloat | None):
            Font size in pixels for HTML output (None for browser
            default).
        font_weight (NonNegativeInt | None):
            Font weight for HTML output (None for browser
            default).
        line_height (NonNegativeFloat | None):
            Line height multiplier for HTML output (None for
            browser default).
        h_overflow (HorizontalOverflowMode.Literals):
            How to handle text that exceeds the width.
        v_overflow (VerticalOverflowMode.Literals):
            How to handle text that exceeds the height.
        panel (PanelDesign.Literals):
            Visual design of the panel used as container for the
            output. Only `TABLE` is currently supported, which
            displays the output in a table-like grid.
        title_at_top (bool):
            Whether panel titles will be displayed over the panel
            content (True) or below the content (False)
        max_title_height (MaxTitleHeight.Literals):
            Maximum height of the panel title. If `AUTO`, the
            height is determined by the content of the title, up
            to a maximum of two lines. If `ZERO`, the title is not
            displayed at all. If `ONE` or `TWO`, the title is
            displayed with a fixed height of max one or two lines,
            respectively.
        min_panel_width (NonNegativeInt):
            Minimum width in characters per panel.
        min_crop_width (NonNegativeInt):
            Minimum cropping width in characters for panels in
            cases where more than one panel are to be displayed.
            This is for instance used to calculate the number of
            models to display in a Dataset peek(). Only applied if
            `use_min_crop_width` is set to `True`.
            `min_crop_width` must be equal to or larger than
            `min_panel_width`.
        use_min_crop_width (bool):
            Whether the `min_crop_width` value should be
            considered in cases where more than one panel are to
            be displayed, potentially reducing the number of
            displayed panels.
        max_panels_hor (NonNegativeInt | None):
            Maximum number of panels to display horizontally
            side-by-side at the top level. This value also acts as
            a ceiling for nested panels; nested panels cannot
            exceed this limit even if the constant
            `MAX_PANELS_HORIZONTALLY_DEEPLY_NESTED` is set to a
            higher value. If None, there is no limit.
        max_nesting_depth (NonNegativeInt | None):
            Maximum levels of nested panels to display. If None,
            there is no limit.
        justify (Justify.Literals):
            Justification mode for the panel if inside a layout
            panel. This is only used for the panel content.

    Returns:
        If the UI type is Jupyter running in browser, the
        method returns a ReactivelyResizingHtml element which
        is a Jupyter widget to display HTML output in the
        browser. Otherwise, the method returns None.

    Note:
        Any default argument value is overridden by the
        corresponding value in the relevant subsection of the
        UserInterfaceConfig.
    """
    return self._display_according_to_ui_type(
        ui_type=self._extract_ui_type(**kwargs),
        return_output_if_str=False,
        output_method=self._peek,
        **kwargs,
    )

pending_task_details

pending_task_details() -> dict[str, IsPendingData]

Return pending task marker payloads keyed by dataset entry name.

Source code in src/omnipy/data/_mixins/task.py
def pending_task_details(self) -> dict[str, IsPendingData]:
    """Return pending task marker payloads keyed by dataset entry name."""

    self_with_data = cast(HasData, self)
    return {  # pyright: ignore [reportReturnType]
        key: val for key, val in self_with_data.data.items() if isinstance(val, PendingData)
    }

save

save(path: str)

Serialize the dataset to a .tar.gz archive and extract a directory copy.

PARAMETER DESCRIPTION
path

Destination path with or without the .tar.gz suffix.

TYPE: str

Source code in src/omnipy/data/dataset.py
def save(self, path: str):
    """Serialize the dataset to a ``.tar.gz`` archive and extract a directory copy.

    Args:
        path: Destination path with or without the ``.tar.gz`` suffix.
    """
    serializer_registry = self._get_serializer_registry()

    parsed_dataset, serializer = serializer_registry.auto_detect_tar_file_serializer(self)

    if serializer is None:
        print(f'Unable to find a serializer for dataset with data type "{type(self)}". '
              f'Will abort saving...')
    else:
        if not path.endswith('.tar.gz'):
            out_tar_gz_path = f'{path}.tar.gz'

        print(f'Writing dataset as a gzipped tarpack to "{os.path.abspath(out_tar_gz_path)}"')

        with open(out_tar_gz_path, 'wb') as out_tar_gz_file:
            out_tar_gz_file.write(serializer.serialize(parsed_dataset))

        directory = os.path.abspath(out_tar_gz_path[:-7])
        if not os.path.exists(directory):
            os.makedirs(directory)

        tar = tarfile.open(out_tar_gz_path)
        print(f'Extracting content to directory "{os.path.abspath(out_tar_gz_path[:-7])}"')
        tar.extractall(path=directory)
        tar.close()

to

to(model_or_dataset_cls: type[_OtherModelOrDatasetT]) -> _OtherModelOrDatasetT

Convert this dataset to another model or dataset class.

PARAMETER DESCRIPTION
model_or_dataset_cls

Target model or dataset class that can be constructed from this dataset.

TYPE: type[_OtherModelOrDatasetT]

RETURNS DESCRIPTION
_OtherModelOrDatasetT

An instance of the requested target class.

Source code in src/omnipy/data/dataset.py
def to(self, model_or_dataset_cls: type[_OtherModelOrDatasetT]) -> '_OtherModelOrDatasetT':
    """Convert this dataset to another model or dataset class.

    Args:
        model_or_dataset_cls: Target model or dataset class that can be constructed from this
            dataset.

    Returns:
        An instance of the requested target class.
    """
    return model_or_dataset_cls(self)

to_data

to_data() -> dict_t[str, Any]

Return the dataset as plain Python contents.

RETURNS DESCRIPTION
dict_t[str, Any]

A mapping from data-file name to plain Python data extracted from each validated item.

Source code in src/omnipy/data/dataset.py
def to_data(self) -> dict_t[str, Any]:
    """Return the dataset as plain Python contents.

    Returns:
        A mapping from data-file name to plain Python data extracted from each validated item.
    """
    return {key: self._check_value(val) for key, val in self.dict(by_alias=True).items()}

to_json

to_json(pretty=True) -> dict_t[str, str]

Serialize each dataset item to JSON.

PARAMETER DESCRIPTION
pretty

Whether to pretty-print the JSON for each item.

DEFAULT: True

RETURNS DESCRIPTION
dict_t[str, str]

A mapping from data-file name to JSON string.

Source code in src/omnipy/data/dataset.py
def to_json(self, pretty=True) -> dict_t[str, str]:
    """Serialize each dataset item to JSON.

    Args:
        pretty: Whether to pretty-print the JSON for each item.

    Returns:
        A mapping from data-file name to JSON string.
    """
    result = {}

    for key, val in self.data.items():
        result[key] = val.to_json(pretty=pretty)

    return result

to_json_schema classmethod

to_json_schema(pretty: bool = True) -> str | dict_t[str, str]

Return a JSON schema for the dataset's serialized contents.

PARAMETER DESCRIPTION
pretty

Whether to return pretty-printed JSON text instead of compact JSON text.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
str | dict_t[str, str]

A JSON schema string describing the dataset contents.

Source code in src/omnipy/data/dataset.py
@classmethod
def to_json_schema(cls, pretty: bool = True) -> str | dict_t[str, str]:
    """Return a JSON schema for the dataset's serialized contents.

    Args:
        pretty: Whether to return pretty-printed JSON text instead of compact JSON text.

    Returns:
        A JSON schema string describing the dataset contents.
    """
    result = {}
    clean_dataset = super(Dataset, Dataset).__class_getitem__(cls.get_type())
    schema = clean_dataset.schema()
    for key, val in schema['properties'][DATA_KEY].items():
        # Remove the first part of the type definition of 'data', added
        # as a hack to stop coercing of e.g. [{'a': 'b', 'c': 'd'}]
        # to {'a': 'c'}
        if key == 'anyOf':
            result['type'] = 'object'
            result['additionalProperties'] = {
                '$ref': '#/definitions/' + pyd.normalize_name(clean_dataset.get_type().__name__)
            }
        else:
            result[key] = val

    result['title'] = clean_dataset.__name__
    result['definitions'] = schema['definitions']

    for model_desc in result['definitions'].values():
        if 'orig_model' in model_desc:
            del model_desc['orig_model']

    if pretty:
        return cls._pretty_print_json(result)
    else:
        return json.dumps(result)

update_forward_refs classmethod

update_forward_refs(
    calling_module: str | None = None, prev_visited_classes: set[type] | None = None, **localns: Any
) -> None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

Source code in src/omnipy/data/dataset.py
@classmethod
def update_forward_refs(
    cls,
    calling_module: str | None = None,
    prev_visited_classes: set[type] | None = None,
    **localns: Any,
) -> None:
    """
    Try to update ForwardRefs on fields based on this Model, globalns and localns.
    """

    from omnipy.data.model import is_model_subclass

    if prev_visited_classes is None:
        prev_visited_classes = set()
    elif cls in prev_visited_classes:
        return

    # Merge the namespaces of the Datasets's own module and the
    # calling module to the local namespace for evaluation of forward
    # references, which is necessary for cases where the Dataset is
    # defined in a different module than where it is used, e.g. when
    # the Dataset is defined in a library and used by a user in their
    # own code.
    if calling_module is None:
        calling_module = get_calling_module_name()
    own_module_ns, globalns = \
        build_own_module_and_global_namespace_for_forward_refs(cls, calling_module, **localns)

    prev_type = cls._get_data_field().type_

    super().update_forward_refs(**globalns)

    cls._get_data_field().type_ = evaluate_any_forward_refs_if_possible(prev_type, **globalns)
    if DATA_KEY in cls.__annotations__:
        cls.__annotations__[DATA_KEY] = evaluate_any_forward_refs_if_possible(
            cls.__annotations__[DATA_KEY], **globalns)

    cls._clean_type_caches()

    prev_visited_classes.add(cls)

    # Merge the Dataset's own module namespace into
    # localns before propagating. This is to allow Model classes and
    # pydantic-generated parametrized base classes (which have
    # __module__='omnipy.data.dataset' rather than the defining
    # module) to still resolve forward refs that only exist
    # in the defining module's namespace.

    extra_ns: dict[str, Any] = {}
    extra_ns.update(own_module_ns)
    extra_ns.update(localns)

    # Propagate update_forward_refs to parent Dataset classes but
    # retaining the same calling module. This is needed to ensure the
    # correct context is used to resolve forward references in complex
    # inheritance hierarchies.
    #
    # We explicitly call `update_forward_refs` on immediate parent
    # classes (`__bases__`) instead of relying solely on
    # `super().update_forward_refs()`. This is because `super()`
    # inside this classmethod resolves relative to `Dataset` in the MRO,
    # silently bypassing custom logic on any intermediate `Dataset`
    # subclasses. Explicitly propagating through `__bases__` ensures
    # that class-level setups are correctly applied to all parents
    # exactly once, efficiently preventing redundant updates.
    for base in cls.__bases__:
        if is_dataset_subclass(base) and base is not Dataset:
            base.update_forward_refs(
                calling_module=calling_module,
                prev_visited_classes=prev_visited_classes,
                **extra_ns,
            )

    # As above, but now propagate update_forward_refs to the types of
    # the Dataset (e.g. the Model).
    for type_variant in split_to_union_variants(cls.get_type()):
        if is_dataset_subclass(type_variant) or is_model_subclass(type_variant):
            type_variant.update_forward_refs(
                calling_module=calling_module,
                prev_visited_classes=prev_visited_classes,
                **extra_ns,
            )

    cls.__name__ = remove_forward_ref_notation(cls.__name__)
    cls.__qualname__ = remove_forward_ref_notation(cls.__qualname__)

update_reactive_views

update_reactive_views()
Source code in src/omnipy/data/_mixins/display.py
def update_reactive_views(self):
    from omnipy import runtime
    assert runtime.objects.reactive is not None
    obj_id_update_flags = runtime.objects.reactive.obj_id_update_flags.value.copy()
    flag = obj_id_update_flags.get(id(self), False)
    obj_id_update_flags[id(self)] = not flag
    runtime.objects.reactive.obj_id_update_flags.set(obj_id_update_flags)

validate classmethod

validate(value: Any) -> Self

Validate arbitrary input as an instance of this dataset class.

This method is primarily part of the Pydantic integration layer and preserves dataset validation behavior when iterables are accepted as input.

PARAMETER DESCRIPTION
value

The value to validate.

TYPE: Any

RETURNS DESCRIPTION
Self

A validated dataset instance.

Source code in src/omnipy/data/dataset.py
@classmethod
def validate(cls, value: Any) -> Self:
    """Validate arbitrary input as an instance of this dataset class.

    This method is primarily part of the Pydantic integration layer and preserves dataset
    validation behavior when iterables are accepted as input.

    Args:
        value: The value to validate.

    Returns:
        A validated dataset instance.
    """
    # TODO: Doublecheck if validate() method is still needed for pydantic v2

    # validate_cls_counts[cls.__name__] += 1
    if is_iterable(value) and not isinstance(value, Mapping):
        value = cls._check_iterable(value)

    return super().validate({'data': value})

is_dataset_instance

is_dataset_instance(__obj: object) -> TypeIs[Dataset]

Return whether an object is a dataset instance.

PARAMETER DESCRIPTION
__obj

Object to test.

TYPE: object

RETURNS DESCRIPTION
TypeIs[Dataset]

True if the object is recognized as a Dataset instance.

Source code in src/omnipy/data/dataset.py
def is_dataset_instance(__obj: object) -> 'TypeIs[Dataset]':
    """Return whether an object is a dataset instance.

    Args:
        __obj: Object to test.

    Returns:
        ``True`` if the object is recognized as a ``Dataset`` instance.
    """
    return lenient_isinstance(__obj, Dataset)

is_dataset_subclass cached

is_dataset_subclass(__cls: TypeForm) -> TypeIs[type[Dataset]]

Return whether a type form is a dataset subclass.

PARAMETER DESCRIPTION
__cls

Type or type-like form to test.

TYPE: TypeForm

RETURNS DESCRIPTION
TypeIs[type[Dataset]]

True if the argument is recognized as a Dataset subclass.

Source code in src/omnipy/data/dataset.py
@functools.cache
def is_dataset_subclass(__cls: TypeForm) -> 'TypeIs[type[Dataset]]':
    """Return whether a type form is a dataset subclass.

    Args:
        __cls: Type or type-like form to test.

    Returns:
        ``True`` if the argument is recognized as a ``Dataset`` subclass.
    """
    return lenient_issubclass(__cls, Dataset)