northgravity 0.1.14.dev834026__tar.gz → 0.2.0__tar.gz

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.
Files changed (32) hide show
  1. {northgravity-0.1.14.dev834026/northgravity.egg-info → northgravity-0.2.0}/PKG-INFO +270 -46
  2. northgravity-0.1.14.dev834026/PKG-INFO → northgravity-0.2.0/README.md +257 -60
  3. northgravity-0.2.0/northgravity/Authenticator.py +70 -0
  4. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/northgravity/DatalakeHandler.py +66 -2
  5. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/northgravity/HTTPCalller.py +39 -13
  6. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/northgravity/StatusHandler.py +2 -2
  7. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/northgravity/Timeseries.py +2 -2
  8. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/northgravity/__init__.py +1 -1
  9. northgravity-0.2.0/northgravity/constants.py +12 -0
  10. northgravity-0.2.0/northgravity/task/__init__.py +5 -0
  11. northgravity-0.2.0/northgravity/task/base.py +42 -0
  12. northgravity-0.2.0/northgravity/task/files.py +15 -0
  13. northgravity-0.2.0/northgravity/task/inputs.py +69 -0
  14. northgravity-0.2.0/northgravity/task/local.py +91 -0
  15. northgravity-0.2.0/northgravity/task/logs.py +39 -0
  16. northgravity-0.2.0/northgravity/task/outputs.py +126 -0
  17. northgravity-0.2.0/northgravity/task/params.py +247 -0
  18. northgravity-0.2.0/northgravity/task/platform_api.py +89 -0
  19. northgravity-0.2.0/northgravity/task/runner.py +114 -0
  20. northgravity-0.2.0/northgravity/task/status.py +25 -0
  21. northgravity-0.1.14.dev834026/README.md → northgravity-0.2.0/northgravity.egg-info/PKG-INFO +284 -44
  22. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/northgravity.egg-info/SOURCES.txt +12 -1
  23. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/northgravity.egg-info/requires.txt +1 -0
  24. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/setup.cfg +1 -1
  25. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/setup.py +3 -2
  26. northgravity-0.1.14.dev834026/northgravity/Authenticator.py +0 -37
  27. northgravity-0.1.14.dev834026/northgravity/constants.py +0 -4
  28. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/LICENSE +0 -0
  29. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/northgravity/ExceptionHandler.py +0 -0
  30. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/northgravity/TaskHandler.py +0 -0
  31. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/northgravity.egg-info/dependency_links.txt +0 -0
  32. {northgravity-0.1.14.dev834026 → northgravity-0.2.0}/northgravity.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: northgravity
3
- Version: 0.1.14.dev834026
3
+ Version: 0.2.0
4
4
  Summary: Python SDK for NorthGravity platform
5
5
  Home-page: https://www.northgravity.com/
6
6
  Author: NorthGravity
@@ -8,11 +8,22 @@ Author-email: info@northgravity.com
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.6
11
+ Requires-Python: >=3.7
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: requests>=2.27.1
15
15
  Requires-Dist: urllib3>=1.26.9
16
+ Requires-Dist: auth0-python>=4.7.0
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: license-file
24
+ Dynamic: requires-dist
25
+ Dynamic: requires-python
26
+ Dynamic: summary
16
27
 
17
28
  # NORTH GRAVITY PYTHON SDK #
18
29
 
@@ -41,21 +52,20 @@ The scope of the SDK:
41
52
 
42
53
  - **Time Series Handler** - retrieves data directly from the time series database
43
54
 
55
+ - **Task module** - runs a task in a pipeline: parameters, inputs, outputs and statuses, with a command to run the task locally
56
+
44
57
 
45
58
 
46
59
  # How to install and set the package:
47
60
  ## Install
48
61
  ```text
49
- pip3 install northgravity==0.1.14
62
+ pip3 install northgravity==0.2.0
50
63
  ```
51
64
  As the library is available from pip, it can be installed as a specific version within a Python Task from within requirements.txt just by adding:
52
65
  ```text
53
- northgravity==0.1.14
54
- ```
55
- The package relies on the requests library so, in the project, the user must install this library in the requirements.txt file.
56
- ```text
57
- pip3 install requests
66
+ northgravity==0.2.0
58
67
  ```
68
+ pip installs the libraries the SDK needs (requests, urllib3 and auth0-python) together with it. The SDK needs Python 3.7 or newer.
59
69
 
60
70
 
61
71
  ## Environment Variables
@@ -75,6 +85,37 @@ Mandatory environment variables to set:
75
85
  This allows to pass the authentication process and directs users' requests to the North Gravity environment API.
76
86
  Alternatively, instead of the LOGIN and PASSWORD, you may set NG_API_KEY environment variable with an API key generated within the North Gravity platform to enable the authentication process.
77
87
 
88
+
89
+ For SSO only user accounts, it is additionally needed to set the following environment variables for Auth0:
90
+
91
+ - CLIENT_ID
92
+
93
+ - CLIENT_SECRET
94
+
95
+ When using different NG_API_ENDPOINT than the default, also set the following environment variables: DOMAIN, GRANT_TYPE, REALM, SCOPE, AUDIENCE.
96
+
97
+ The full SSO user setup in code would look the folowing:
98
+
99
+ ```python
100
+ import os
101
+ # minimum requirements for the https://api.northgravity.com environment
102
+ os.environ['LOGIN'] = ''
103
+ os.environ['PASSWORD'] = ''
104
+ os.environ['CLIENT_ID'] = ''
105
+ os.environ['CLIENT_SECRET'] = ''
106
+
107
+ # full user setup for other environments
108
+ os.environ['NG_API_ENDPOINT'] = ''
109
+ os.environ['DOMAIN'] = ''
110
+ os.environ['GRANT_TYPE'] = ''
111
+ os.environ['REALM'] = ''
112
+ os.environ['SCOPE'] = ''
113
+ os.environ['AUDIENCE'] = ''
114
+
115
+ import northgravity as ng
116
+ ```
117
+
118
+
78
119
  Other variables may be useful when creating the tasks within the platform:
79
120
 
80
121
  - NG_STATUS_GROUP_NAME → the group on the data lake where the pipeline is located, and is used to display the statuses
@@ -86,6 +127,19 @@ Other variables may be useful when creating the tasks within the platform:
86
127
 
87
128
 
88
129
  --- -
130
+ # Logger
131
+ Please note that the default logging level for this package is `WARNING`. For more verbosity this can be changed to debug or info in following way:
132
+
133
+ ```python
134
+ import logging
135
+ import northgravity as ng
136
+
137
+ logger = logging.getLogger('NG_SDK')
138
+ logger.setLevel(logging.DEBUG)
139
+ ```
140
+
141
+ ---
142
+
89
143
  # Datalake Handler
90
144
  ## How to download or read a file from data lake by its name ?
91
145
  The DatalakeHandler class can be used as follow within a script to download or upload a file:
@@ -125,7 +179,9 @@ The download methods allows to either:
125
179
 
126
180
  Note that by default:
127
181
  - the file is NOT saved locally, but returned as a BytesIO object (streamed from the datalake).
128
- - the argument *dest_file_name=None*, which will save the downloaded file to the root folder with its original name.
182
+ - the argument *dest_file_name=None*, which will save the downloaded file to the current folder with its original name.
183
+
184
+ With *save=True*, *dest_folder_name* saves the file in an existing folder, and *unzip=True* extracts the saved .zip file into the current folder. *unzip* does not work together with *dest_folder_name*.
129
185
 
130
186
 
131
187
 
@@ -163,14 +219,16 @@ The download methods allows to either:
163
219
 
164
220
  Note that by default:
165
221
  - the file is NOT saved locally, but returned as a BytesIO object (streamed from the datalake).
166
- - the argument *dest_file_name=None*, which will save the downloaded file to the root folder with its original name.
222
+ - the argument *dest_file_name=None*, which will save the downloaded file to the current folder with its original name.
223
+
224
+ With *save=True*, *dest_folder_name* saves the file in an existing folder, and *unzip=True* extracts the saved .zip file into the current folder. *unzip* does not work together with *dest_folder_name*.
167
225
 
168
226
 
169
227
 
170
228
 
171
229
 
172
230
  ## How to upload a file to the data lake?
173
- The uploading method will upload to the given group the file at the specified path, and returns its ID on the lake:
231
+ The uploading method will upload to the given group the file at the specified path, and returns its ID and its name on the lake:
174
232
  ```python
175
233
  import northgravity as ng
176
234
 
@@ -178,9 +236,9 @@ import northgravity as ng
178
236
  dh = ng.DatalakeHandler()
179
237
 
180
238
  # upload file to data lake
181
- file_id = dh.upload_file(file='path/local_name.csv',
182
- group_name='My Group',
183
- file_upload_name='name_in_the_datalake.csv')
239
+ file_id, file_name = dh.upload_file(file='path/local_name.csv',
240
+ group_name='My Group',
241
+ file_upload_name='name_in_the_datalake.csv')
184
242
  ```
185
243
  It is possible as well to stream a python object's content directly to the datalake from memory, without having to save the file on the disk.
186
244
 
@@ -197,9 +255,34 @@ dh = ng.DatalakeHandler()
197
255
  fileIO = io.BytesIO(df.to_csv().encode())
198
256
 
199
257
  # upload file to data lake
200
- file_id = dh.upload_file(file=fileIO,
201
- group_name='My Group',
202
- file_upload_name='name_in_the_datalake.csv')
258
+ file_id, file_name = dh.upload_file(file=fileIO,
259
+ group_name='My Group',
260
+ file_upload_name='name_in_the_datalake.csv')
261
+ ```
262
+
263
+ upload_file returns only when the file is stored: it sends the file to S3 and waits until the datalake shows it, checking up to 30 times, every 10 seconds. If the upload fails, it raises an exception.
264
+
265
+ Other arguments of upload_file:
266
+ - *file_type* - the type of the file on the datalake, SOURCE by default. NCSV files are loaded into the Timeseries database.
267
+ - *metadata_field* and *metadata_value* - one metadata field saved with the file. They must be passed together.
268
+ - *partial_update=True* - for NCSV files, updates only the columns present in the file and keeps the other columns of the same symbols and dates. By default, the values of these other columns are removed.
269
+ - *sync=False* - returns right after sending the file, without waiting for the datalake and without checking whether the upload succeeded.
270
+ - *validate_ncsv=True* - for NCSV files with *sync=True*, also waits for the Timeseries validation of the file and raises an exception when it fails.
271
+
272
+ ## How to find a file and read or change its metadata?
273
+ *search_file* returns the files that match the given name, group, type or metadata field, most recent first, in the *items* key. All its arguments are optional, and *size* sets how many files are returned (100 by default). *get_info_from_id* returns the metadata of the file with the given ID in the same format, and *update_file_metadata* sets one metadata field of a file.
274
+
275
+ ```python
276
+ import northgravity as ng
277
+
278
+ dh = ng.DatalakeHandler()
279
+
280
+ found = dh.search_file(file_name='my_file.csv', group_name='My Group', file_type='SOURCE', size=10)
281
+ file_id = found['items'][0]['fid']
282
+
283
+ info = dh.get_info_from_id(file_id)
284
+
285
+ dh.update_file_metadata(file_id, metadata_field='Region', metadata_value='Europe')
203
286
  ```
204
287
  --- -
205
288
  # Timeseries Queries
@@ -243,7 +326,7 @@ The user must provide either group_name or search_for to the method in order to
243
326
 
244
327
 
245
328
  If trying to get the list of symbols from a group that contains more than 1 000 items, the results will be paginated (by default into chunks of 1 000 items).
246
- To navigate in the large results the *get_symbols()* method takes as extra arguments the size of the returned list and the from page:
329
+ To navigate in the large results the *get_symbols()* method takes as extra arguments the size of the returned list and the number of items to skip:
247
330
  ```python
248
331
  import northgravity as ng
249
332
 
@@ -253,11 +336,11 @@ ts = ng.Timeseries()
253
336
  # Get the list of symbols for given group
254
337
  group = 'My Group'
255
338
 
256
- # Get the results into chunks of 200 items for page 5
257
- # meaning the results from the 1000th till the 1200th
258
- group_symbols = ts.get_symbols(group_name=group, _size=200, _from=5)
339
+ # Get the results into chunks of 200 items, skipping the first 1000
340
+ # meaning the results from the 1001st till the 1200th
341
+ group_symbols = ts.get_symbols(group_name=group, _size=200, _from=1000)
259
342
  ```
260
- By default, these parameters are _size=2000 (the maximum limit for the items lengths) and _from=0.
343
+ By default, these parameters are _size=1000 and _from=0. The sum of _from and _size can be at most 10 000.
261
344
 
262
345
 
263
346
  ## How to read data from Timeseries database?
@@ -278,14 +361,14 @@ If an empty list [ ] is passed to the function, it returns all the available col
278
361
  To read all available data for specific symbols and columns with no time frame, no start or end date are passed to the method.
279
362
 
280
363
  Extra settings are as well available to query data:
281
- - Metadata: to either return it in the query of not
282
- - Format: either get a Normalized CSV (NCSV) or a dataframe format
283
- - Timezone: get the timestamps in the timezone of the user's account or get the data in a specific timezone
284
- - Corrections: how to handle corrections to the TimeSeries database (corrections set to 'yes', 'no', 'history' or 'only')
364
+ - Metadata: to either return it in the query or not (*metadata*)
365
+ - Format: either get a Normalized CSV (*output_format='NCSV'*, the default) or a dataframe format (*output_format='PANDAS'*)
366
+ - Timezone: get the timestamps in the timezone of the user's account or get the data in a specific timezone (*timezone*)
367
+ - Corrections: how to handle corrections to the TimeSeries database (*corrections* set to 'yes', 'no', 'history' or 'only'; 'no' by default)
285
368
  - Delta: whether to show by datatimestamp file (delta=False) or insert time (delta=True)
286
369
 
287
370
 
288
- The following code shows an example of how to query the TimseSeries database: :
371
+ The following code shows an example of how to query the TimeSeries database:
289
372
 
290
373
  ```python
291
374
  import northgravity as ng
@@ -444,7 +527,7 @@ fileIO = ts.retrieve_data_as_csv(file_name=None,
444
527
  df = pd.read_csv(fileIO)
445
528
  ```
446
529
 
447
- Note that this configuration can be used with keys wildcards (with *allow_wildacrd=True*) and any other setting.
530
+ Note that this configuration can be used with keys wildcards (with *allow_wildcard=True*) and any other setting.
448
531
 
449
532
 
450
533
  ## How to modify the Time Zone of the data ?
@@ -516,7 +599,7 @@ The queried data comes by default as Normalized CSV format (NCSV), with in this
516
599
  * the values columns,
517
600
  * the metadata columns, if wanted (*metadata=True*)
518
601
 
519
- By setting *NCSV=False* in the retrieval method, the data will be returned as Dataframe format (PANDAS in API docs), as a JSON.
602
+ By setting *output_format='PANDAS'* in the retrieval method, the data will be returned as Dataframe format, as a JSON.
520
603
  The JSON (python dict) has timestamps as keys and a dictionary containing pairs of symbols_columns and their value.
521
604
 
522
605
  ```python
@@ -530,14 +613,14 @@ ts = ng.Timeseries()
530
613
  symbols = {'Key1': "Val1", "Key2": "Val2"}
531
614
  columns = ['Open', 'Close']
532
615
 
533
- # retrieve all available data from group according to keys & columns
534
- # and stream to memory as BytesIO object
616
+ # retrieve all available data from group according to keys & columns
617
+ # and return it as a JSON (python dict)
535
618
  file_json = ts.retrieve_data_as_csv(file_name=None,
536
619
  symbols=symbols,
537
620
  columns=columns,
538
621
  group_name='My Group',
539
622
  metadata=True,
540
- NCSV=False
623
+ output_format='PANDAS'
541
624
  )
542
625
 
543
626
  # read as pandas dataframe
@@ -548,6 +631,23 @@ df = pd.DataFrame(file_json).T
548
631
  Note that the dataframe, created from the JSON containing the data, is then transposed to have timestamps as DatetimeIndex (along rows axis).
549
632
 
550
633
 
634
+ ## How to upload data to the Timeseries database?
635
+ *upload_data* uploads a csv file to the Timeseries database. It reorders the columns as NCSV expects: the key columns first, then the date column renamed to DateTime, then the value columns. The reordered data is written to temp.csv next to the original file, uploaded to the group as an NCSV file and then removed from the disk, so the file on the datalake is called temp.csv. The method returns the ID and the name of the uploaded file.
636
+
637
+ ```python
638
+ import northgravity as ng
639
+
640
+ ts = ng.Timeseries()
641
+
642
+ file_id, file_name = ts.upload_data(file_name='prices.csv',
643
+ symbols_columns=['Key1', 'Key2'],
644
+ date_column='Date',
645
+ group_name='My Group')
646
+ ```
647
+
648
+ *sync* and *validate_ncsv* work the same way as in *upload_file*.
649
+
650
+
551
651
  --- -
552
652
  # Task Handler
553
653
  Users can extend the existing set of tasks on North Gravity platform by executing scripts or notebooks respectively from the Python Runner Task or the Jupyter Runner Task.
@@ -559,7 +659,7 @@ This task then can be used in a pipeline and be able to communicate with other t
559
659
 
560
660
  A task can as well receive inputs directly as a file picked from the datalake, either for a specific file either for the newest available version of a file on the lake, given its name and group.
561
661
 
562
- Whithin a python script, run into either one of the **Python Runner Task**, this is implemented as follow:
662
+ Within a python script run in the **Python Runner Task**, this is implemented as follows:
563
663
 
564
664
  ## Read a Task Input
565
665
  The input file passed to the Task can be:
@@ -588,25 +688,27 @@ file_content = th.download_from_input_parameter(arg_name='Input #2',
588
688
  df = pd.read_csv(file_content)
589
689
  ```
590
690
 
591
- If dest_file_name=None then the file is saved on the disk with its original name from the datalake.
691
+ If dest_file_name=None then the file is saved on the disk with its original name from the datalake. *dest_folder_name* saves the file in an existing folder.
592
692
 
593
693
  ## How to obtain additional file information
594
694
 
595
695
  There is a possibility to retrieve information related to the input parameters using the DatalakeHandler (```dh.get_info_from_id()```) and TaskHandler (``` th.read_task_parameter_value()```) together.
596
696
 
697
+ *read_task_parameter_value* returns the value of the input as text. For a file passed by a previous task, it is a JSON with the id, name and groupName of the file, for example `{"id": "...", "name": "data.csv", "groupName": "My Group"}`. The id from it is passed to *get_info_from_id*:
698
+
597
699
  ```python
598
700
  import northgravity as ng
599
- import pandas as pd
701
+ from ast import literal_eval
600
702
 
601
- # Instantiate TaskHandler class
602
703
  th = ng.TaskHandler()
603
- # Instantiate the Datalake Handler
604
704
  dh = ng.DatalakeHandler()
605
705
 
606
- dh.get_info_from_id(th.read_task_parameter_value('Input #1'))
706
+ input_file = literal_eval(th.read_task_parameter_value('Input #1'))
707
+ info = dh.get_info_from_id(input_file['id'])
708
+ ```
709
+ This can be used to retrieve any metadata associated with the file itself like file name or arrival time (time it was uploaded to the system).
607
710
 
608
- ```
609
- This can be used to retrieve any metadata associated with the file itself like file name or arrival time (time it was uploaded to the system)
711
+ A file picked in the File Picker as its latest version has only a name and a groupName, without an id. *dh.search_file()* finds it by its name and group.
610
712
 
611
713
  ## Set a Task Output
612
714
  The output of the Task can be set :
@@ -645,12 +747,19 @@ th.upload_to_output_parameter(output_name='Output #1',
645
747
  If file_upload_name=None then the saved file will be uploaded with its original name.
646
748
  If the file is streamed directly to the datalake, the file_upload_name argument must be set.
647
749
 
750
+ *upload_to_output_parameter* returns only when the file is stored, the same way as *upload_file*, and only then passes it to the next task. If the output is not connected to another task, the file is still uploaded and a warning is logged. *partial_update* and *sync* work the same way as in *upload_file*.
751
+
752
+ ## Other Task Handler methods
753
+ - *write_task_parameter_value(output_name, value)* - passes any text to the next task through an output, without a file. It raises ValueError when the output is not connected to another task.
754
+ - *get_storage_value(key)* and *set_storage_value(key, value)* - read and write a value in the storage of the pipeline under the given key. *get_storage_value* returns a dictionary with the value in its *value* key.
755
+ - *get_all_tasks_definitions()* - returns the definitions of the tasks the user can access, optionally filtered by *group_name*, *readable_name* (the name shown in the application) or *category*.
756
+
648
757
  --- -
649
758
  # Statuses
650
- Sending status can be used to show in the application what is the progress of the task execution. It allows to use 3 different levels:
651
- - FINISHED (green),
652
- - WARNING (orange),
653
- - ERROR (red).
759
+ Sending status can be used to show in the application what is the progress of the task execution. It allows to use 3 different levels:
760
+ - INFO, with *sh.info()*,
761
+ - WARN, with *sh.warn()*,
762
+ - ERROR, with *sh.error()*.
654
763
 
655
764
  Sending statuses remains optional as the North Gravity platform sends general statuses.
656
765
  Only if user needs to pass some specific information in the status, this is worth using.
@@ -682,6 +791,100 @@ if i>1:
682
791
  raise PythonStepWarnException(message='The value of i is bigger than 1! Stopping pipeline execution.')
683
792
 
684
793
  ```
794
+ --- -
795
+ # Task module
796
+ `northgravity.task` runs a task in the AWS Lambda of a North Gravity pipeline. The task code only says what to do with the data. The SDK reads and checks the parameters from task_params.json, downloads the input files, saves the output files, sends the statuses and returns the result of the job.
797
+
798
+ New task repositories are generated from the python-task-template repository. It already contains the files below, tests with a fake platform, the Dockerfile and the CI configuration. Its GUIDE.md describes every parameter type, inputs, outputs, statuses, local runs and deployment.
799
+
800
+ ## Minimal task
801
+ A task that copies its input file. The parameters in task_params.json:
802
+
803
+ ```json
804
+ "params": [
805
+ {
806
+ "name": "Input File",
807
+ "description": "File to copy",
808
+ "type": "INPUT",
809
+ "valueType": "DATALAKE_FILE",
810
+ "dynamic": true
811
+ },
812
+ {
813
+ "name": "Output Group",
814
+ "description": "Datalake group where the copy is saved",
815
+ "type": "INPUT",
816
+ "valueType": "GROUP",
817
+ "dynamic": false
818
+ },
819
+ {
820
+ "name": "Output File",
821
+ "description": "The copy",
822
+ "type": "OUTPUT",
823
+ "valueType": "DATALAKE_FILE",
824
+ "optional": true,
825
+ "dynamic": true
826
+ }
827
+ ]
828
+ ```
829
+
830
+ The task class in Pycode/Pipeline.py:
831
+
832
+ ```python
833
+ from northgravity.task import BaseTask, TaskContext, TaskFile
834
+
835
+
836
+ class Task(BaseTask):
837
+
838
+ def run(self, params, ctx: TaskContext) -> None:
839
+ source = ctx.inputs.get_file("Input File")
840
+ ctx.status.running("Copying " + source.name)
841
+ ctx.outputs.upload_files("Output File", [TaskFile("copy_" + source.name, source.content)])
842
+ ctx.log.info("Saved copy_%s", source.name)
843
+ ```
844
+
845
+ The Lambda handler in run_task.py:
846
+
847
+ ```python
848
+ from northgravity.task import run_lambda
849
+
850
+ from Pycode.Pipeline import Task
851
+
852
+
853
+ def handler(event, context):
854
+ return run_lambda(event, Task)
855
+ ```
856
+
857
+ What run gets:
858
+ - `params` - the values of the parameters, already checked and converted: NUMBER to int or float, BOOLEAN to bool, DATE to datetime.date, PASSWORD and SECRET to a Secret object that is hidden when printed. A wrong or missing value stops the job before run.
859
+ - `ctx.inputs.get_file(name)` - the file of an input parameter, given by id, by name and group, or passed by the previous task.
860
+ - `ctx.outputs.upload_files(name, files, group=None, file_type=None)` - saves the files in the datalake and, when the output is connected to another task, passes the first file to it. Without the arguments, the group comes from the parameter Output Group and the file type from the parameter Output File Type, otherwise it is SOURCE. The SDK finds these two parameters only by their exact names.
861
+ - `ctx.status.running(message)` and `ctx.status.warn(message)` - statuses shown in the application. The job ends with SUCCESS, with WARN after a warning, or with ERROR when run raises an exception.
862
+ - `ctx.log`, `ctx.job`, `ctx.now`, `ctx.tmp_dir` - the logger of the job, the data of the run, the start time of the job in UTC and a working folder that is removed after the job.
863
+
864
+ ## Run a task locally
865
+ `python -m northgravity.task.local` runs the task from the current folder on your computer against a real North Gravity environment, the same way the Lambda runs it. It reads the event from event.json:
866
+
867
+ ```json
868
+ {
869
+ "Input": [
870
+ {"Name": "NG_API_ENDPOINT", "Value": "<API address of the environment>"},
871
+ {"Name": "Input File", "Value": "{\"name\": \"rates.csv\", \"groupName\": \"My Group\"}"},
872
+ {"Name": "Output Group", "Value": "My Group"}
873
+ ]
874
+ }
875
+ ```
876
+
877
+ - NG_API_ENDPOINT is required, so a local run never calls the production API by accident.
878
+ - Set the credentials in the terminal, as described in Environment Variables: NG_API_KEY, or LOGIN and PASSWORD. Never put them in event.json, because the file is part of the repository. The command refuses an event.json with NG_API_AUTHTOKEN.
879
+
880
+ ```bash
881
+ read -s NG_API_KEY
882
+ export NG_API_KEY
883
+ python -m northgravity.task.local
884
+ ```
885
+
886
+ The command prints the result of the job, for example `{"returnCode": "SUCCESS", "message": "Finished with status SUCCESS"}`. To use another event file, pass its path: `python -m northgravity.task.local other_event.json`.
887
+
685
888
  --- -
686
889
  # Example 1 - OOP
687
890
  To simplify the use of the SDK methods in a script, Python SDK methods can be inherited by the user’s main class.
@@ -723,7 +926,7 @@ class Runner:
723
926
  fileIO = io.BytesIO(df_processed.to_csv().encode())
724
927
 
725
928
  # pass the processed data csv file as the output of the task called Processed Data
726
- self.handler.upload_to_output_parameter(output_name='Processed Dataset', file=fileIO, group_name='Final Group')
929
+ self.handler.upload_to_output_parameter(output_name='Processed Dataset', file=fileIO, group_name='Final Group', file_upload_name='processed_data.csv')
727
930
 
728
931
 
729
932
  def run(self):
@@ -805,6 +1008,27 @@ th.upload_to_output_parameter(output_name='Output #1',
805
1008
  # use file_type='NCSV' to save NCSV-type datasets into Timeseries database
806
1009
  file_type='SOURCE')
807
1010
  ```
1011
+ ---
1012
+ # SSL Verification Bypass
1013
+
1014
+ This package includes a feature designed to bypass SSL certificate verification for HTTP requests, intended for development or testing purposes in trusted environments. Activating this feature allows you to send requests without verifying the SSL certificate of the server you're connecting to, which can be useful when working with self-signed certificates or servers with certificate issues. To use this feature, simply pass the argument `verify_ssl=False` to init function of the component you are using:
1015
+
1016
+ ```python
1017
+ import northgravity as ng
1018
+ import os
1019
+ os.environ['LOGIN'] = ''
1020
+ os.environ['PASSWORD'] = ''
1021
+
1022
+ dh = ng.DatalakeHandler(verify_ssl=False)
1023
+ th = ng.TaskHandler(verify_ssl=False)
1024
+ ts = ng.Timeseries(verify_ssl=False)
1025
+ sh = ng.StatusHandler(verify_ssl=False)
1026
+ ```
1027
+
1028
+ **Warning:** Disabling SSL certificate verification poses a security risk by exposing your application to man-in-the-middle attacks. Therefore, it is strongly recommended to use this feature only in controlled and secure environments, and always ensure SSL verification is enabled in production.
1029
+
1030
+ Further documentation on bypassing SSL verification can be found [here.](https://requests.readthedocs.io/en/latest/user/advanced/)
808
1031
 
1032
+ ---
809
1033
  ## Who do I talk to? ##
810
1034
  * Admin: NorthGravity info@northgravity.com