pycarlo 0.11.15__py3-none-any.whl → 0.12.5__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.
pycarlo/lib/types.py ADDED
@@ -0,0 +1,68 @@
1
+ """
2
+ Custom GraphQL types for the Monte Carlo Python Schema Library.
3
+
4
+ This module provides custom implementations of/replacements for sgqlc types that are used
5
+ in the auto-generated schema.
6
+ """
7
+
8
+ import logging
9
+ from typing import Any, Optional, Union
10
+
11
+ import sgqlc.types
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class Enum(sgqlc.types.Enum):
17
+ """
18
+ A backward-compatible GraphQL enum type that gracefully handles unknown values.
19
+
20
+ Problem:
21
+ When new enum values are added to the Monte Carlo GraphQL API, older SDK versions
22
+ that don't have these values in their generated schema will crash with a ValueError
23
+ when trying to deserialize API responses containing the new values.
24
+
25
+ Solution:
26
+ This custom Enum class returns unknown enum values as plain strings instead of
27
+ raising an error. Since sgqlc enums are already represented as strings internally,
28
+ this maintains full compatibility with existing code while preventing crashes.
29
+
30
+ Behavior:
31
+ - Known enum values: Returned as strings (same as sgqlc.types.Enum)
32
+ - Unknown enum values: Returned as strings with a warning logged
33
+ - All comparisons, collections, and operations work identically
34
+
35
+ Example:
36
+ # Previous Values for EntitlementTypes = ['SSO', 'MULTI_WORKSPACE']
37
+ # API is updated to return new value: ['SSO', 'NEW_FEATURE', 'MULTI_WORKSPACE']
38
+
39
+ # With standard sgqlc.types.Enum:
40
+ # ValueError: EntitlementTypes does not accept value NEW_FEATURE
41
+
42
+ # With this Enum:
43
+ # Will return the new value as str and log a warning, no exception raised
44
+
45
+ # Code still works:
46
+ if 'SSO' in entitlements: # Works
47
+ enable_sso()
48
+ if 'NEW_FEATURE' in entitlements: # Also works
49
+ enable_new_feature()
50
+ """
51
+
52
+ def __new__(
53
+ cls, json_data: Any, _: Optional[Any] = None
54
+ ) -> Union[str, sgqlc.types.Variable, None]:
55
+ try:
56
+ return sgqlc.types.get_variable_or_none(json_data)
57
+ except ValueError:
58
+ pass
59
+
60
+ if json_data not in cls:
61
+ # Log warning but don't crash - return the unknown value as a string
62
+ logger.warning(
63
+ f"Unknown enum value '{json_data}' for {cls.__name__}. "
64
+ f"This may indicate the SDK is out of date. Returning raw string value."
65
+ )
66
+ return str(json_data)
67
+
68
+ return str(json_data)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycarlo
3
- Version: 0.11.15
3
+ Version: 0.12.5
4
4
  Summary: Monte Carlo's Python SDK
5
5
  Home-page: https://www.montecarlodata.com/
6
6
  Author: Monte Carlo Data, Inc
@@ -19,15 +19,13 @@ Classifier: Programming Language :: Python :: 3.12
19
19
  Requires-Python: >=3.8
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
- Requires-Dist: dataclasses-json <6.0.0,>=0.5.7
23
- Requires-Dist: python-box >=5.0.0
24
- Requires-Dist: requests <3.0.0,>=2.0.0
25
- Requires-Dist: responses >=0.20.0
26
- Requires-Dist: sgqlc <17.0,>=14.1
22
+ Requires-Dist: dataclasses-json<6.0.0,>=0.5.7
23
+ Requires-Dist: python-box>=5.0.0
24
+ Requires-Dist: requests<3.0.0,>=2.0.0
25
+ Requires-Dist: responses>=0.20.0
26
+ Requires-Dist: sgqlc<17.0,>=14.1
27
27
 
28
- # Pycarlo
29
-
30
- Monte Carlo's Alpha Python SDK!
28
+ # Pycarlo - Monte Carlo's Python SDK
31
29
 
32
30
  ## Installation
33
31
 
@@ -40,23 +38,22 @@ virtualenv venv
40
38
  pip install -U pycarlo
41
39
  ```
42
40
 
43
- Developers of the SDK can use:
44
-
45
- ```shell
46
- make install-with-tests
47
- . venv/bin/activate
48
- pre-commit install
49
- ```
50
-
51
41
  ## Overview
52
42
 
53
43
  Pycarlo comprises two components: `core` and `features`.
54
44
 
55
- All Monte Carlo API queries and mutations that you could execute via the API are supported via the `core` library. Operations can be executed as first class objects, using [sgqlc](https://github.com/profusion/sgqlc), or as raw GQL with variables. In both cases, a consistent object where fields can be referenced by dot notation and the more pythonic snake_case is returned for ease of use.
45
+ All Monte Carlo API queries and mutations that you could execute via the API are supported via the
46
+ `core` library. Operations can be executed as first class objects, using
47
+ [sgqlc](https://github.com/profusion/sgqlc), or as raw GQL with variables. In both cases, a
48
+ consistent object where fields can be referenced by dot notation and the more pythonic snake_case is
49
+ returned for ease of use.
56
50
 
57
- The `features` library provides additional convenience for performing common operations like with dbt, circuit breaking, and pii filtering.
51
+ The `features` library provides additional convenience for performing common operations like with
52
+ dbt, circuit breaking, and pii filtering.
58
53
 
59
- Note that an API Key is required to use the SDK. See [here](https://docs.getmontecarlo.com/docs/developer-resources#creating-an-api-key) for details on how to generate one.
54
+ Note that an API Key is required to use the SDK. See
55
+ [our docs on generating API keys](https://docs.getmontecarlo.com/docs/developer-resources#creating-an-api-key)
56
+ for details.
60
57
 
61
58
  ## Basic usage
62
59
 
@@ -144,13 +141,20 @@ print(client(mutation))
144
141
  # ]
145
142
  ```
146
143
 
147
- Note that you can find Monte Carlo's API reference [here](https://apidocs.getmontecarlo.com/).
144
+ ### Examples
145
+
146
+ We have [a few examples here you can reference](./examples).
148
147
 
149
- For details and additional examples on how to map (convert) GraphQL queries to `sgqlc` operations please refer to the docs [here](https://sgqlc.readthedocs.io/en/latest/sgqlc.operation.html).
148
+ See [Monte Carlo's API reference](https://apidocs.getmontecarlo.com/) for all supported queries and
149
+ mutations.
150
+
151
+ For details and additional examples on how to map (convert) GraphQL queries to `sgqlc` operations
152
+ please refer to [the sgqlc docs](https://sgqlc.readthedocs.io/en/latest/sgqlc.operation.html).
150
153
 
151
154
  ### Features
152
155
 
153
- You can use [pydoc](https://docs.python.org/3.8/library/pydoc.html) to retrieve documentation on any feature packages (`pydoc pycarlo.features`).
156
+ You can use [pydoc](https://docs.python.org/library/pydoc.html) to retrieve documentation on any
157
+ feature packages (`pydoc pycarlo.features`).
154
158
 
155
159
  For instance for [circuit breakers](https://docs.getmontecarlo.com/docs/circuit-breakers):
156
160
 
@@ -160,9 +164,13 @@ pydoc pycarlo.features.circuit_breakers.service
160
164
 
161
165
  ## Session configuration
162
166
 
163
- By default, when creating a client the `default` profile from `~/.mcd/profiles.ini` is used. This file created via [montecarlo configure](https://docs.getmontecarlo.com/docs/using-the-cli#setting-up-the-cli) on the CLI. Note that you can find Monte Carlo's CLI reference [here](https://clidocs.getmontecarlo.com/).
167
+ By default, when creating a client the `default` profile from `~/.mcd/profiles.ini` is used. This
168
+ file created via
169
+ [montecarlo configure](https://docs.getmontecarlo.com/docs/using-the-cli#setting-up-the-cli) on the
170
+ CLI. See [Monte Carlo's CLI reference](https://clidocs.getmontecarlo.com/) for more details.
164
171
 
165
- You can override this usage by creating a custom `Session`. For instance, if you want to pass the ID and Token:
172
+ You can override this usage by creating a custom `Session`. For instance, if you want to pass the ID
173
+ and Token:
166
174
 
167
175
  ```python
168
176
  from pycarlo.core import Client, Session
@@ -174,7 +182,8 @@ Sessions support the following params:
174
182
 
175
183
  - `mcd_id`: API Key ID.
176
184
  - `mcd_token`: API secret.
177
- - `mcd_profile`: Named profile containing credentials. This is created via the CLI (e.g. `montecarlo configure --profile-name zeus`).
185
+ - `mcd_profile`: Named profile containing credentials. This is created via the CLI (e.g.
186
+ `montecarlo configure --profile-name zeus`).
178
187
  - `mcd_config_path`: Path to file containing credentials. Defaults to `~/.mcd/`.
179
188
 
180
189
  You can also specify the API Key, secret or profile name using the following environment variables:
@@ -183,7 +192,8 @@ You can also specify the API Key, secret or profile name using the following env
183
192
  - `MCD_DEFAULT_API_TOKEN`
184
193
  - `MCD_DEFAULT_PROFILE`
185
194
 
186
- When creating a session any explicitly passed `mcd_id` and `mcd_token` params take precedence, followed by environmental variables and then any config-file options.
195
+ When creating a session any explicitly passed `mcd_id` and `mcd_token` params take precedence,
196
+ followed by environmental variables and then any config-file options.
187
197
 
188
198
  Environment variables can be mixed with passed credentials, but not the config-file profile.
189
199
 
@@ -191,9 +201,11 @@ Environment variables can be mixed with passed credentials, but not the config-f
191
201
 
192
202
  ## Integration Gateway API
193
203
 
194
- There are features that require the Integration Gateway API instead of the regular GraphQL Application API, for example Airflow Callbacks invoked by the `airflow-mcd` library.
204
+ There are features that require the Integration Gateway API instead of the regular GraphQL
205
+ Application API, for example Airflow Callbacks invoked by the `airflow-mcd` library.
195
206
 
196
- To use the Gateway you need to initialize the `Session` object passing a `scope` parameter and then use `make_request` to invoke Gateway endpoints:
207
+ To use the Gateway you need to initialize the `Session` object passing a `scope` parameter and then
208
+ use `make_request` to invoke Gateway endpoints:
197
209
 
198
210
  ```python
199
211
  from pycarlo.core import Client, Session
@@ -211,17 +223,22 @@ The following values also be set by the environment:
211
223
  - `MCD_VERBOSE_ERRORS`: Enable logging. This includes a trace ID for each session and request.
212
224
  - `MCD_API_ENDPOINT`: Customize the endpoint where queries and mutations are executed.
213
225
 
214
- ## Tests and releases
226
+ ## Enum Backward Compatibility
227
+
228
+ Unlike the baseline `sgqlc` behavior, this SDK is designed to maintain backward compatibility when
229
+ new enum values are added to the Monte Carlo API. If the API returns an enum value that doesn't
230
+ exist in your SDK version, it will be returned as a string with a warning logged, rather than
231
+ raising an error. This allows older SDK versions to continue working when new features are added.
215
232
 
216
- To update queries and mutations via introspection, use `make generate`.
233
+ To avoid warnings and ensure full feature support, keep your SDK updated to the latest version.
217
234
 
218
- `make test` can be used to run all tests locally. CircleCI manages all testing for deployment. When ready for a review, create a PR against `main`.
235
+ ## Contributing
219
236
 
220
- When ready to release, create a new [Github release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) with a tag using semantic versioning (e.g. `v0.42.0`) and CircleCI will test and publish to PyPI. Note that an existing version will not be deployed.
237
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for details.
221
238
 
222
239
  ## References
223
240
 
224
- - Dashboard: <https://getmontecarlo.com>
241
+ - Monte Carlo App: <https://getmontecarlo.com>
225
242
  - Product docs: <https://docs.getmontecarlo.com>
226
243
  - Status page: <https://status.getmontecarlo.com>
227
244
  - API (and SDK): <https://apidocs.getmontecarlo.com>
@@ -229,4 +246,4 @@ When ready to release, create a new [Github release](https://docs.github.com/en/
229
246
 
230
247
  ## License
231
248
 
232
- Apache 2.0 - See the [LICENSE](http://www.apache.org/licenses/LICENSE-2.0) for more information.
249
+ Apache 2.0 - See the [LICENSE](./LICENSE) for more information.
@@ -25,7 +25,7 @@ pycarlo/features/metadata/asset_allow_block_list.py,sha256=jXCS7HtUJhexEXZyRzyN4
25
25
  pycarlo/features/metadata/asset_filters_container.py,sha256=O15SC6u7HMGlViYnX7H8MRFttQrIXQd3a0oOrz7My5U,3411
26
26
  pycarlo/features/metadata/base_allow_block_list.py,sha256=c8zd0BXkNSfQ3LkNC_A0KrO2AsYtIowc8FjbdyDyDu0,4738
27
27
  pycarlo/features/metadata/metadata_allow_block_list.py,sha256=HzgXE0WhwDZoBHeV04e8dwe88rUSVVnOl8nFEPlb0jA,3496
28
- pycarlo/features/metadata/metadata_filters_container.py,sha256=GCbk-t7Njq2IiQrre186aN3DT2ytN-8RTwBPnBmfgJA,12715
28
+ pycarlo/features/metadata/metadata_filters_container.py,sha256=p7FNg71KYZZrvgJmlx9rID2TAL_e9LKzNQZ9KKN5uGs,12812
29
29
  pycarlo/features/pii/__init__.py,sha256=w5X-oD8HWaL6fP2jt40AhlXO-MNzlVAlhRaZ5kQqAZY,247
30
30
  pycarlo/features/pii/constants.py,sha256=XWeiikXk9AtljdWsGfl49b9zI6w8EzK8F__Euc0vQ3w,70
31
31
  pycarlo/features/pii/pii_filterer.py,sha256=k53b_V_mddY4A17-DJ5vQKszFDlUaiP3E650JFHAeJA,6209
@@ -36,12 +36,13 @@ pycarlo/features/user/exceptions.py,sha256=Za5mPMynNDW_UQkfMbCSGjP1ht-xSUkwoI6hV
36
36
  pycarlo/features/user/models.py,sha256=fhvS7tBhTtx7p9624yN5tzebXs5ERrl1XQ9B_DYor0E,126
37
37
  pycarlo/features/user/queries.py,sha256=m97RvM0oiBlrU5xmOwe_JJ5N0G0NG5hIOeyQqN2O8_4,170
38
38
  pycarlo/features/user/service.py,sha256=DHkhuonySaHro07NTd0YNe3cNkDk62CiRTY77dhVaMs,2890
39
- pycarlo/lib/README.md,sha256=QGNeUefPzLKGyZqn5aITpcFgkC9WQTNS292BGisRFHk,139
39
+ pycarlo/lib/README.md,sha256=CVVrPPgje7pkXNNsPvwLSeUOm5aktb22MlttmoxX08k,1677
40
40
  pycarlo/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
- pycarlo/lib/schema.json,sha256=QPrl1YZ0WF2HNxk4EJG3PuypjUEu6z9cT-zby0oXlqY,6521200
42
- pycarlo/lib/schema.py,sha256=6MMMErpEG-oFTgOfGBoZmQw5tgo4li7XFKXA-JqGY3k,2832020
43
- pycarlo-0.11.15.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
44
- pycarlo-0.11.15.dist-info/METADATA,sha256=IiKzQSFemktwSfQa1MtnM2A2AeKeBxnbC_y4XwQaWx0,8741
45
- pycarlo-0.11.15.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
46
- pycarlo-0.11.15.dist-info/top_level.txt,sha256=TIE04H4pgzGaFxAB-gvkmVAUOAoHxxFfhnEcpuQ5bF4,8
47
- pycarlo-0.11.15.dist-info/RECORD,,
41
+ pycarlo/lib/schema.json,sha256=AjbIWUdzPwAxpeqmZ8DoA-FSUPcxaAiPsM-J7ePlWN4,6593668
42
+ pycarlo/lib/schema.py,sha256=uhhOjB4kbru-7tZT_O_TUW8jzSCBiCtGkxTyQNbt7Hg,2866352
43
+ pycarlo/lib/types.py,sha256=lGOrm5Qm-SieDAkOkVOFSgyUJYGOjKnea961AD9Dv6s,2404
44
+ pycarlo-0.12.5.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
45
+ pycarlo-0.12.5.dist-info/METADATA,sha256=_jGoE6lB9pSjezfhXdXtXk-QWfv5Yh1_ucmBiega48g,8717
46
+ pycarlo-0.12.5.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
47
+ pycarlo-0.12.5.dist-info/top_level.txt,sha256=TIE04H4pgzGaFxAB-gvkmVAUOAoHxxFfhnEcpuQ5bF4,8
48
+ pycarlo-0.12.5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (75.3.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5