industrial-model 0.1.1__py3-none-any.whl → 0.1.3__py3-none-any.whl

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.
@@ -22,7 +22,7 @@ def get_schema_properties(
22
22
  nested_separator: str = NESTED_SEP,
23
23
  prefix: str | None = None,
24
24
  ) -> list[str]:
25
- data = _get_type_properties(cls, defaultdict(lambda: 0)) or {}
25
+ data = _get_type_properties(cls) or {}
26
26
  keys = _flatten_dict_keys(data, None, nested_separator)
27
27
  if not prefix:
28
28
  return keys
@@ -31,14 +31,19 @@ def get_schema_properties(
31
31
 
32
32
 
33
33
  def _get_type_properties(
34
- cls: type[BaseModel], visited_count: defaultdict[type, int]
34
+ cls: type[BaseModel], visited_count: defaultdict[type, int] | None = None
35
35
  ) -> dict[str, Any] | None:
36
- if visited_count[cls] > 3:
37
- return None
36
+ if visited_count is not None:
37
+ if visited_count[cls] > 2:
38
+ return None
39
+ visited_count[cls] += 1
38
40
 
39
41
  hints = get_type_hints(cls)
40
42
  origins = {
41
- key: _get_field_type(type_hint, visited_count)
43
+ key: _get_field_type(
44
+ type_hint,
45
+ visited_count or defaultdict(lambda: 0),
46
+ )
42
47
  for key, type_hint in hints.items()
43
48
  }
44
49
 
@@ -59,7 +64,6 @@ def _get_field_type(
59
64
  [_cast_base_model(type_hint)], visited_count
60
65
  )
61
66
 
62
- visited_count[type_hint] += visited_count[type_hint] + 1
63
67
  entries: list[type[BaseModel] | None] = []
64
68
  for arg in get_args(type_hint):
65
69
  if _type_is_list_or_union(arg):
@@ -118,4 +122,4 @@ def _flatten_dict_keys(
118
122
  [f"{full_key}{nested_separator}{item}" for item in value]
119
123
  )
120
124
 
121
- return list(paths)
125
+ return sorted(paths)
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.4
2
+ Name: industrial-model
3
+ Version: 0.1.3
4
+ Summary: Industrial Model ORM
5
+ Author-email: Lucas Alves <lucasrosaalves@gmail.com>
6
+ Classifier: Programming Language :: Python
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3 :: Only
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Topic :: Database
13
+ Classifier: Topic :: Database :: Database Engines/Servers
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.11
16
+ Requires-Dist: anyio>=4.9.0
17
+ Requires-Dist: cognite-sdk>=7.75.0
18
+ Requires-Dist: pydantic>=2.11.4
19
+ Description-Content-Type: text/markdown
20
+
21
+ # 📦 industrial-model
22
+
23
+ `industrial-model` is a Python ORM-style abstraction for querying views and data models 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.
24
+
25
+ ---
26
+
27
+ ## ✨ Features
28
+
29
+ - Define CDF views using Pydantic-style classes.
30
+ - Build complex queries using fluent and composable filters.
31
+ - Easily fetch data using standard or paginated query execution.
32
+ - Automatic alias and field transformation support.
33
+ - Extensible and test-friendly design.
34
+
35
+ ---
36
+
37
+ ## 📦 Installation
38
+
39
+ ```bash
40
+ pip install industrial-model
41
+ ```
42
+
43
+ ---
44
+
45
+ ## 🛠️ Usage Example
46
+
47
+ ```python
48
+ import datetime
49
+ from cognite.client import CogniteClient
50
+ from pydantic import Field
51
+
52
+ from industrial_model import (
53
+ AsyncEngine,
54
+ DataModelId,
55
+ Engine,
56
+ ViewInstance,
57
+ select,
58
+ col,
59
+ and_,
60
+ or_,
61
+ )
62
+
63
+ # Define entities (view instances)
64
+
65
+
66
+ class Car(ViewInstance):
67
+ name: str
68
+
69
+
70
+ class Region(ViewInstance):
71
+ name: str
72
+
73
+
74
+ class Country(ViewInstance):
75
+ name: str
76
+ region: Region = Field(
77
+ alias="regionRef"
78
+ ) # Maps property to field if names differ
79
+
80
+
81
+ class Person(ViewInstance):
82
+ name: str
83
+ birthday: datetime.date
84
+ livesIn: Country
85
+ cars: list[Car]
86
+
87
+
88
+ # Initialize Cognite client and data model engine
89
+
90
+ cognite_client = CogniteClient()
91
+
92
+ data_model_id = DataModelId(
93
+ external_id="IndustrialData",
94
+ space="IndustralSpaceType",
95
+ version="v1"
96
+ )
97
+
98
+ engine = Engine(cognite_client, data_model_id)
99
+ async_engine = AsyncEngine(cognite_client, data_model_id) # Optional async engine
100
+
101
+
102
+ # -----------------------------------
103
+ # Example Queries
104
+ # -----------------------------------
105
+
106
+ # 1. Basic query: Find person named "Lucas"
107
+ statement = select(Person).where(Person.name == "Lucas").limit(1)
108
+ result = engine.query(statement)
109
+
110
+
111
+ # 2. Combined filter with AND/OR
112
+ statement = select(Person).where(
113
+ (Person.name == "Lucas") & (Person.birthday > datetime.date(2023, 1, 2)) |
114
+ (Person.name == "Another")
115
+ )
116
+ result = engine.query(statement)
117
+
118
+
119
+ # 3. Same logic using `col()` expressions
120
+ statement = select(Person).where(
121
+ (col("name").equals_("Lucas")) &
122
+ (col(Person.birthday).gt_("2023-01-02")) |
123
+ (Person.name == "Another")
124
+ )
125
+ result = engine.query(statement)
126
+
127
+
128
+ # 4. Nested filtering using relationships
129
+ statement = select(Person).where(
130
+ or_(
131
+ col(Person.livesIn).nested_(Country.name == "usa"),
132
+ and_(
133
+ col(Person.livesIn).nested_(col(Country.name).equals_("bra")),
134
+ col(Person.birthday).equals_("2023-01-01")
135
+ )
136
+ )
137
+ )
138
+ result = engine.query(statement)
139
+
140
+
141
+ # 5. Paginated query with sorting and cursor
142
+ statement = (
143
+ select(Person)
144
+ .where(
145
+ (Person.name == "Lucas") &
146
+ (Person.birthday > datetime.date(2023, 1, 2)) |
147
+ (Person.name == "Another")
148
+ )
149
+ .limit(10)
150
+ .cursor("NEXT CURSOR")
151
+ .asc(Person.name)
152
+ )
153
+ result = engine.query(statement)
154
+
155
+
156
+ # 6. Fetch all pages of a query
157
+ statement = select(Person).where(
158
+ (Person.name == "Lucas") &
159
+ (Person.birthday > datetime.date(2023, 1, 2)) |
160
+ (Person.name == "Another")
161
+ )
162
+ all_results = engine.query_all_pages(statement)
163
+
164
+ ```
165
+
166
+ ---
@@ -8,7 +8,7 @@ industrial_model/cognite_adapters/filter_mapper.py,sha256=NqH-OW7_iKFY9POCG8W3Kj
8
8
  industrial_model/cognite_adapters/optimizer.py,sha256=msOXAU2nY2-7U0-AlST3_SWuLHnyQ9wNa5_BzMRQfdw,2166
9
9
  industrial_model/cognite_adapters/query_mapper.py,sha256=lYKRiIEmFiX7CQUnrOh5_-t1UkAMcT3dr9ORgErDXOY,6233
10
10
  industrial_model/cognite_adapters/query_result_mapper.py,sha256=jUreXqsaLnq7hp6T_JZQNRtL8TL8hoLSFvD4SkJ4TEE,7002
11
- industrial_model/cognite_adapters/schemas.py,sha256=Td9pcIj1vr9hrmI9noFKBxK6SNS9EAwol6tosz9HEdg,3364
11
+ industrial_model/cognite_adapters/schemas.py,sha256=EiRe0HK6thCzk0WYOPrAIRe8GkkG7_ykQsy7WVfT_Og,3430
12
12
  industrial_model/cognite_adapters/sort_mapper.py,sha256=RJUAYlZGXoYzK0PwX63cibRF_L-MUq9g2ZsC2EeNIF4,696
13
13
  industrial_model/cognite_adapters/utils.py,sha256=nBYHK8697L2yGEAcyKjQV9NEZQmWy_aSGq_iMl7gofM,907
14
14
  industrial_model/cognite_adapters/view_mapper.py,sha256=lnv64KezSQTAr6XdcExa8d92GU5Ll9K9HfMcQGzhX6k,488
@@ -23,6 +23,6 @@ industrial_model/queries/models.py,sha256=iiHQ7-cfg0nukEv5PoCx9QPF-w1gVSnoNbXBOK
23
23
  industrial_model/queries/params.py,sha256=ehgCoR5n6E-tkEuoymZ2lkLcSzMaBAx_HnyJ7sWpqz0,964
24
24
  industrial_model/statements/__init__.py,sha256=mqPIvfQ-XZ_IILwha7RbkdIKH_MRAdAvfrw80pCKU1c,1753
25
25
  industrial_model/statements/expressions.py,sha256=bsUnkFDGVHpOQ1RUtEbSPE1nfVkF0zC3m5-9JFkSqu8,4751
26
- industrial_model-0.1.1.dist-info/METADATA,sha256=0Ba1Ye2htMw494FFTBpUVg-vDhUmUVLDCI28jVB97LU,763
27
- industrial_model-0.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
28
- industrial_model-0.1.1.dist-info/RECORD,,
26
+ industrial_model-0.1.3.dist-info/METADATA,sha256=3DmP5yMReiv2zFlknqgEo6hCLMoIwQDNGX0e_wqN0KE,3935
27
+ industrial_model-0.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
28
+ industrial_model-0.1.3.dist-info/RECORD,,
@@ -1,23 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: industrial-model
3
- Version: 0.1.1
4
- Summary: Industrial Model ORM
5
- Author-email: Lucas Alves <lucasrosaalves@gmail.com>
6
- Classifier: Programming Language :: Python
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: Programming Language :: Python :: 3 :: Only
9
- Classifier: Programming Language :: Python :: 3.11
10
- Classifier: Programming Language :: Python :: 3.12
11
- Classifier: Programming Language :: Python :: 3.13
12
- Classifier: Topic :: Database
13
- Classifier: Topic :: Database :: Database Engines/Servers
14
- Classifier: Typing :: Typed
15
- Requires-Python: >=3.11
16
- Requires-Dist: anyio>=4.9.0
17
- Requires-Dist: cognite-sdk>=7.75.0
18
- Requires-Dist: pydantic>=2.11.4
19
- Description-Content-Type: text/markdown
20
-
21
- # capybara
22
-
23
- ![My Image](./assets/logo.jpeg)