ToolJet/docs/versioned_docs/version-2.18.0/how-to/import-external-lib-py.md
Shubhendra Singh Chauhan 9f2ff94a12
[docs] platform 5.x (#7427)
* whtie label revamp

* minor changes

* updated beta info in copilot docs

* renamed gds to ds in overview doc of v2.15 onwards

* updated multienv: renamed gds to ds, updated screenshot

* updated multienv: app state description

* updated superadmin wrt new licensing updates

* licensing update: free trial

* updates in licensing

* changes after review

* [docs]updated restapi with bearer auth

* Update kubernetes-aks.md

* Update openshift.md

* Update ecs.md

* Update ecs.md

* Update kubernetes-gke.md

* Update kubernetes.md

* Update docker.md

* Update docker.md

* Update ecs.md

* Update google-cloud-run.md

* Update kubernetes-aks.md

* Update kubernetes-gke.md

* Update kubernetes.md

* Update openshift.md

* Update kubernetes-gke.md

* Update kubernetes-aks.md

* fixed ecs, removed heroku from 2.15 onwards

* updated digitalocean doc

* licensing doc changes and location

* Update digitalocean.md

* Update digitalocean.md

* added v2.18.0

---------

Co-authored-by: Adish M <44204658+adishM98@users.noreply.github.com>
2023-09-27 12:24:39 +05:30

3.6 KiB

id title
import-external-libraries-using-runpy Import external libraries using RunPy

ToolJet allows you to utilize python packages in your app by importing them using the RunPy query. In this how-to guide, we will import a few packages and use it in the application.

:::caution Unsupported modules The modules that are not currently supported in Pyodide are those that have C or C++ extensions that rely on system libraries. These modules cannot be used in Pyodide because it runs in a web browser, which does not have access to the underlying system libraries that the C or C++ extensions rely on. Additionally, Pyodide uses a version of Python that has been compiled to WebAssembly, which does not support the same system calls as a regular version of Python. Therefore, any module that requires access to system libraries or system calls will not work in Pyodide. :::

  • Create a new application and then create a new RunPy query from the query panel.

    Import external libraries using RunPy
  • Let's write some code for importing packages. We will first import the micropip which is a package installer for Python and then we will install the Pandas and NumPy using micropip. Run the query to install the packages.

    import micropip
    await micropip.install('pandas')
    await micropip.install('numpy')
    
    Import external libraries using RunPy

:::tip Enable the Run this query on application load? option to make the packages available throughout the application. :::

Examples

Array of random numbers of using NumPy

  • Let's create a RunPy query that will use random module from the NumPy package and the query will generate array of random numbers.

    from numpy import random
    
    x = random.binomial(n=10, p=0.5, size=10)
    
    print(x)
    
    Import external libraries using RunPy

:::info You can check the output on the browser's console. :::

Parse CSV data

  • Let's create a RunPy query that will parse the data from the csv file. In this query we will use StringIO, csv, and Pandas module.

    from io import StringIO
    import csv
    import pandas as pd
    
    scsv = components.filepicker1.file[0].content
    
    f = StringIO(scsv)
    reader = csv.reader(f, delimiter=',')
    
    df = pd.DataFrame(reader)
    
    print(df.info())
    print(df)
    
    Import external libraries using RunPy
  • Add a file picker component on the canvas and set a event handler for On file loaded event to Run Query that we created for parsing the data.

    Import external libraries using RunPy
  • Finally, let's load a csv file on the file picker and check the output by the RunPy query on the browser console.

    Import external libraries using RunPy