industrial-model 1.2.2__tar.gz → 1.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. {industrial_model-1.2.2 → industrial_model-1.2.4}/PKG-INFO +59 -26
  2. {industrial_model-1.2.2 → industrial_model-1.2.4}/README.md +58 -25
  3. {industrial_model-1.2.2 → industrial_model-1.2.4}/pyproject.toml +1 -1
  4. {industrial_model-1.2.2 → industrial_model-1.2.4}/.gitignore +0 -0
  5. {industrial_model-1.2.2 → industrial_model-1.2.4}/LICENSE +0 -0
  6. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/__init__.py +0 -0
  7. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/cognite_adapters/__init__.py +0 -0
  8. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/cognite_adapters/aggregation_mapper.py +0 -0
  9. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/cognite_adapters/filter_mapper.py +0 -0
  10. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/cognite_adapters/models.py +0 -0
  11. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/cognite_adapters/optimizer.py +0 -0
  12. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/cognite_adapters/query_mapper.py +0 -0
  13. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/cognite_adapters/query_result_mapper.py +0 -0
  14. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/cognite_adapters/search_mapper.py +0 -0
  15. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/cognite_adapters/sort_mapper.py +0 -0
  16. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/cognite_adapters/upsert_mapper.py +0 -0
  17. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/cognite_adapters/utils.py +0 -0
  18. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/cognite_adapters/view_mapper.py +0 -0
  19. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/config.py +0 -0
  20. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/constants.py +0 -0
  21. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/engines/__init__.py +0 -0
  22. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/engines/_internal.py +0 -0
  23. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/engines/async_engine.py +0 -0
  24. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/engines/engine.py +0 -0
  25. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/models/__init__.py +0 -0
  26. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/models/base.py +0 -0
  27. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/models/entities.py +0 -0
  28. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/models/schemas.py +0 -0
  29. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/models/utils.py +0 -0
  30. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/py.typed +0 -0
  31. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/queries/__init__.py +0 -0
  32. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/queries/models.py +0 -0
  33. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/queries/params.py +0 -0
  34. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/queries/utils.py +0 -0
  35. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/statements/__init__.py +0 -0
  36. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/statements/expressions.py +0 -0
  37. {industrial_model-1.2.2 → industrial_model-1.2.4}/industrial_model/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: industrial-model
3
- Version: 1.2.2
3
+ Version: 1.2.4
4
4
  Summary: Industrial Model ORM
5
5
  Project-URL: Homepage, https://github.com/lucasrosaalves/industrial-model
6
6
  Project-URL: Source, https://github.com/lucasrosaalves/industrial-model
@@ -24,22 +24,38 @@ Description-Content-Type: text/markdown
24
24
 
25
25
  # 📦 industrial-model
26
26
 
27
- `industrial-model` is a Python ORM-style abstraction for querying views in Cognite Data Fusion (CDF). It provides a declarative and type-safe way to model CDF views using `pydantic`, build queries, and interact with the CDF API in a Pythonic fashion.
27
+ **Type-safe, Pythonic access to Cognite Data Fusion views.**
28
+
29
+ `industrial-model` is a Python ORM for Cognite Data Fusion (CDF). Define views as Pydantic models, build queries with a fluent API, and work with CDF in the same way you write the rest of your Python—with types, autocomplete, and clear errors.
30
+
31
+ ```python
32
+ from industrial_model import Engine, ViewInstance, ViewInstanceConfig, select
33
+ from pathlib import Path
34
+
35
+ class Asset(ViewInstance):
36
+ view_config = ViewInstanceConfig(
37
+ view_external_id="CogniteAsset", # Map to the view externalId. If the class name is the same as the view external id, you do not need to configure this property.
38
+ instance_spaces_prefix="instance_data-", # Define the scope of your instance spaces to improve performance.
39
+ )
40
+ name: str
41
+ description: str | None = None
42
+
43
+ engine = Engine.from_config_file(Path("cognite-sdk-config.yaml"))
44
+ results = engine.query(select(Asset).limit(10))
45
+ # results.data → list[Asset], fully typed
46
+ ```
28
47
 
29
48
  ---
30
49
 
31
50
  ## ✨ Features
32
51
 
33
- - **Declarative Models**: Define CDF views using Pydantic-style classes with type hints
34
- - **Type-Safe Queries**: Build complex queries using fluent and composable filters
35
- - **Flexible Querying**: Support for standard queries, paginated queries, and full page retrieval
36
- - **Advanced Filtering**: Rich set of filter operators including nested queries, edge filtering, and boolean logic
37
- - **Search Capabilities**: Full-text fuzzy search with configurable operators
38
- - **Aggregations**: Count, sum, average, min, max with grouping support
39
- - **Write Operations**: Upsert and delete instances with edge relationship support
40
- - **Automatic Aliasing**: Built-in support for field aliases and camelCase transformation
41
- - **Async Support**: All operations have async equivalents
42
- - **Validation Modes**: Configurable error handling for data validation
52
+ - **Declarative models** Pydantic-style classes with type hints; only the fields you need
53
+ - **Type-safe queries** Fluent, composable filters with full IDE support
54
+ - **Query, search, aggregate** Standard and paginated queries, full-text search, count/sum/avg/min/max
55
+ - **Rich filtering** Nested queries, edge filters, boolean logic, list/string operators
56
+ - **Read and write** Upsert and delete with edge relationship support
57
+ - **Async** All operations have async equivalents
58
+ - **Configurable validation** Choose how to handle validation errors per request
43
59
 
44
60
  ---
45
61
 
@@ -53,22 +69,24 @@ pip install industrial-model
53
69
 
54
70
  ## 📚 Table of Contents
55
71
 
56
- 1. [Getting Started](#-getting-started)
57
- 2. [Model Definition](#-model-definition)
58
- 3. [Engine Setup](#-engine-setup)
59
- 4. [Querying Data](#-querying-data)
60
- 5. [Filtering](#-filtering)
61
- 6. [Search](#-search)
62
- 7. [Aggregations](#-aggregations)
63
- 8. [Write Operations](#-write-operations)
64
- 9. [Advanced Features](#-advanced-features)
65
- 10. [Async Operations](#-async-operations)
72
+ | Section | What you'll find |
73
+ |--------|-------------------|
74
+ | [Getting Started](#-getting-started) | Prerequisites and example schema |
75
+ | [Model Definition](#-model-definition) | Views as Pydantic models, aliases, config |
76
+ | [Engine Setup](#-engine-setup) | Config file or manual `Engine` / `AsyncEngine` |
77
+ | [Querying Data](#-querying-data) | `select()`, pagination, sorting, validation |
78
+ | [Filtering](#-filtering) | Comparison, list, string, nested, and edge filters |
79
+ | [Search](#-search) | Full-text search with filters |
80
+ | [Aggregations](#-aggregations) | Count, sum, avg, min, max, with grouping |
81
+ | [Write Operations](#-write-operations) | Upsert and delete |
82
+ | [Advanced Features](#-advanced-features) | ID generation, `InstanceId`, result helpers |
83
+ | [Async Operations](#-async-operations) | `AsyncEngine` and async API |
66
84
 
67
85
  ---
68
86
 
69
87
  ## 🚀 Getting Started
70
88
 
71
- This guide uses the `CogniteAsset` view from the `CogniteCore` data model (version `v1`) as an example.
89
+ The quick example above shows the core flow: **model → engine → query**. The rest of this guide uses the `CogniteAsset` view from the `CogniteCore` data model (version `v1`).
72
90
 
73
91
  ### Sample GraphQL Schema
74
92
 
@@ -87,6 +105,8 @@ type CogniteAsset {
87
105
 
88
106
  ## 🏗️ Model Definition
89
107
 
108
+ Models map CDF views to Python classes. Inherit from `ViewInstance` (or `WritableViewInstance` for writes) and declare only the properties you need.
109
+
90
110
  ### Basic Model
91
111
 
92
112
  Define your model by inheriting from `ViewInstance` and adding only the properties you need:
@@ -186,6 +206,8 @@ class CogniteAssetByName(AggregatedViewInstance):
186
206
 
187
207
  ## ⚙️ Engine Setup
188
208
 
209
+ The engine connects to CDF and knows which data model and version to use. You can load it from a config file or build it from an existing `CogniteClient`.
210
+
189
211
  ### Option A: From Configuration File
190
212
 
191
213
  Create a `cognite-sdk-config.yaml` file:
@@ -251,6 +273,8 @@ async_engine = AsyncEngine.from_config_file(Path("cognite-sdk-config.yaml"))
251
273
 
252
274
  ## 🔎 Querying Data
253
275
 
276
+ Use `select()` to build statements, then run them with `engine.query()` or `engine.query_all_pages()`. Results are typed and paginated.
277
+
254
278
  ### Basic Query
255
279
 
256
280
  ```python
@@ -322,6 +346,8 @@ results = engine.query(statement, validation_mode="ignoreOnError")
322
346
 
323
347
  ## 🔍 Filtering
324
348
 
349
+ Add `.where(...)` to narrow results. Use `col()` for operators like `in_()`, `prefix()`, and `nested_()`; use `==`, `!=`, `&`, and `|` where they apply.
350
+
325
351
  ### Comparison Operators
326
352
 
327
353
  ```python
@@ -535,6 +561,8 @@ statement = select(CogniteAsset).where(
535
561
 
536
562
  ## 🔍 Search
537
563
 
564
+ Full-text search over view instances. Combine `search()` with `.where()` filters and `.query_by()` to search specific properties.
565
+
538
566
  ### Search with Filters
539
567
 
540
568
  ```python
@@ -604,6 +632,8 @@ results = engine.search(search_statement)
604
632
 
605
633
  ## 📊 Aggregations
606
634
 
635
+ Use `AggregatedViewInstance` and `aggregate()` for count, sum, avg, min, and max—optionally with `.group_by()` and `.where()`.
636
+
607
637
  ### Count Aggregation
608
638
 
609
639
  ```python
@@ -722,6 +752,8 @@ results = engine.aggregate(statement)
722
752
 
723
753
  ## ✏️ Write Operations
724
754
 
755
+ Use `WritableViewInstance` and implement `edge_id_factory` for models with relationships. Then `engine.upsert()` and `engine.delete()` work on lists of instances.
756
+
725
757
  ### Upsert Instances
726
758
 
727
759
  ```python
@@ -804,6 +836,7 @@ engine.delete(instances_to_delete)
804
836
 
805
837
  ## 🚀 Advanced Features
806
838
 
839
+ Utilities for ID generation, `InstanceId` handling, and working with `PaginatedResult`.
807
840
 
808
841
  ### Generate Model IDs
809
842
 
@@ -884,7 +917,7 @@ if result.has_next_page:
884
917
 
885
918
  ## ⚡ Async Operations
886
919
 
887
- All engine methods have async equivalents:
920
+ Use `AsyncEngine` for async code. Every sync method has an `_async` counterpart (e.g. `query_async`, `upsert_async`).
888
921
 
889
922
  ### AsyncEngine Setup
890
923
 
@@ -955,7 +988,7 @@ asyncio.run(main())
955
988
 
956
989
  ## 📝 Complete Example
957
990
 
958
- Here's a complete example demonstrating multiple features:
991
+ Putting it together: query with filters, search, aggregate, upsert, and delete in one script.
959
992
 
960
993
  ```python
961
994
  from industrial_model import (
@@ -1058,7 +1091,7 @@ engine.delete(obsolete)
1058
1091
 
1059
1092
  ## 🎯 Best Practices
1060
1093
 
1061
- 1. **Model Definition**: Only include fields you actually need in your models
1094
+ 1. **Models** Declare only the fields you use; smaller models stay clearer and faster
1062
1095
  2. **View Configuration**: Use `instance_spaces` or `instance_spaces_prefix` to optimize queries
1063
1096
  3. **Pagination**: Use `query_all_pages()` for small datasets, `query()` with cursors for large datasets
1064
1097
  4. **Validation**: Use `ignoreOnError` mode when dealing with potentially inconsistent data
@@ -1,21 +1,37 @@
1
1
  # 📦 industrial-model
2
2
 
3
- `industrial-model` is a Python ORM-style abstraction for querying views in Cognite Data Fusion (CDF). It provides a declarative and type-safe way to model CDF views using `pydantic`, build queries, and interact with the CDF API in a Pythonic fashion.
3
+ **Type-safe, Pythonic access to Cognite Data Fusion views.**
4
+
5
+ `industrial-model` is a Python ORM for Cognite Data Fusion (CDF). Define views as Pydantic models, build queries with a fluent API, and work with CDF in the same way you write the rest of your Python—with types, autocomplete, and clear errors.
6
+
7
+ ```python
8
+ from industrial_model import Engine, ViewInstance, ViewInstanceConfig, select
9
+ from pathlib import Path
10
+
11
+ class Asset(ViewInstance):
12
+ view_config = ViewInstanceConfig(
13
+ view_external_id="CogniteAsset", # Map to the view externalId. If the class name is the same as the view external id, you do not need to configure this property.
14
+ instance_spaces_prefix="instance_data-", # Define the scope of your instance spaces to improve performance.
15
+ )
16
+ name: str
17
+ description: str | None = None
18
+
19
+ engine = Engine.from_config_file(Path("cognite-sdk-config.yaml"))
20
+ results = engine.query(select(Asset).limit(10))
21
+ # results.data → list[Asset], fully typed
22
+ ```
4
23
 
5
24
  ---
6
25
 
7
26
  ## ✨ Features
8
27
 
9
- - **Declarative Models**: Define CDF views using Pydantic-style classes with type hints
10
- - **Type-Safe Queries**: Build complex queries using fluent and composable filters
11
- - **Flexible Querying**: Support for standard queries, paginated queries, and full page retrieval
12
- - **Advanced Filtering**: Rich set of filter operators including nested queries, edge filtering, and boolean logic
13
- - **Search Capabilities**: Full-text fuzzy search with configurable operators
14
- - **Aggregations**: Count, sum, average, min, max with grouping support
15
- - **Write Operations**: Upsert and delete instances with edge relationship support
16
- - **Automatic Aliasing**: Built-in support for field aliases and camelCase transformation
17
- - **Async Support**: All operations have async equivalents
18
- - **Validation Modes**: Configurable error handling for data validation
28
+ - **Declarative models** Pydantic-style classes with type hints; only the fields you need
29
+ - **Type-safe queries** Fluent, composable filters with full IDE support
30
+ - **Query, search, aggregate** Standard and paginated queries, full-text search, count/sum/avg/min/max
31
+ - **Rich filtering** Nested queries, edge filters, boolean logic, list/string operators
32
+ - **Read and write** Upsert and delete with edge relationship support
33
+ - **Async** All operations have async equivalents
34
+ - **Configurable validation** Choose how to handle validation errors per request
19
35
 
20
36
  ---
21
37
 
@@ -29,22 +45,24 @@ pip install industrial-model
29
45
 
30
46
  ## 📚 Table of Contents
31
47
 
32
- 1. [Getting Started](#-getting-started)
33
- 2. [Model Definition](#-model-definition)
34
- 3. [Engine Setup](#-engine-setup)
35
- 4. [Querying Data](#-querying-data)
36
- 5. [Filtering](#-filtering)
37
- 6. [Search](#-search)
38
- 7. [Aggregations](#-aggregations)
39
- 8. [Write Operations](#-write-operations)
40
- 9. [Advanced Features](#-advanced-features)
41
- 10. [Async Operations](#-async-operations)
48
+ | Section | What you'll find |
49
+ |--------|-------------------|
50
+ | [Getting Started](#-getting-started) | Prerequisites and example schema |
51
+ | [Model Definition](#-model-definition) | Views as Pydantic models, aliases, config |
52
+ | [Engine Setup](#-engine-setup) | Config file or manual `Engine` / `AsyncEngine` |
53
+ | [Querying Data](#-querying-data) | `select()`, pagination, sorting, validation |
54
+ | [Filtering](#-filtering) | Comparison, list, string, nested, and edge filters |
55
+ | [Search](#-search) | Full-text search with filters |
56
+ | [Aggregations](#-aggregations) | Count, sum, avg, min, max, with grouping |
57
+ | [Write Operations](#-write-operations) | Upsert and delete |
58
+ | [Advanced Features](#-advanced-features) | ID generation, `InstanceId`, result helpers |
59
+ | [Async Operations](#-async-operations) | `AsyncEngine` and async API |
42
60
 
43
61
  ---
44
62
 
45
63
  ## 🚀 Getting Started
46
64
 
47
- This guide uses the `CogniteAsset` view from the `CogniteCore` data model (version `v1`) as an example.
65
+ The quick example above shows the core flow: **model → engine → query**. The rest of this guide uses the `CogniteAsset` view from the `CogniteCore` data model (version `v1`).
48
66
 
49
67
  ### Sample GraphQL Schema
50
68
 
@@ -63,6 +81,8 @@ type CogniteAsset {
63
81
 
64
82
  ## 🏗️ Model Definition
65
83
 
84
+ Models map CDF views to Python classes. Inherit from `ViewInstance` (or `WritableViewInstance` for writes) and declare only the properties you need.
85
+
66
86
  ### Basic Model
67
87
 
68
88
  Define your model by inheriting from `ViewInstance` and adding only the properties you need:
@@ -162,6 +182,8 @@ class CogniteAssetByName(AggregatedViewInstance):
162
182
 
163
183
  ## ⚙️ Engine Setup
164
184
 
185
+ The engine connects to CDF and knows which data model and version to use. You can load it from a config file or build it from an existing `CogniteClient`.
186
+
165
187
  ### Option A: From Configuration File
166
188
 
167
189
  Create a `cognite-sdk-config.yaml` file:
@@ -227,6 +249,8 @@ async_engine = AsyncEngine.from_config_file(Path("cognite-sdk-config.yaml"))
227
249
 
228
250
  ## 🔎 Querying Data
229
251
 
252
+ Use `select()` to build statements, then run them with `engine.query()` or `engine.query_all_pages()`. Results are typed and paginated.
253
+
230
254
  ### Basic Query
231
255
 
232
256
  ```python
@@ -298,6 +322,8 @@ results = engine.query(statement, validation_mode="ignoreOnError")
298
322
 
299
323
  ## 🔍 Filtering
300
324
 
325
+ Add `.where(...)` to narrow results. Use `col()` for operators like `in_()`, `prefix()`, and `nested_()`; use `==`, `!=`, `&`, and `|` where they apply.
326
+
301
327
  ### Comparison Operators
302
328
 
303
329
  ```python
@@ -511,6 +537,8 @@ statement = select(CogniteAsset).where(
511
537
 
512
538
  ## 🔍 Search
513
539
 
540
+ Full-text search over view instances. Combine `search()` with `.where()` filters and `.query_by()` to search specific properties.
541
+
514
542
  ### Search with Filters
515
543
 
516
544
  ```python
@@ -580,6 +608,8 @@ results = engine.search(search_statement)
580
608
 
581
609
  ## 📊 Aggregations
582
610
 
611
+ Use `AggregatedViewInstance` and `aggregate()` for count, sum, avg, min, and max—optionally with `.group_by()` and `.where()`.
612
+
583
613
  ### Count Aggregation
584
614
 
585
615
  ```python
@@ -698,6 +728,8 @@ results = engine.aggregate(statement)
698
728
 
699
729
  ## ✏️ Write Operations
700
730
 
731
+ Use `WritableViewInstance` and implement `edge_id_factory` for models with relationships. Then `engine.upsert()` and `engine.delete()` work on lists of instances.
732
+
701
733
  ### Upsert Instances
702
734
 
703
735
  ```python
@@ -780,6 +812,7 @@ engine.delete(instances_to_delete)
780
812
 
781
813
  ## 🚀 Advanced Features
782
814
 
815
+ Utilities for ID generation, `InstanceId` handling, and working with `PaginatedResult`.
783
816
 
784
817
  ### Generate Model IDs
785
818
 
@@ -860,7 +893,7 @@ if result.has_next_page:
860
893
 
861
894
  ## ⚡ Async Operations
862
895
 
863
- All engine methods have async equivalents:
896
+ Use `AsyncEngine` for async code. Every sync method has an `_async` counterpart (e.g. `query_async`, `upsert_async`).
864
897
 
865
898
  ### AsyncEngine Setup
866
899
 
@@ -931,7 +964,7 @@ asyncio.run(main())
931
964
 
932
965
  ## 📝 Complete Example
933
966
 
934
- Here's a complete example demonstrating multiple features:
967
+ Putting it together: query with filters, search, aggregate, upsert, and delete in one script.
935
968
 
936
969
  ```python
937
970
  from industrial_model import (
@@ -1034,7 +1067,7 @@ engine.delete(obsolete)
1034
1067
 
1035
1068
  ## 🎯 Best Practices
1036
1069
 
1037
- 1. **Model Definition**: Only include fields you actually need in your models
1070
+ 1. **Models** Declare only the fields you use; smaller models stay clearer and faster
1038
1071
  2. **View Configuration**: Use `instance_spaces` or `instance_spaces_prefix` to optimize queries
1039
1072
  3. **Pagination**: Use `query_all_pages()` for small datasets, `query()` with cursors for large datasets
1040
1073
  4. **Validation**: Use `ignoreOnError` mode when dealing with potentially inconsistent data
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "industrial-model"
3
- version = "1.2.2"
3
+ version = "1.2.4"
4
4
  description = "Industrial Model ORM"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"