Skip to content

Commit cb4918d

Browse files
Merge branch 'feat/update-class-dashboards/SDKPY-146' into feat/update-class-devices/SDKPY-147
2 parents 0e51264 + ad2507f commit cb4918d

10 files changed

Lines changed: 75 additions & 58 deletions

File tree

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"ignoretz",
99
"PYPI",
1010
"pytest",
11-
"serie_number"
11+
"serie_number",
12+
"Tago"
1213
]
1314
}

docs/source/Resources/Account/index.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ See: `Login to Account <https://api.docs.tago.io/#3196249b-4aef-46ff-b5c3-f103b6
271271
print(login_result) # {'type': 'user', 'id': '...', 'profiles': [...]}
272272
273273
274-
==============
274+
===============
275275
passwordRecover
276-
==============
276+
===============
277277

278278
Send password recovery email to the specified address. This is a static method that doesn't require authentication.
279279

@@ -385,9 +385,9 @@ Confirm account creation using the token sent via email. This is a static method
385385
print(result) # Account confirmed successfully
386386
387387
388-
==================
388+
===================
389389
requestLoginPINCode
390-
==================
390+
===================
391391

392392
Request the PIN Code for a given OTP Type (authenticator, sms, or email). This is a static method that doesn't require authentication.
393393

@@ -472,5 +472,5 @@ Decline a team member invitation to become a profile's team member. This is a st
472472
473473
.. toctree::
474474

475-
Account_Type
475+
Account_type
476476
../../regions

docs/source/Resources/Run/Run_Types.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ UserInfo
294294
| **options**: object
295295
| **tags**: list[:ref:`TagsObj`]
296296
297-
.. _LoginResponse:
297+
.. _LoginResponseRunUser:
298298

299299
LoginResponse
300300
-------------

docs/source/Resources/Run/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Log in as a specific user in the TagoRUN service.
154154
155155
**Returns:**
156156

157-
| **result**: :ref:`LoginResponse`
157+
| **result**: :ref:`LoginResponseRunUser`
158158
| Login response.
159159
160160

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "tagoio-sdk"
7-
version = "5.0.4"
7+
version = "5.1.0"
88
description = "Official Python SDK for TagoIO"
99
authors = [{name = "TagoIO Inc.", email = "contact@tago.io"}]
1010
license = {text = "Apache-2.0"}

src/tagoio_sdk/modules/Analysis/Analysis.py

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -44,47 +44,69 @@ def my_analysis(context, scope):
4444
# Your analysis logic here
4545
print("Processing data...")
4646
47-
analysis = Analysis(my_analysis, {"token": "your-analysis-token"})
47+
Analysis.use(analysis=my_analysis, params={"token": "your-analysis-token"})
4848
```
4949
50-
Example: Environment variables
50+
Example: Analysis with EU region
5151
```python
52+
from tagoio_sdk import Analysis
53+
5254
def my_analysis(context, scope):
53-
env = context.environment
54-
api_key = next((e["value"] for e in env if e["key"] == "API_KEY"), None)
55+
context.log("Running in EU region")
56+
print("Environment:", context.environment)
57+
58+
# Using Analysis.use() method
59+
Analysis.use(analysis=my_analysis, params={"token": "your-analysis-token", "region": "eu-w1"})
60+
```
5561
56-
analysis = Analysis(my_analysis)
62+
Example: Analysis with Tago Deploy
63+
```python
64+
from tagoio_sdk import Analysis
65+
66+
def my_analysis(context, scope):
67+
context.log("Running in TDeploy")
68+
print("Scope:", scope)
69+
70+
# Tago Deploy requires a dictionary with tdeploy ID
71+
Analysis.use(
72+
analysis=my_analysis,
73+
params={
74+
"token": "your-analysis-token",
75+
"region": {"tdeploy": "your-tdeploy-id"}
76+
}
77+
)
5778
```
5879
59-
Example: Manual start control
80+
Example: Environment variables
6081
```python
61-
analysis = Analysis(my_analysis, {
62-
"token": "token",
63-
"autostart": False
64-
})
82+
def my_analysis(context, scope):
83+
env = context.environment
84+
api_key = next((e["value"] for e in env if e["key"] == "API_KEY"), None)
6585
66-
# Start analysis manually
67-
analysis.start()
86+
Analysis.use(analysis=my_analysis, params={"token": "your-analysis-token"})
6887
```
6988
"""
7089

71-
def __init__(self, analysis: AnalysisFunction, params: Optional[AnalysisConstructorParams] = None):
90+
def __init__(self, params: Optional[AnalysisConstructorParams] = None):
7291
if params is None:
7392
params = {"token": "unknown"}
7493

7594
super().__init__(params)
76-
self.analysis = analysis
95+
self.params = params
96+
self._running = True
7797

78-
if params.get("autostart"):
79-
self.start()
98+
def init(self, analysis: AnalysisFunction):
99+
self.analysis = analysis
80100

81-
def start(self) -> None:
82-
if self.started:
83-
return
101+
if not os.environ.get("T_ANALYSIS_TOKEN") and self.params.get("token"):
102+
os.environ["T_ANALYSIS_TOKEN"] = self.params.get("token")
84103

85-
self.started = True
104+
# Configure runtime region
105+
runtimeRegion = getRegionObj(self.params["region"]) if self.params.get("region") else None
106+
if runtimeRegion:
107+
setRuntimeRegion(runtimeRegion)
86108

87-
if not os.environ.get("T_ANALYSIS_CONTEXT"):
109+
if T_ANALYSIS_CONTEXT is None:
88110
self._localRuntime()
89111
else:
90112
self._runOnTagoIO()
@@ -93,13 +115,13 @@ def _runOnTagoIO(self) -> None:
93115
if not self.analysis or not callable(self.analysis):
94116
raise TypeError("Invalid analysis function")
95117

96-
# Create context object
97-
context = {
98-
"log": print,
99-
"token": os.environ.get("T_ANALYSIS_TOKEN", ""),
100-
"environment": JSONParseSafe(os.environ.get("T_ANALYSIS_ENV", "[]"), []),
101-
"analysis_id": os.environ.get("T_ANALYSIS_ID", ""),
102-
}
118+
def context():
119+
pass
120+
121+
context.log = print
122+
context.token = os.environ.get("T_ANALYSIS_TOKEN", "")
123+
context.analysis_id = os.environ.get("T_ANALYSIS_ID", "")
124+
context.environment = JSONParseSafe(os.environ.get("T_ANALYSIS_ENV", "[]"), [])
103125

104126
data = JSONParseSafe(os.environ.get("T_ANALYSIS_DATA", "[]"), [])
105127

@@ -145,12 +167,13 @@ def log(*args: Any) -> None:
145167
except Exception as e:
146168
print(f"Console error: {e}", file=sys.stderr)
147169

148-
context = {
149-
"log": log,
150-
"token": token,
151-
"environment": environment,
152-
"analysis_id": analysisID,
153-
}
170+
def context():
171+
pass
172+
173+
context.log = log
174+
context.token = token
175+
context.environment = environment
176+
context.analysis_id = analysisID
154177

155178
# Execute analysis function
156179
if inspect.iscoroutinefunction(self.analysis):
@@ -177,7 +200,7 @@ def _localRuntime(self) -> None:
177200
analysis = None
178201

179202
if not analysis:
180-
print("¬ Error :: Analysis not found or not active.", file=sys.stderr)
203+
print("¬ Error :: Analysis not found or not active or invalid analysis token.", file=sys.stderr)
181204
return
182205

183206
if analysis.get("run_on") != "external":
@@ -217,7 +240,7 @@ def _localRuntime(self) -> None:
217240
payload.get("environment", []),
218241
payload.get("data", []),
219242
payload.get("analysis_id", ""),
220-
payload.get("token", self.params.get("token", "")),
243+
self.token,
221244
)
222245
except Exception as e:
223246
print(f"¬ Error processing event: {e}", file=sys.stderr)
@@ -253,12 +276,4 @@ def my_analysis(context, scope):
253276
if params is None:
254277
params = {"token": "unknown"}
255278

256-
if not os.environ.get("T_ANALYSIS_TOKEN") and params.get("token"):
257-
os.environ["T_ANALYSIS_TOKEN"] = params["token"]
258-
259-
# Configure runtime region
260-
runtimeRegion = params.get("region") if getRegionObj(params["region"]) else None
261-
if runtimeRegion:
262-
setRuntimeRegion(runtimeRegion)
263-
264-
return Analysis(analysis, params)
279+
return Analysis(params).init(analysis)

src/tagoio_sdk/modules/Analysis/Analysis_Type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class AnalysisConstructorParams(TypedDict, total=False):
4545
AnalysisID = str
4646

4747

48-
class TagoContext(TypedDict):
48+
class TagoContext:
4949
"""
5050
TagoIO Analysis Context interface.
5151
As current version of the SDK doesn't provide the full TagoContext interface.

src/tagoio_sdk/modules/Resources/Account.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def edit(self, accountObj: Dict) -> str:
5656
```python
5757
resources = Resources()
5858
result = resources.account.edit({
59+
"id": "account-id"
5960
"name": "Updated Account Name",
6061
"timezone": "America/New_York",
6162
"company": "My Company"

src/tagoio_sdk/modules/Resources/Analyses.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,10 @@ def listSnippets(self, runtime: SnippetRuntime) -> SnippetsListResponse:
343343
@example:
344344
```python
345345
resources = Resources()
346-
deno_snippets = resources.analyses.listSnippets("deno-rt2025")
346+
python_snippets = resources.analyses.listSnippets("python-rt2025")
347347
348348
# Print all snippet titles
349-
for snippet in deno_snippets["snippets"]:
349+
for snippet in python_snippets["snippets"]:
350350
print(f"{snippet['title']}: {snippet['description']}")
351351
```
352352

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)