Generators
cognite.pygen._core.generators
This module contains the SDK generator classes.
These are responsible for: 1. Generating the internal representation from the input views. 2. Use the internal representation with the Jinja templates to generate the SDK.
APIGenerator
This class is responsible for generating the API and Data Classes for a single view.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
view
|
View
|
The view to generate the API and Data Classes for. |
required |
has_default_instance_space
|
bool
|
Whether the generated SDK has a default instance space. |
required |
config
|
PygenConfig
|
The configuration for the SDK generation |
required |
base_name
|
str | None
|
The base name of the view. If None, the base name will be inferred from the view. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
view |
The view to generate the API and Data Classes for. |
|
data_class |
The data class for the view. |
|
api_class |
The API class for the view. |
|
query_api |
QueryAPIClass
|
The query API class for the view. |
Source code in cognite/pygen/_core/generators.py
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 |
|
edge_apis: list[EdgeAPIClass]
property
The edge APIs for the view.
has_edge_api_dependencies: bool
property
Whether the view has edge API dependencies.
list_method: FilterMethod
property
The list method for the view.
timeseries_apis: list[TimeSeriesAPIClass]
property
The timeseries APIs for the view.
view_id: dm.ViewId
property
The view ID of the view.
create_edge_apis(query_api_by_view_id, api_generator_by_view_id)
Create the edge APIs for the view.
Source code in cognite/pygen/_core/generators.py
generate_api_file(client_name)
Generate the API file for the view.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_name
|
str
|
The name of the client class. |
required |
Returns:
Type | Description |
---|---|
str
|
The generated API file as a string. |
Source code in cognite/pygen/_core/generators.py
generate_api_query_file(client_name)
Generate the API query file for the view.
This is the basis for the Python query functionality for the view.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_name
|
str
|
The name of the client class. |
required |
Returns:
Type | Description |
---|---|
str
|
The generated API query file as a string. |
Source code in cognite/pygen/_core/generators.py
generate_data_class_file()
Generate the data class file for the view.
Returns:
Type | Description |
---|---|
str
|
The generated data class file as a string. |
Source code in cognite/pygen/_core/generators.py
generate_edge_api_files(client_name)
Generate the edge API files for the view.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_name
|
str
|
The name of the client class. |
required |
Returns:
Type | Description |
---|---|
Iterator[tuple[str, str]]
|
Iterator of tuples of file names and file contents for the edge APIs. |
Source code in cognite/pygen/_core/generators.py
generate_timeseries_api_files(client_name)
Generate the timeseries API files for the view.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_name
|
str
|
The name of the client class. |
required |
Returns:
Type | Description |
---|---|
Iterator[tuple[str, str]]
|
Iterator of tuples of file names and file contents for the timeseries APIs. |
Source code in cognite/pygen/_core/generators.py
MultiAPIGenerator
This class is responsible for generating the API and Data Classes for multiple views.
Source code in cognite/pygen/_core/generators.py
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 |
|
apis: Iterator[APIGenerator]
property
Iterate over the unique APIs.
data_classes_topological_order: list[DataClass]
property
Return the topological order of the data classes.
has_default_instance_space: bool
property
Whether the SDK has a default instance space.
create_api_by_view_id_type(views, has_default_instance_space, top_level_package, config, base_name_functions, selected_function=0)
classmethod
Create the API by view ID for the given views.
Source code in cognite/pygen/_core/generators.py
generate_api_core_file()
Generate the core API file for the SDK.
Source code in cognite/pygen/_core/generators.py
generate_api_init_file()
Generate the core API file for the SDK.
Source code in cognite/pygen/_core/generators.py
generate_apis(client_dir)
Generate the APIs for the SDK.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_dir
|
Path
|
The directory to generate the SDK in. |
required |
Returns:
Type | Description |
---|---|
dict[Path, str]
|
A dictionary of file paths and file contents for the generated SDK. |
Source code in cognite/pygen/_core/generators.py
generate_client_init_file()
Generate the init.py file for the client.
Returns:
Type | Description |
---|---|
str
|
The generated init.py file as a string. |
Source code in cognite/pygen/_core/generators.py
generate_data_class_core_base_file()
Generate the core/base.py data classes file for the SDK.
Source code in cognite/pygen/_core/generators.py
generate_data_class_core_cdf_external_file()
Generate the core data classes file for the SDK.
Source code in cognite/pygen/_core/generators.py
generate_data_class_core_constants_file()
Generate the core/constants data classes file for the SDK.
Source code in cognite/pygen/_core/generators.py
generate_data_class_core_datapoints_api_file()
Generate the core data classes file for the SDK.
Source code in cognite/pygen/_core/generators.py
generate_data_class_core_filecontent_api_file()
Generate the core data classes file for the SDK.
Source code in cognite/pygen/_core/generators.py
generate_data_class_core_helpers_file()
Generate the core/helpers data classes file for the SDK.
Source code in cognite/pygen/_core/generators.py
generate_data_class_core_init_file()
Generate the core/init data classes file for the SDK.
Source code in cognite/pygen/_core/generators.py
generate_data_class_core_query_file()
Generate the core data classes file for the SDK.
Source code in cognite/pygen/_core/generators.py
generate_data_classes_init_file()
Generate the init.py file for the data classes.
Returns:
Type | Description |
---|---|
str
|
The generated init.py file as a string. |
Source code in cognite/pygen/_core/generators.py
generate_typed_classes_file(include=None, module_by_space=None, readonly_properties_by_view=None)
Generate the typed classes file for the SDK.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include
|
set[ViewId] | None
|
The set of view IDs to include in the generated typed classes file. If None, all views will be included. |
None
|
module_by_space
|
dict[str, str] | None
|
A dictionary mapping space names to module names. This is used if part of the data model has been generated before and you want to reuse the generated classes. The keys are the space names and the values are the module names. For example, {"cdf_cdm": "cognite.client.data_classes.cdm.v1"}, this will import all classes generated from views in the 'cdf_cdm' space from the 'cognite.client.data_classes.cdm.v1' module. |
None
|
readonly_properties_by_view
|
dict[ViewId, set[str]] | None
|
A dictionary mapping view IDs to a set of readonly properties for that view. |
None
|
Returns:
Type | Description |
---|---|
str
|
The generated typed classes file as a string. |
Source code in cognite/pygen/_core/generators.py
SDKGenerator
SDK generator for one or more data models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
top_level_package
|
str
|
The name of the top level package for the SDK. Example "movie.client" |
required |
client_name
|
str
|
The name of the client class. Example "MovieClient" |
required |
data_model
|
DataModel | Sequence[DataModel]
|
The data model(s) used to generate an SDK. |
required |
default_instance_space
|
str | None
|
The default instance space to use for the SDK. If None, the first space in the data model will be used. |
None
|
implements
|
Literal['inheritance', 'composition']
|
Whether to use inheritance or composition for views that are implementing other views. |
'inheritance'
|
logger
|
Callable[[str], None] | None
|
A logger function to use for logging. If None, print will be done. |
None
|
Source code in cognite/pygen/_core/generators.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
has_default_instance_space: bool
property
Whether the SDK has a default instance space.
generate_sdk()
Generate the SDK.
Returns:
Type | Description |
---|---|
dict[Path, str]
|
A Python SDK given as a dictionary of file paths and file contents, which can be written to disk. |
Source code in cognite/pygen/_core/generators.py
to_direct_children_by_view_id(views)
Given a list of views, return a dictionary of direct children for each view.
Source code in cognite/pygen/_core/generators.py
to_unique_parents_by_view_id(views)
Given a list of views, return a dictionary of unique parents for each view.
Note that this is necessary due to the following situation (-> denotes implements): A -> B and C B -> C Then, A implements B and C, while B also implements C. This means that the unique parents for A is [B and C] and for B is [C].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
views
|
Sequence[View]
|
|
required |
Returns: