-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathclient.py
More file actions
180 lines (150 loc) · 5.85 KB
/
Copy pathclient.py
File metadata and controls
180 lines (150 loc) · 5.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
from __future__ import annotations
from sift_client.resources import (
AssetsAPI,
AssetsAPIAsync,
CalculatedChannelsAPI,
CalculatedChannelsAPIAsync,
ChannelsAPI,
ChannelsAPIAsync,
FileAttachmentsAPI,
FileAttachmentsAPIAsync,
IngestionAPIAsync,
JobsAPI,
JobsAPIAsync,
PingAPI,
PingAPIAsync,
ReportsAPI,
ReportsAPIAsync,
RulesAPI,
RulesAPIAsync,
RunsAPI,
RunsAPIAsync,
TagsAPI,
TagsAPIAsync,
TestResultsAPI,
TestResultsAPIAsync,
)
from sift_client.transport import (
GrpcClient,
GrpcConfig,
RestClient,
RestConfig,
SiftConnectionConfig,
WithGrpcClient,
WithRestClient,
)
from sift_client.util.util import AsyncAPIs
class SiftClient(
WithGrpcClient,
WithRestClient,
):
"""SiftClient is a high-level client for interacting with Sift's APIs.
It provides both synchronous and asynchronous interfaces, strong type checking, and a Pythonic API design.
Examples:
from sift_client import SiftClient
from datetime import datetime
# Initialize with individual parameters
client = SiftClient(
api_key="your-api-key",
grpc_url="your-sift-grpc-url",
rest_url="your-sift-rest-url")
# Or use a connection configuration to customize connection behavior
connection_config = SiftConnectionConfig(
grpc_config=GrpcConfig(),
rest_config=RestConfig())
sift = SiftClient(connection_config=connection_config)
# Use the client to make requests
response = sift.ping.ping()
# Or asynchronously
response = await sift.async_.ping.ping()
"""
ping: PingAPI
"""Instance of the Ping API for making synchronous requests."""
assets: AssetsAPI
"""Instance of the Assets API for making synchronous requests."""
calculated_channels: CalculatedChannelsAPI
"""Instance of the Calculated Channels API for making synchronous requests."""
channels: ChannelsAPI
"""Instance of the Channels API for making synchronous requests."""
file_attachments: FileAttachmentsAPI
"""Instance of the File Attachments API for making synchronous requests."""
ingestion: IngestionAPIAsync
"""Instance of the Ingestion API for making synchronous requests."""
jobs: JobsAPI
"""Instance of the Jobs API for making synchronous requests."""
reports: ReportsAPI
"""Instance of the Reports API for making synchronous requests."""
rules: RulesAPI
"""Instance of the Rules API for making synchronous requests."""
runs: RunsAPI
"""Instance of the Runs API for making synchronous requests."""
tags: TagsAPI
"""Instance of the Tags API for making synchronous requests."""
test_results: TestResultsAPI
"""Instance of the Test Results API for making synchronous requests."""
async_: AsyncAPIs
"""Accessor for the asynchronous APIs. All asynchronous APIs are available as attributes on this accessor."""
def __init__(
self,
api_key: str | None = None,
grpc_url: str | None = None,
rest_url: str | None = None,
connection_config: SiftConnectionConfig | None = None,
):
"""Initialize the SiftClient with specific connection parameters or a connection_config.
Args:
api_key: The Sift API key for authentication.
grpc_url: The Sift gRPC API URL.
rest_url: The Sift REST API URL.
connection_config: A SiftConnectionConfig object to configure the connection behavior of the SiftClient.
"""
if not (api_key and grpc_url and rest_url) and not connection_config:
raise ValueError(
"Either api_key, grpc_url and rest_url or connection_config must be provided to establish a connection."
)
if connection_config:
grpc_client = GrpcClient(connection_config.get_grpc_config())
rest_client = RestClient(connection_config.get_rest_config())
elif api_key and grpc_url and rest_url:
grpc_client = GrpcClient(GrpcConfig(grpc_url, api_key))
rest_client = RestClient(RestConfig(rest_url, api_key))
else:
raise ValueError(
"Invalid connection configuration. Please provide api_key, grpc_uri and rest_uri or a connection_config."
)
WithGrpcClient.__init__(self, grpc_client=grpc_client)
WithRestClient.__init__(self, rest_client=rest_client)
self.ping = PingAPI(self)
self.assets = AssetsAPI(self)
self.calculated_channels = CalculatedChannelsAPI(self)
self.channels = ChannelsAPI(self)
self.file_attachments = FileAttachmentsAPI(self)
self.jobs = JobsAPI(self)
self.rules = RulesAPI(self)
self.reports = ReportsAPI(self)
self.runs = RunsAPI(self)
self.tags = TagsAPI(self)
self.test_results = TestResultsAPI(self)
# Accessor for the asynchronous APIs
self.async_ = AsyncAPIs(
ping=PingAPIAsync(self),
assets=AssetsAPIAsync(self),
calculated_channels=CalculatedChannelsAPIAsync(self),
channels=ChannelsAPIAsync(self),
file_attachments=FileAttachmentsAPIAsync(self),
ingestion=IngestionAPIAsync(self),
jobs=JobsAPIAsync(self),
reports=ReportsAPIAsync(self),
rules=RulesAPIAsync(self),
runs=RunsAPIAsync(self),
tags=TagsAPIAsync(self),
test_results=TestResultsAPIAsync(self),
)
@property
def grpc_client(self) -> GrpcClient:
"""The gRPC client used by the SiftClient for making gRPC API calls."""
return self._grpc_client
@property
def rest_client(self) -> RestClient:
"""The REST client used by the SiftClient for making REST API calls."""
return self._rest_client