Skip to main content

JSPython - Run offline with NodeJS

You can use JSPython CLI and Worksheets CLI to run your projects outside Worksheets Data Studio environment. This will allow you to

  • Automate / Run JSPY code outside of WORKSHEETS Data Studio
  • Store source code in a Source Contro repository

Steps to follow​

Before you start, please make sure you have installed:​

Use worksheets-cli to pull your project​

Create a folder where you want your ource code to be

  • run command: worksheets-cli config --baseUrl=https://api.worksheet.systems
  • run command: worksheets-cli config --app=PROJECT_OWNER/PROJECT_NAME
  • run command: worksheets-cli pull this command will ask you username and password. Please provide the same username/password as you use it in Worksheet Systems

Done, you should see source code in the .\src folder

Setup npm project​

If you haven't done it yet, then, you have to create package.json file and install all dependencies

npm init

After you have package.json installed, then you should install dependencies. All those dependecies are optional. It depends what your scripts are doing. The following list, is essential libraries used in WORKSHEETS Data Studio

npm install axios --save
npm install datapipe-js --save
npm install sql-data-api --save

Run jspy file​

jspython --srcRoot=src --file=run_batch.jspy

You have to define srcRoot parameter

Create app.js​

app.js file is an entry file, that jspython-cli is running before it will execute jspython script. So, it is a perfect place where you can provide configuration for your app or define some of the functions.

Here is an example of app.js file, that configures sql-data-api


const api = require('sql-data-api');

// not required to do. Only for a `local` runs
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'

api.setBaseUrl("https://api.worksheet.systems")
api.setUserAccessToken("***")

async function initialize() {
// just in case, you don't want to use user access token, you can pass you Worksheet Systems' username/password
// await api.authenticate("username", "password")
}

module.exports = {
// jspyhon-cli will call it prior to executing `jspython` script.
// it is great place to do some authentication or initializations
_initAsync: async () => await initialize(),

// expose a function to JSPython
// You can call it in any of your jspy files
testFunc1: ()=> {
return "Hello From JavaScript"
}
}