fxn 0.0.35__py3-none-any.whl → 0.0.37__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.
- fxn/c/__init__.py +16 -0
- fxn/c/configuration.py +60 -0
- fxn/c/dtype.py +26 -0
- fxn/c/fxnc.py +28 -0
- fxn/c/map.py +34 -0
- fxn/c/prediction.py +37 -0
- fxn/c/predictor.py +31 -0
- fxn/c/status.py +12 -0
- fxn/c/stream.py +22 -0
- fxn/c/value.py +50 -0
- fxn/c/version.py +13 -0
- fxn/cli/__init__.py +8 -8
- fxn/cli/auth.py +1 -1
- fxn/cli/misc.py +10 -4
- fxn/cli/predict.py +3 -4
- fxn/cli/predictors.py +1 -40
- fxn/function.py +4 -10
- fxn/lib/macos/arm64/Function.dylib +0 -0
- fxn/lib/macos/x86_64/Function.dylib +0 -0
- fxn/lib/windows/arm64/Function.dll +0 -0
- fxn/lib/windows/x86_64/Function.dll +0 -0
- fxn/services/__init__.py +1 -3
- fxn/services/prediction.py +456 -0
- fxn/services/predictor.py +4 -73
- fxn/services/user.py +1 -1
- fxn/types/__init__.py +2 -3
- fxn/types/prediction.py +0 -4
- fxn/types/predictor.py +15 -22
- fxn/version.py +1 -1
- {fxn-0.0.35.dist-info → fxn-0.0.37.dist-info}/METADATA +27 -29
- fxn-0.0.37.dist-info/RECORD +46 -0
- {fxn-0.0.35.dist-info → fxn-0.0.37.dist-info}/WHEEL +1 -1
- fxn/libs/linux/__init__.py +0 -4
- fxn/libs/macos/Function.dylib +0 -0
- fxn/libs/macos/__init__.py +0 -4
- fxn/libs/windows/Function.dll +0 -0
- fxn/libs/windows/__init__.py +0 -4
- fxn/magic.py +0 -35
- fxn/services/environment.py +0 -111
- fxn/services/prediction/__init__.py +0 -6
- fxn/services/prediction/fxnc.py +0 -312
- fxn/services/prediction/service.py +0 -512
- fxn/services/storage.py +0 -160
- fxn/types/value.py +0 -22
- fxn-0.0.35.dist-info/RECORD +0 -42
- /fxn/{graph → api}/__init__.py +0 -0
- /fxn/{graph → api}/client.py +0 -0
- /fxn/{libs → lib}/__init__.py +0 -0
- {fxn-0.0.35.dist-info → fxn-0.0.37.dist-info}/LICENSE +0 -0
- {fxn-0.0.35.dist-info → fxn-0.0.37.dist-info}/entry_points.txt +0 -0
- {fxn-0.0.35.dist-info → fxn-0.0.37.dist-info}/top_level.txt +0 -0
fxn/types/predictor.py
CHANGED
@@ -3,21 +3,24 @@
|
|
3
3
|
# Copyright © 2024 NatML Inc. All Rights Reserved.
|
4
4
|
#
|
5
5
|
|
6
|
-
from enum import Enum
|
7
|
-
from
|
8
|
-
from typing import
|
6
|
+
from enum import Enum, IntFlag
|
7
|
+
from io import BytesIO
|
8
|
+
from numpy.typing import NDArray
|
9
|
+
from PIL import Image
|
10
|
+
from pydantic import AliasChoices, BaseModel, ConfigDict, Field
|
11
|
+
from typing import Any, Dict, List, Optional, Tuple
|
9
12
|
|
10
13
|
from .dtype import Dtype
|
11
14
|
from .profile import Profile
|
12
|
-
from .value import Value
|
13
15
|
|
14
|
-
class Acceleration (
|
16
|
+
class Acceleration (IntFlag):
|
15
17
|
"""
|
16
18
|
Predictor acceleration.
|
17
19
|
"""
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
Default = 0,
|
21
|
+
CPU = 1 << 0,
|
22
|
+
GPU = 1 << 1,
|
23
|
+
NPU = 1 << 2
|
21
24
|
|
22
25
|
class AccessMode (str, Enum):
|
23
26
|
"""
|
@@ -26,13 +29,6 @@ class AccessMode (str, Enum):
|
|
26
29
|
Public = "PUBLIC"
|
27
30
|
Private = "PRIVATE"
|
28
31
|
|
29
|
-
class PredictorType (str, Enum):
|
30
|
-
"""
|
31
|
-
Predictor type.
|
32
|
-
"""
|
33
|
-
Cloud = "CLOUD"
|
34
|
-
Edge = "EDGE"
|
35
|
-
|
36
32
|
class PredictorStatus (str, Enum):
|
37
33
|
"""
|
38
34
|
Predictor status.
|
@@ -51,7 +47,7 @@ class EnumerationMember (BaseModel):
|
|
51
47
|
value (str | int): Enumeration member value.
|
52
48
|
"""
|
53
49
|
name: str = Field(description="Enumeration member name.")
|
54
|
-
value:
|
50
|
+
value: str | int = Field(description="Enumeration member value.")
|
55
51
|
|
56
52
|
class Parameter (BaseModel):
|
57
53
|
"""
|
@@ -64,7 +60,7 @@ class Parameter (BaseModel):
|
|
64
60
|
optional (bool): Whether the parameter is optional.
|
65
61
|
range (tuple): Parameter value range for numeric parameters.
|
66
62
|
enumeration (list): Parameter value choices for enumeration parameters.
|
67
|
-
default_value (
|
63
|
+
default_value (str | float | int | bool | ndarray | list | dict | PIL.Image | BytesIO): Parameter default value.
|
68
64
|
value_schema (dict): Parameter JSON schema. This is only populated for `list` and `dict` parameters.
|
69
65
|
"""
|
70
66
|
name: str = Field(description="Parameter name.")
|
@@ -73,8 +69,9 @@ class Parameter (BaseModel):
|
|
73
69
|
optional: Optional[bool] = Field(default=None, description="Whether the parameter is optional.")
|
74
70
|
range: Optional[Tuple[float, float]] = Field(default=None, description="Parameter value range for numeric parameters.")
|
75
71
|
enumeration: Optional[List[EnumerationMember]] = Field(default=None, description="Parameter value choices for enumeration parameters.")
|
76
|
-
default_value: Optional[
|
72
|
+
default_value: Optional[str | float | int | bool | NDArray | List[Any] | Dict[str, Any] | Image.Image | BytesIO] = Field(default=None, description="Parameter default value.", serialization_alias="defaultValue", validation_alias=AliasChoices("default_value", "defaultValue"))
|
77
73
|
value_schema: Optional[dict] = Field(default=None, description="Parameter JSON schema. This is only populated for `list` and `dict` parameters.", serialization_alias="schema", validation_alias=AliasChoices("schema", "value_schema"))
|
74
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
78
75
|
|
79
76
|
class Signature (BaseModel):
|
80
77
|
"""
|
@@ -95,7 +92,6 @@ class Predictor (BaseModel):
|
|
95
92
|
tag (str): Predictor tag.
|
96
93
|
owner (Profile): Predictor owner.
|
97
94
|
name (str): Predictor name.
|
98
|
-
type (PredictorType): Predictor type.
|
99
95
|
status (PredictorStatus): Predictor status.
|
100
96
|
access (AccessMode): Predictor access.
|
101
97
|
signature (Signature): Predictor signature.
|
@@ -103,13 +99,11 @@ class Predictor (BaseModel):
|
|
103
99
|
description (str): Predictor description.
|
104
100
|
card (str): Predictor card.
|
105
101
|
media (str): Predictor media URL.
|
106
|
-
acceleration (Acceleration): Predictor acceleration. This only applies to cloud predictors.
|
107
102
|
license (str): Predictor license URL.
|
108
103
|
"""
|
109
104
|
tag: str = Field(description="Predictor tag.")
|
110
105
|
owner: Profile = Field(description="Predictor owner.")
|
111
106
|
name: str = Field(description="Predictor name.")
|
112
|
-
type: PredictorType = Field(description="Predictor type.")
|
113
107
|
status: PredictorStatus = Field(description="Predictor status.")
|
114
108
|
access: AccessMode = Field(description="Predictor access.")
|
115
109
|
signature: Signature = Field(description="Predictor signature.")
|
@@ -117,5 +111,4 @@ class Predictor (BaseModel):
|
|
117
111
|
description: Optional[str] = Field(default=None, description="Predictor description.")
|
118
112
|
card: Optional[str] = Field(default=None, description="Predictor card.")
|
119
113
|
media: Optional[str] = Field(default=None, description="Predictor media URL.")
|
120
|
-
acceleration: Optional[Acceleration] = Field(default=None, description="Predictor acceleration. This only applies to cloud predictors.")
|
121
114
|
license: Optional[str] = Field(default=None, description="Predictor license URL.")
|
fxn/version.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: fxn
|
3
|
-
Version: 0.0.
|
4
|
-
Summary: Run
|
3
|
+
Version: 0.0.37
|
4
|
+
Summary: Run prediction functions locally in Python. Register at https://fxn.ai.
|
5
5
|
Author-email: "NatML Inc." <hi@fxn.ai>
|
6
6
|
License: Apache License
|
7
7
|
Version 2.0, January 2004
|
@@ -213,14 +213,12 @@ Classifier: License :: OSI Approved :: Apache Software License
|
|
213
213
|
Classifier: Operating System :: OS Independent
|
214
214
|
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
215
215
|
Classifier: Topic :: Software Development :: Libraries
|
216
|
-
Requires-Python: >=3.
|
216
|
+
Requires-Python: >=3.10
|
217
217
|
Description-Content-Type: text/markdown
|
218
218
|
License-File: LICENSE
|
219
|
-
Requires-Dist: aiohttp
|
220
|
-
Requires-Dist: magika
|
221
219
|
Requires-Dist: numpy
|
222
220
|
Requires-Dist: pillow
|
223
|
-
Requires-Dist: pydantic
|
221
|
+
Requires-Dist: pydantic>=2.0
|
224
222
|
Requires-Dist: requests
|
225
223
|
Requires-Dist: rich
|
226
224
|
Requires-Dist: typer
|
@@ -231,52 +229,52 @@ Requires-Dist: typer
|
|
231
229
|
|
232
230
|
[](https://fxn.ai/community)
|
233
231
|
|
234
|
-
Run
|
232
|
+
Run prediction functions (a.k.a "predictors") locally in your Python apps, with full GPU acceleration and zero dependencies. In a few steps:
|
235
233
|
|
236
234
|
## Installing Function
|
237
235
|
Function is distributed on PyPi. This distribution contains both the Python client and the command line interface (CLI). To install, open a terminal and run the following command:
|
238
236
|
```sh
|
239
|
-
|
237
|
+
# Install Function
|
238
|
+
$ pip install --upgrade fxn
|
240
239
|
```
|
241
240
|
|
242
241
|
> [!NOTE]
|
243
242
|
> Function requires Python 3.9+
|
244
243
|
|
245
|
-
##
|
246
|
-
|
244
|
+
## Retrieving your Access Key
|
245
|
+
Head over to [fxn.ai](https://fxn.ai) to create an account by logging in. Once you do, generate an access key:
|
246
|
+
|
247
|
+

|
247
248
|
|
248
|
-
|
249
|
-
Run the following Python script:
|
249
|
+
## Making a Prediction
|
250
|
+
Let's run the [`@fxn/greeting`](https://fxn.ai/@fxn/greeting) predictor which accepts a `name` and returns a congenial greeting. Run the following Python script:
|
250
251
|
```py
|
251
252
|
from fxn import Function
|
252
253
|
|
253
254
|
# Create the Function client
|
254
|
-
fxn = Function()
|
255
|
+
fxn = Function(access_key="<Function access key>")
|
255
256
|
# Create a prediction
|
256
257
|
prediction = fxn.predictions.create(
|
257
|
-
tag="@
|
258
|
-
inputs={
|
259
|
-
"prompt": "An astronaut riding a horse on Mars"
|
260
|
-
}
|
258
|
+
tag="@fxn/greeting",
|
259
|
+
inputs={ "name": "Peter" }
|
261
260
|
)
|
262
|
-
#
|
263
|
-
|
264
|
-
image.show()
|
261
|
+
# Print the returned greeting
|
262
|
+
print(prediction.results[0])
|
265
263
|
```
|
266
264
|
|
267
|
-
|
265
|
+
> [!TIP]
|
266
|
+
> Explore public predictors [on Function](https://fxn.ai/explore) or [create your own](https://fxn.ai/waitlist).
|
267
|
+
r
|
268
|
+
## Using the Function CLI
|
268
269
|
Open up a terminal and run the following command:
|
269
270
|
|
270
271
|
```sh
|
271
|
-
|
272
|
-
|
272
|
+
# Login to Function
|
273
|
+
fxn auth login <ACCESS KEY>
|
273
274
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
## Creating a Predictor
|
279
|
-
At some point, you might want to create your own predictor. With Function, you don't have to deal with GitHub repos, Dockerfiles, or weird YAMLs. All you need is a Jupyter Notebook with a `predict` function. See our [samples project](https://github.com/fxnai/samples) for more.
|
275
|
+
# Make a prediction using the Function CLI
|
276
|
+
fxn predict @fxn/greeting --name Peter
|
277
|
+
```
|
280
278
|
|
281
279
|
___
|
282
280
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
fxn/__init__.py,sha256=tWk0-aCNHX_yCS-Dg90pYnniNka9MWFoNMk6xY7u4nI,157
|
2
|
+
fxn/function.py,sha256=W_JkTk3KAMpFGqh95yO-Iy4AvFU22UJZkRt15dyf3IY,1187
|
3
|
+
fxn/version.py,sha256=wjJZ4T4vd1dYpP5qvR3wfnAkWkgGYwz6yi2XeM2_KCY,95
|
4
|
+
fxn/api/__init__.py,sha256=rJIDBhYg5jcrWO4hT4-CpwPq6dSgmLTEHCfUYTLpVaI,103
|
5
|
+
fxn/api/client.py,sha256=WCNsebcuwIlP9W5k_8AQCpxOCcy7cpbengfu2rIkGmc,1192
|
6
|
+
fxn/c/__init__.py,sha256=qBnS4_eoBe5biKoyhW0Fsfr3cqJ9SAvzmm-XB56ev0A,438
|
7
|
+
fxn/c/configuration.py,sha256=BU6WRaYVCjdCSTESNqZX9ghvA19l1yLUCn5EhChQTpA,2707
|
8
|
+
fxn/c/dtype.py,sha256=jcbFpQSnpvMPwXQ3mVyTZRSlJxcaArM2cvgXwAqzx0Q,386
|
9
|
+
fxn/c/fxnc.py,sha256=kaEWw_bmDVj55IcSJR8sPmmEE2-DwTAt-MW6h3p8aIU,859
|
10
|
+
fxn/c/map.py,sha256=IXYPGp4KEmgoO7v-EXJNDBVDm8qmMEuDDYZR1SCKFCM,1234
|
11
|
+
fxn/c/prediction.py,sha256=foPETcJUGn8QxBbub0O7EBPA8G3i9XNdwV22iB1Rm-A,1476
|
12
|
+
fxn/c/predictor.py,sha256=sqJo7BMnl_tVUlZx5tNy5IwoxK8bx-sHJzgYtSJkQR0,1172
|
13
|
+
fxn/c/status.py,sha256=QodZjS0pVI5NIBw5x2OobJLV44VVNhB0UNKmOI9yuAk,225
|
14
|
+
fxn/c/stream.py,sha256=F2R9eUPW3fvUzb7KBfRCk9KiGFl_Yhdf0gqEzM06RKs,725
|
15
|
+
fxn/c/value.py,sha256=FZbEaeJYBxdOIVOPR4n0wJ1G_8I0RZ6dRFPcVsDLYbU,1931
|
16
|
+
fxn/c/version.py,sha256=fnV14LTAXSl6Q03YFIWOINOUrs0DJpyBOcwP5VZvLFc,282
|
17
|
+
fxn/cli/__init__.py,sha256=c9qBvRTHSWnO-8Ny431RlkZWznF7sShJfHYfjBazjRk,1481
|
18
|
+
fxn/cli/auth.py,sha256=tMjgNA6AQeom3I5AsgPvWvN62cM3nFGBcjjXB7x4s8U,1688
|
19
|
+
fxn/cli/env.py,sha256=shqoP4tUiXdOoil73oiUYpqGeVcR119HPYFKgnoF894,1553
|
20
|
+
fxn/cli/misc.py,sha256=6zYuuF1pm1LzYkHG4YaSnBxzs7h8CReI6YLk1ysGRso,843
|
21
|
+
fxn/cli/predict.py,sha256=hpd1VZtw1OBNkZwePCFtyTHLSDOzc8fuSODGmvmmG1E,3026
|
22
|
+
fxn/cli/predictors.py,sha256=SSvxf5emr_upcU78vhdB2F9PM351YdP2a1bqf8FRaxE,2248
|
23
|
+
fxn/lib/__init__.py,sha256=c_q01PLV3Mi-qV0_HVbNRHOI2TIUr_cDIJHvCASsYZk,71
|
24
|
+
fxn/lib/macos/arm64/Function.dylib,sha256=N-ewU2AXqgVAsYPpEnlWU09uyxLAywtsL0ous4MG3Zg,268736
|
25
|
+
fxn/lib/macos/x86_64/Function.dylib,sha256=DfoGF8v-lvxo8a10QUZ0egbfQZo6B6tNct5NMV1kpYc,269744
|
26
|
+
fxn/lib/windows/arm64/Function.dll,sha256=kvixEsiKalAqMOyCRpcAcFgkXxK_9Vt-WDQgws5M6Xg,425472
|
27
|
+
fxn/lib/windows/x86_64/Function.dll,sha256=lEHVER_6PQUqJHDd6YWMqZ2X6PLnJTmVa68cUgp5lJ8,450560
|
28
|
+
fxn/services/__init__.py,sha256=TZBB8xekhfA_Z1Jh68m_GScjXYsLGdx9MlCrjF9Ojsc,249
|
29
|
+
fxn/services/prediction.py,sha256=EfjnwF_GEKSifClzsBWBuKe-NeSk9CeAMQAYDT0lF9A,20228
|
30
|
+
fxn/services/predictor.py,sha256=0FOrnGJo0Z0IqpY5exe7laHFXTbA6NXmWLeu8zioEJ0,5071
|
31
|
+
fxn/services/user.py,sha256=niExZwZFl_hlgLTz9lvrU3QrVR8oKdMcm623wyQK-cA,1217
|
32
|
+
fxn/types/__init__.py,sha256=GY7ST0Ue_sh4rB3a4MHkvql_Cn0p9qZ4wlf3luPOwk8,398
|
33
|
+
fxn/types/dtype.py,sha256=YpTnIG-yzrQwda27GzfGZcel-zF3gOMMoHhcWD915BY,617
|
34
|
+
fxn/types/environment.py,sha256=FbmfGjSb5yYMT9IyDj8zNUpsoP3RbzqM6tK8gn2TfDs,394
|
35
|
+
fxn/types/prediction.py,sha256=y54TA0w16MVW2jUwN6U-BtXARZgyk2WXy2mHDf9Hsjw,2028
|
36
|
+
fxn/types/predictor.py,sha256=bqpt3m616JloxkcIGxUKP1_-7ioLXepe8DjgfEPzj-E,4699
|
37
|
+
fxn/types/profile.py,sha256=1KWqPusKieCIcw4KSS2sScpwP0Z-mU4ThMYOZRxZ_68,1123
|
38
|
+
fxn/types/storage.py,sha256=AtVKR3CtHzvSWLiJS_bbUyIA2Of_IKZVeL5_1PqqrQ0,228
|
39
|
+
fxn/types/tag.py,sha256=hWzSDCo8VjRHjS5ZLuFi3xVo8cuCNaNeULQ2mHEuwzM,707
|
40
|
+
fxn/types/user.py,sha256=_hc1YQh0WydniAurywA70EDs4VCY5rnGRYSiRc97Ab0,150
|
41
|
+
fxn-0.0.37.dist-info/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
42
|
+
fxn-0.0.37.dist-info/METADATA,sha256=3-Jhz_avkErQguXTzBGED3_slasVTUI2aH48tFrjl_Y,16068
|
43
|
+
fxn-0.0.37.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
|
44
|
+
fxn-0.0.37.dist-info/entry_points.txt,sha256=O_AwD5dYaeB-YT1F9hPAPuDYCkw_W0tdNGYbc5RVR2k,45
|
45
|
+
fxn-0.0.37.dist-info/top_level.txt,sha256=1ULIEGrnMlhId8nYAkjmRn9g3KEFuHKboq193SEKQkA,4
|
46
|
+
fxn-0.0.37.dist-info/RECORD,,
|
fxn/libs/linux/__init__.py
DELETED
fxn/libs/macos/Function.dylib
DELETED
Binary file
|
fxn/libs/macos/__init__.py
DELETED
fxn/libs/windows/Function.dll
DELETED
Binary file
|
fxn/libs/windows/__init__.py
DELETED
fxn/magic.py
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Function
|
3
|
-
# Copyright © 2024 NatML Inc. All Rights Reserved.
|
4
|
-
#
|
5
|
-
|
6
|
-
from IPython.core.interactiveshell import InteractiveShell
|
7
|
-
from IPython.core.magic import Magics, magics_class, line_magic
|
8
|
-
from typing import List
|
9
|
-
|
10
|
-
@magics_class
|
11
|
-
class FunctionMagics (Magics):
|
12
|
-
|
13
|
-
@line_magic
|
14
|
-
def fxn (self, line: str):
|
15
|
-
COMMANDS = {
|
16
|
-
"python": self.__python,
|
17
|
-
"image": self.__image,
|
18
|
-
}
|
19
|
-
args = line.split(" ")
|
20
|
-
command = COMMANDS.get(args[0], None)
|
21
|
-
if command is not None:
|
22
|
-
command(args[1:])
|
23
|
-
else:
|
24
|
-
raise RuntimeError(f"Unrecognized Function command: {args[0]}")
|
25
|
-
|
26
|
-
def __python (self, args: List[str]):
|
27
|
-
version = args[0]
|
28
|
-
print(f"Predictor will use Python {version} when running on Function")
|
29
|
-
|
30
|
-
def __image (self, args: List[str]):
|
31
|
-
image = args[0]
|
32
|
-
print(f"Predictor will use base image {image} when running on Function")
|
33
|
-
|
34
|
-
def load_ipython_extension (ipython: InteractiveShell):
|
35
|
-
ipython.register_magics(FunctionMagics)
|
fxn/services/environment.py
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Function
|
3
|
-
# Copyright © 2024 NatML Inc. All Rights Reserved.
|
4
|
-
#
|
5
|
-
|
6
|
-
from typing import List
|
7
|
-
|
8
|
-
from ..graph import GraphClient
|
9
|
-
from ..types import EnvironmentVariable
|
10
|
-
|
11
|
-
class EnvironmentVariableService:
|
12
|
-
|
13
|
-
def __init__ (self, client: GraphClient) -> None:
|
14
|
-
self.client = client
|
15
|
-
self.__value = "xxxxxxxx"
|
16
|
-
|
17
|
-
def list (self, organization: str=None) -> List[EnvironmentVariable]:
|
18
|
-
"""
|
19
|
-
List the current user's environment variables.
|
20
|
-
|
21
|
-
Note that the variable values can only viewed at https://fxn.ai.
|
22
|
-
|
23
|
-
Parameters:
|
24
|
-
organization (str): Organization username.
|
25
|
-
|
26
|
-
Returns:
|
27
|
-
list: User environment variables.
|
28
|
-
"""
|
29
|
-
# Query
|
30
|
-
response = self.client.query(f"""
|
31
|
-
query ($input: UserInput) {{
|
32
|
-
user (input: $input) {{
|
33
|
-
... on User {{
|
34
|
-
environmentVariables {{
|
35
|
-
{ENVIRONMENT_VARIABLE_FIELDS}
|
36
|
-
}}
|
37
|
-
}}
|
38
|
-
... on Organization {{
|
39
|
-
environmentVariables {{
|
40
|
-
{ENVIRONMENT_VARIABLE_FIELDS}
|
41
|
-
}}
|
42
|
-
}}
|
43
|
-
}}
|
44
|
-
}}
|
45
|
-
""",
|
46
|
-
{ "input": { "username": organization } if organization is not None else None }
|
47
|
-
)
|
48
|
-
# Create envs
|
49
|
-
assert response["user"] is not None, "Failed to list environment variables because user could not be found. Check that you are authenticated."
|
50
|
-
environments = response["user"]["environmentVariables"]
|
51
|
-
environments = [EnvironmentVariable(**env, value=self.__value) for env in environments]
|
52
|
-
# Return
|
53
|
-
return environments
|
54
|
-
|
55
|
-
def create (self, name: str, value: str, organization: str=None) -> EnvironmentVariable:
|
56
|
-
"""
|
57
|
-
Create an environment variable.
|
58
|
-
|
59
|
-
This environment variable will apply to all predictors you create.
|
60
|
-
|
61
|
-
Parameters:
|
62
|
-
name (str): Variable name.
|
63
|
-
value (str): Variable value.
|
64
|
-
organization (str): Organization username. Use this for organization environment variables.
|
65
|
-
|
66
|
-
Returns:
|
67
|
-
EnvironmentVariable: Created environment variable.
|
68
|
-
"""
|
69
|
-
# Query
|
70
|
-
response = self.client.query(f"""
|
71
|
-
mutation ($input: CreateEnvironmentVariableInput!) {{
|
72
|
-
environment: createEnvironmentVariable (input: $input) {{
|
73
|
-
{ENVIRONMENT_VARIABLE_FIELDS}
|
74
|
-
}}
|
75
|
-
}}
|
76
|
-
""",
|
77
|
-
{ "input": { "name": name, "value": value, "organization": organization } }
|
78
|
-
)
|
79
|
-
# Create env
|
80
|
-
environment = response["environment"]
|
81
|
-
environment = EnvironmentVariable(**environment, value=self.__value)
|
82
|
-
# Return
|
83
|
-
return environment
|
84
|
-
|
85
|
-
def delete (self, name: str, organization: str=None) -> bool:
|
86
|
-
"""
|
87
|
-
Delete an environment variable.
|
88
|
-
|
89
|
-
Parameters:
|
90
|
-
name (str): Variable name.
|
91
|
-
organization (str): Organization username. Use this for organization environment variables.
|
92
|
-
access_key (str): Function access key.
|
93
|
-
|
94
|
-
Returns:
|
95
|
-
bool: Whether the environment variable was successfully deleted.
|
96
|
-
"""
|
97
|
-
# Query
|
98
|
-
response = self.client.query(f"""
|
99
|
-
mutation ($input: DeleteEnvironmentVariableInput!) {{
|
100
|
-
result: deleteEnvironmentVariable (input: $input)
|
101
|
-
}}
|
102
|
-
""",
|
103
|
-
{ "input": { "name": name, "organization": organization } }
|
104
|
-
)
|
105
|
-
# Return
|
106
|
-
return response["result"]
|
107
|
-
|
108
|
-
|
109
|
-
ENVIRONMENT_VARIABLE_FIELDS = f"""
|
110
|
-
name
|
111
|
-
"""
|