mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-23 06:27:57 +00:00
* docs: jira * docs: formatting + Client Credentials grant type * docs: connection string pgsql * docs: parameterized queries mysql * docs: parameterized queries in PostgreSQL * docs: update mysql example * docs: TJDB sql editor * docs: add metadata to REST API * docs: add, update postgresql media * docs: add metadata to graphql * docs: update parameterized queries * docs: add parameterized queries for mssql * docs: add SSL Cert to mysql * docs: TJDB SQL restricted commands * docs: update JIRA token location * docs: update delete issue example * docs: update find user by query example * docs: remove session id from get assignable users * docs: use correct image for get issues for board * docs: update create issue example * docs: update delete issue media * docs: update assignable users media * docs: update examples * docs: update key desc * docs: v2.68.0-Beta
3.1 KiB
3.1 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 them in the application.
:::caution Unsupported modules Modules with C/C++ extensions needing system libraries won't work in Pyodide, as it runs in a web browser without system library access. Pyodide, based on WebAssembly-compiled Python, also doesn't support certain system calls. :::
- Start by creating a new application in ToolJet.
- From the Query Panel, add a new RunPy query - it will be named runpy1 by default.
- Use micropip to install packages like Pandas and NumPy. Run the query to complete installation.
import micropip
await micropip.install('pandas')
await micropip.install('numpy')
- Enable
Run this query on application load?to make these packages available every time the application loads.
Generating Random Numbers with NumPy
- Create a RunPy query using NumPy's random module to generate random numbers.
from numpy import random
x = random.binomial(n=10, p=0.5, size=10)
print(x)
You can check the output on the browser's console.
Parse CSV data
- Create a RunPy query to parse CSV data using
StringIO,csv, andPandasmodule.
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)
- Add a File Picker component on the canvas
- Select
On File Loadedas the Event and Run Query as the Action. - Select the query we just created as the Query.
- Finally, load a csv file on the File Picker component, Run related RunPy query and check the output on the browser console.