pycarlo-0.9.9
0.9.9
0.9.8
0.9.7
0.9.6
0.9.5
0.9.4
0.9.3
0.9.2
0.9.15
0.9.14
0.9.13
0.9.12
0.9.11
0.9.10
0.9.1
0.8.9
0.8.8
0.8.7
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.15
0.8.14
0.8.13
0.8.12
0.8.11
0.8.10
0.8.1
0.8.0
0.7.7
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.1
0.5.0
0.4.0
0.3.1
0.3.0
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.12.99
0.12.98
0.12.97
0.12.96
0.12.95
0.12.94
0.12.93
0.12.92
0.12.91
0.12.90
0.12.9
0.12.89
0.12.88
0.12.87
0.12.86
0.12.85
0.12.84
0.12.83
0.12.82
0.12.81
0.12.80
0.12.8
0.12.79
0.12.78
0.12.77
0.12.76
0.12.75
0.12.74
0.12.73
0.12.72
0.12.71
0.12.70
0.12.7
0.12.69
0.12.68
0.12.67
0.12.66
0.12.65
0.12.64
0.12.63
0.12.62
0.12.61
0.12.60
0.12.6
0.12.59
0.12.58
0.12.57
0.12.56
0.12.55
0.12.54
0.12.53
0.12.52
0.12.51
0.12.50
0.12.5
0.12.49
0.12.48
0.12.47
0.12.46
0.12.45
0.12.44
0.12.43
0.12.42
0.12.41
0.12.40
0.12.4
0.12.39
0.12.38
0.12.37
0.12.36
0.12.35
0.12.34
0.12.33
0.12.32
0.12.31
0.12.30
0.12.3
0.12.29
0.12.28
0.12.27
0.12.26
0.12.25
0.12.24
0.12.23
0.12.22
0.12.21
0.12.20
0.12.2
0.12.19
0.12.18
0.12.17
0.12.16
0.12.158
0.12.157
0.12.156
0.12.155
0.12.154
0.12.153
0.12.152
0.12.151
0.12.150
0.12.15
0.12.149
0.12.148
0.12.147
0.12.146
0.12.145
0.12.144
0.12.143
0.12.142
0.12.141
0.12.140
0.12.14
0.12.139
0.12.138
0.12.137
0.12.136
0.12.135
0.12.134
0.12.133
0.12.132
0.12.131
0.12.130
0.12.13
0.12.129
0.12.128
0.12.127
0.12.126
0.12.125
0.12.124
0.12.123
0.12.122
0.12.121
0.12.120
0.12.12
0.12.119
0.12.118
0.12.117
0.12.116
0.12.115
0.12.114
0.12.113
0.12.112
0.12.111
0.12.110
0.12.11
0.12.109
0.12.108
0.12.107
0.12.106
0.12.105
0.12.104
0.12.103
0.12.102
0.12.101
0.12.100
0.12.10
0.12.1
0.12.0b1
0.11.9
0.11.8
0.11.7
0.11.6
0.11.5
0.11.4
0.11.3
0.11.28
0.11.27
0.11.26
0.11.25
0.11.24
0.11.23
0.11.22
0.11.21
0.11.20
0.11.2
0.11.19
0.11.18
0.11.17
0.11.16
0.11.15
0.11.14
0.11.13
0.11.12
0.11.11
0.11.10
0.11.1
0.11.0
0.10.99
0.10.98
0.10.97
0.10.96
0.10.95
0.10.94
0.10.93
0.10.92
0.10.91
0.10.90
0.10.9
0.10.89
0.10.88
0.10.87
0.10.86
0.10.85
0.10.84
0.10.83
0.10.82
0.10.81
0.10.80
0.10.8
0.10.79
0.10.78
0.10.77
0.10.76
0.10.75
0.10.74
0.10.73
0.10.72
0.10.71
0.10.70
0.10.7
0.10.69
0.10.68
0.10.67
0.10.66
0.10.65
0.10.64
0.10.63
0.10.62
0.10.61
0.10.60
0.10.6
0.10.59
0.10.58
0.10.57
0.10.56
0.10.55
0.10.54
0.10.53
0.10.52
0.10.51
0.10.50
0.10.5
0.10.49
0.10.48
0.10.47
0.10.46
0.10.45
0.10.44
0.10.43
0.10.42
0.10.41
0.10.40
0.10.4
0.10.39
0.10.38
0.10.37
0.10.36
0.10.35
0.10.34
0.10.33
0.10.32
0.10.31
0.10.30
0.10.3
0.10.29
0.10.28
0.10.27
0.10.26
0.10.25
0.10.24
0.10.235
0.10.234
0.10.233
0.10.232
0.10.231
0.10.230
0.10.23
0.10.229
0.10.228
0.10.227
0.10.226
0.10.225
0.10.224
0.10.223
0.10.222
0.10.221
0.10.220
0.10.22
0.10.219
0.10.218
0.10.217
0.10.216
0.10.215
0.10.214
0.10.213
0.10.212
0.10.211
0.10.210
0.10.21
0.10.209
0.10.208
0.10.207
0.10.206
0.10.205
0.10.204
0.10.203
0.10.202
0.10.201
0.10.200
0.10.20
0.10.2
0.10.199
0.10.198
0.10.197
0.10.196
0.10.195
0.10.194
0.10.193
0.10.192
0.10.191
0.10.190
0.10.19
0.10.189
0.10.188
0.10.187
0.10.186
0.10.185
0.10.184
0.10.183
0.10.182
0.10.181
0.10.180
0.10.18
0.10.179
0.10.178
0.10.177
0.10.176
0.10.175
0.10.174
0.10.173
0.10.172
0.10.171
0.10.170
0.10.17
0.10.169
0.10.168
0.10.167
0.10.166
0.10.165
0.10.164
0.10.163
0.10.162
0.10.161
0.10.160
0.10.16
0.10.159
0.10.158
0.10.157
0.10.156
0.10.155
0.10.154
0.10.153
0.10.152
0.10.151
0.10.150
0.10.15
0.10.149
0.10.148
0.10.147
0.10.146
0.10.145
0.10.144
0.10.143
0.10.142
0.10.141
0.10.140
0.10.14
0.10.139
0.10.138
0.10.137
0.10.136
0.10.135
0.10.134
0.10.133
0.10.132
0.10.131
0.10.130
0.10.13
0.10.129
0.10.128
0.10.127
0.10.126
0.10.125
0.10.124
0.10.123
0.10.122
0.10.121
0.10.120
0.10.12
0.10.119
0.10.118
0.10.117
0.10.116
0.10.115
0.10.114
0.10.113
0.10.112
0.10.111
0.10.110
0.10.11
0.10.109
0.10.108
0.10.107
0.10.106
0.10.105
0.10.104
0.10.103
0.10.102
0.10.101
0.10.100
0.10.10
0.10.1
0.10.0
0.1.3
0.1.2
0.1.1
0.1.0
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.11
0.0.10
0.9.9
0.9.8
0.9.7
0.9.6
0.9.5
0.9.4
0.9.3
0.9.2
0.9.15
0.9.14
0.9.13
0.9.12
0.9.11
0.9.10
0.9.1
0.8.9
0.8.8
0.8.7
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.15
0.8.14
0.8.13
0.8.12
0.8.11
0.8.10
0.8.1
0.8.0
0.7.7
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.1
0.5.0
0.4.0
0.3.1
0.3.0
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.12.99
0.12.98
0.12.97
0.12.96
0.12.95
0.12.94
0.12.93
0.12.92
0.12.91
0.12.90
0.12.9
0.12.89
0.12.88
0.12.87
0.12.86
0.12.85
0.12.84
0.12.83
0.12.82
0.12.81
0.12.80
0.12.8
0.12.79
0.12.78
0.12.77
0.12.76
0.12.75
0.12.74
0.12.73
0.12.72
0.12.71
0.12.70
0.12.7
0.12.69
0.12.68
0.12.67
0.12.66
0.12.65
0.12.64
0.12.63
0.12.62
0.12.61
0.12.60
0.12.6
0.12.59
0.12.58
0.12.57
0.12.56
0.12.55
0.12.54
0.12.53
0.12.52
0.12.51
0.12.50
0.12.5
0.12.49
0.12.48
0.12.47
0.12.46
0.12.45
0.12.44
0.12.43
0.12.42
0.12.41
0.12.40
0.12.4
0.12.39
0.12.38
0.12.37
0.12.36
0.12.35
0.12.34
0.12.33
0.12.32
0.12.31
0.12.30
0.12.3
0.12.29
0.12.28
0.12.27
0.12.26
0.12.25
0.12.24
0.12.23
0.12.22
0.12.21
0.12.20
0.12.2
0.12.19
0.12.18
0.12.17
0.12.16
0.12.158
0.12.157
0.12.156
0.12.155
0.12.154
0.12.153
0.12.152
0.12.151
0.12.150
0.12.15
0.12.149
0.12.148
0.12.147
0.12.146
0.12.145
0.12.144
0.12.143
0.12.142
0.12.141
0.12.140
0.12.14
0.12.139
0.12.138
0.12.137
0.12.136
0.12.135
0.12.134
0.12.133
0.12.132
0.12.131
0.12.130
0.12.13
0.12.129
0.12.128
0.12.127
0.12.126
0.12.125
0.12.124
0.12.123
0.12.122
0.12.121
0.12.120
0.12.12
0.12.119
0.12.118
0.12.117
0.12.116
0.12.115
0.12.114
0.12.113
0.12.112
0.12.111
0.12.110
0.12.11
0.12.109
0.12.108
0.12.107
0.12.106
0.12.105
0.12.104
0.12.103
0.12.102
0.12.101
0.12.100
0.12.10
0.12.1
0.12.0b1
0.11.9
0.11.8
0.11.7
0.11.6
0.11.5
0.11.4
0.11.3
0.11.28
0.11.27
0.11.26
0.11.25
0.11.24
0.11.23
0.11.22
0.11.21
0.11.20
0.11.2
0.11.19
0.11.18
0.11.17
0.11.16
0.11.15
0.11.14
0.11.13
0.11.12
0.11.11
0.11.10
0.11.1
0.11.0
0.10.99
0.10.98
0.10.97
0.10.96
0.10.95
0.10.94
0.10.93
0.10.92
0.10.91
0.10.90
0.10.9
0.10.89
0.10.88
0.10.87
0.10.86
0.10.85
0.10.84
0.10.83
0.10.82
0.10.81
0.10.80
0.10.8
0.10.79
0.10.78
0.10.77
0.10.76
0.10.75
0.10.74
0.10.73
0.10.72
0.10.71
0.10.70
0.10.7
0.10.69
0.10.68
0.10.67
0.10.66
0.10.65
0.10.64
0.10.63
0.10.62
0.10.61
0.10.60
0.10.6
0.10.59
0.10.58
0.10.57
0.10.56
0.10.55
0.10.54
0.10.53
0.10.52
0.10.51
0.10.50
0.10.5
0.10.49
0.10.48
0.10.47
0.10.46
0.10.45
0.10.44
0.10.43
0.10.42
0.10.41
0.10.40
0.10.4
0.10.39
0.10.38
0.10.37
0.10.36
0.10.35
0.10.34
0.10.33
0.10.32
0.10.31
0.10.30
0.10.3
0.10.29
0.10.28
0.10.27
0.10.26
0.10.25
0.10.24
0.10.235
0.10.234
0.10.233
0.10.232
0.10.231
0.10.230
0.10.23
0.10.229
0.10.228
0.10.227
0.10.226
0.10.225
0.10.224
0.10.223
0.10.222
0.10.221
0.10.220
0.10.22
0.10.219
0.10.218
0.10.217
0.10.216
0.10.215
0.10.214
0.10.213
0.10.212
0.10.211
0.10.210
0.10.21
0.10.209
0.10.208
0.10.207
0.10.206
0.10.205
0.10.204
0.10.203
0.10.202
0.10.201
0.10.200
0.10.20
0.10.2
0.10.199
0.10.198
0.10.197
0.10.196
0.10.195
0.10.194
0.10.193
0.10.192
0.10.191
0.10.190
0.10.19
0.10.189
0.10.188
0.10.187
0.10.186
0.10.185
0.10.184
0.10.183
0.10.182
0.10.181
0.10.180
0.10.18
0.10.179
0.10.178
0.10.177
0.10.176
0.10.175
0.10.174
0.10.173
0.10.172
0.10.171
0.10.170
0.10.17
0.10.169
0.10.168
0.10.167
0.10.166
0.10.165
0.10.164
0.10.163
0.10.162
0.10.161
0.10.160
0.10.16
0.10.159
0.10.158
0.10.157
0.10.156
0.10.155
0.10.154
0.10.153
0.10.152
0.10.151
0.10.150
0.10.15
0.10.149
0.10.148
0.10.147
0.10.146
0.10.145
0.10.144
0.10.143
0.10.142
0.10.141
0.10.140
0.10.14
0.10.139
0.10.138
0.10.137
0.10.136
0.10.135
0.10.134
0.10.133
0.10.132
0.10.131
0.10.130
0.10.13
0.10.129
0.10.128
0.10.127
0.10.126
0.10.125
0.10.124
0.10.123
0.10.122
0.10.121
0.10.120
0.10.12
0.10.119
0.10.118
0.10.117
0.10.116
0.10.115
0.10.114
0.10.113
0.10.112
0.10.111
0.10.110
0.10.11
0.10.109
0.10.108
0.10.107
0.10.106
0.10.105
0.10.104
0.10.103
0.10.102
0.10.101
0.10.100
0.10.10
0.10.1
0.10.0
0.1.3
0.1.2
0.1.1
0.1.0
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.11
0.0.10
توضیحات
Monte Carlo's Python SDK
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | pycarlo-0.9.9 |
| نام | pycarlo |
| نسخه کتابخانه | 0.9.9 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Monte Carlo Data, Inc |
| ایمیل نویسنده | info@montecarlodata.com |
| آدرس صفحه اصلی | https://www.montecarlodata.com/ |
| آدرس اینترنتی | https://pypi.org/project/pycarlo/ |
| مجوز | Apache Software License (Apache 2.0) |
# Pycarlo - Monte Carlo's Python SDK
## Installation
Requires Python 3.9 or greater. Normally you can install and update using pip. For instance:
```shell
virtualenv venv
. venv/bin/activate
pip install -U pycarlo
```
## Overview
Pycarlo comprises two components: `core` and `features`.
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.
The `features` library provides additional convenience for performing common operations like with
dbt, circuit breaking, and pii filtering.
Note that an API Key is required to use the SDK. See
[our docs on generating API keys](https://docs.getmontecarlo.com/docs/developer-resources#creating-an-api-key)
for details.
## Basic usage
### Core
```python
from pycarlo.core import Client, Query, Mutation
# First create a client. This creates a session using the 'default' profile from
# '~/.mcd/profiles.ini'. This profile is created automatically via
# `montecarlo configure` on the CLI. See the session subsection for
# customizations, options and alternatives (e.g. using the environment, params,
# named profiles, etc.)
client = Client()
# Now you can can execute a query. For instance, getUser (selecting the email field).
# This would be like executing -
# curl --location --request POST 'https://api.getmontecarlo.com/graphql' \
# --header 'x-mcd-id: <ID>' \
# --header 'x-mcd-token: <TOKEN>' \
# --header 'Content-Type: application/json' \
# --data-raw '{"query": "query {getUser {email}}"}'
# Notice how the CamelCase from the Graphql query is converted to snake_case in
# both the request and response.
query = Query()
query.get_user.__fields__('email')
print(client(query).get_user.email)
# You can also execute a query that requires variables. For instance,
# testTelnetConnection (selecting all fields).
query = Query()
query.test_telnet_connection(host='montecarlodata.com', port=443)
print(client(query))
# If necessary, you can always generate (e.g. print) the raw query that would be executed.
print(query)
# query {
# testTelnetConnection(host: "montecarlodata.com", port: 443) {
# success
# validations {
# type
# message
# }
# warnings {
# type
# message
# }
# }
# }
# If you are not a fan of sgqlc operations (Query and Mutation) you can also execute any
# raw query using the client. For instance, if we want the first 10 tables from getTables.
get_table_query = """
query getTables{
getTables(first: 10) {
edges {
node {
fullTableId
}
}
}
}
"""
response = client(get_table_query)
# This returns a Box object where fields can be accessed using dot notation.
# Notice how unlike with the API the response uses the more Pythonic snake_case.
for edge in response.get_tables.edges:
print(edge.node.full_table_id)
# The response can still be processed as a standard dictionary.
print(response['get_tables']['edges'][0]['node']['full_table_id'])
# You can also execute any mutations too. For instance, generateCollectorTemplate
# (selecting the templateLaunchUrl).
mutation = Mutation()
mutation.generate_collector_template().dc.template_launch_url()
print(client(mutation))
# Any errors will raise a GqlError with details. For instance, executing above with an
# invalid region.
mutation = Mutation()
mutation.generate_collector_template(region='artemis')
print(client(mutation))
# pycarlo.common.errors.GqlError: [
# {'message': 'Region "\'artemis\'" not currently active.'...
# ]
```
### Examples
#### Circuit Breaker Example
```python
from pycarlo.core import Client, Session
from pycarlo.features.circuit_breakers import CircuitBreakerService
# Example from our test.snowflake account.
endpoint = "https://api.dev.getmontecarlo.com/graphql"
service = CircuitBreakerService(
mc_client=Client(Session(mcd_profile="test-snow", endpoint=endpoint)), print_func=print
)
in_breach = service.trigger_and_poll(rule_uuid="87872875-fe80-4963-8ab0-c04397a6daae")
print("That can't be good. Our warehouse is broken." if in_breach else "Go, go, go!.")
```
#### Insight Upload Example
```python
from pathlib import Path
import boto3
import requests
from pycarlo.core import Client, Query
MC_CLIENT = Client()
S3_CLIENT = boto3.client("s3")
def upload_insights_to_s3(
destination_bucket: str,
desired_file_extension: str = ".csv",
) -> None:
"""
Example function for listing all insights in an account, and uploading any available
to S3 as a CSV.
"""
list_insights_query = Query()
list_insights_query.get_insights()
for insight in MC_CLIENT(list_insights_query).get_insights:
report_name = str(Path(insight.name).with_suffix(desired_file_extension))
if insight.available:
report_url_query = Query()
report_url_query.get_report_url(insight_name=insight.name, report_name=report_name)
report_url = MC_CLIENT(report_url_query).get_report_url.url
print(f"Uploading {report_name} to {destination_bucket}.")
S3_CLIENT.upload_fileobj(
Fileobj=requests.get(url=report_url, stream=True).raw,
Bucket=destination_bucket,
Key=report_name,
)
if __name__ == "__main__":
upload_insights_to_s3(destination_bucket="<BUCKET-NAME>")
```
See [Monte Carlo's API reference](https://apidocs.getmontecarlo.com/) for all supported queries and
mutations.
For details and additional examples on how to map (convert) GraphQL queries to `sgqlc` operations
please refer to [the sgqlc docs](https://sgqlc.readthedocs.io/en/latest/sgqlc.operation.html).
### Features
You can use [pydoc](https://docs.python.org/library/pydoc.html) to retrieve documentation on any
feature packages (`pydoc pycarlo.features`).
For instance for [circuit breakers](https://docs.getmontecarlo.com/docs/circuit-breakers):
```shell
pydoc pycarlo.features.circuit_breakers.service
```
## Session configuration
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. See [Monte Carlo's CLI reference](https://clidocs.getmontecarlo.com/) for more details.
You can override this usage by creating a custom `Session`. For instance, if you want to pass the ID
and Token:
```python
from pycarlo.core import Client, Session
client = Client(session=Session(mcd_id='foo', mcd_token='bar'))
```
Sessions support the following params:
- `mcd_id`: API Key ID.
- `mcd_token`: API secret.
- `mcd_profile`: Named profile containing credentials. This is created via the CLI (e.g.
`montecarlo configure --profile-name zeus`).
- `mcd_config_path`: Path to file containing credentials. Defaults to `~/.mcd/`.
You can also specify the API Key, secret or profile name using the following environment variables:
- `MCD_DEFAULT_API_ID`
- `MCD_DEFAULT_API_TOKEN`
- `MCD_DEFAULT_PROFILE`
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.
Environment variables can be mixed with passed credentials, but not the config-file profile.
**We do not recommend passing `mcd_token` as it is a secret and can be accidentally committed.**
## Integration Gateway API
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.
To use the Gateway you need to initialize the `Session` object passing a `scope` parameter and then
use `make_request` to invoke Gateway endpoints:
```python
from pycarlo.core import Client, Session
client = Client(session=Session(mcd_id='foo', mcd_token='bar', scope='AirflowCallbacks'))
response = client.make_request(
path='/airflow/callbacks', method='POST', body={}, timeout_in_seconds=20
)
```
## Advanced configuration
The following values also be set by the environment:
- `MCD_VERBOSE_ERRORS`: Enable logging. This includes a trace ID for each session and request.
- `MCD_API_ENDPOINT`: Customize the endpoint where queries and mutations are executed.
## Enum Backward Compatibility
Unlike the baseline `sgqlc` behavior, this SDK is designed to maintain backward compatibility when
new enum values are added to the Monte Carlo API. If the API returns an enum value that doesn't
exist in your SDK version, it will be returned as a string with a warning logged, rather than
raising an error. This allows older SDK versions to continue working when new features are added.
To avoid warnings and ensure full feature support, keep your SDK updated to the latest version.
## References
- Monte Carlo App: <https://getmontecarlo.com>
- Product docs: <https://docs.getmontecarlo.com>
- Status page: <https://status.getmontecarlo.com>
- API (and SDK): <https://apidocs.getmontecarlo.com>
- CLI: <https://clidocs.getmontecarlo.com>
## License
Apache 2.0 - See the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0) for more information.
نیازمندی
| مقدار | نام |
|---|---|
| - | dataclasses-json<6.0.0,>=0.5.7 |
| - | python-box>=5.0.0 |
| - | requests<3.0.0,>=2.0.0 |
| - | responses>=0.20.0 |
| - | sgqlc<17.0,>=14.1 |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.8 | Python |
نحوه نصب
نصب پکیج whl pycarlo-0.9.9:
pip install pycarlo-0.9.9.whl
نصب پکیج tar.gz pycarlo-0.9.9:
pip install pycarlo-0.9.9.tar.gz