×
‹
›
Logo
  • Go to Home
Book a demo

Search

Basics

Advanced

For developers

Connectors

Contact support

Helpdesk portal

Peliqan documentation

Local development

You can write Python scripts (data apps) directly inside Peliqan using Peliqan’s built-in IDE, or you can develop locally on your computer and then deploy to Peliqan.

  • Peliqan pip module
  • Install
  • Upgrade to latest version
  • Usage
  • Peliqan class arguments
  • Environment variables (optional)
  • Useful Links
  • Streamlit apps
  • Bundler
  • Creating data apps that can run both locally and inside of Peliqan
  • Automated deploys (CI/CD)
  • Local deploy script
  • Deploy using Peliqan’s REST API

Peliqan pip module

A Python module to connect to a Peliqan environment from a Python script running anywhere outside of the Peliqan environment. This module is a wrapper for the public Peliqan REST APIs.

Install

$ pip install peliqan

Upgrade to latest version

$ pip install peliqan --upgrade

Usage

Peliqan class arguments

The Peliqan class takes two arguments:

  • jwt (required): This is the JWT token used to authenticate requests from the client to the server. In Peliqan, see Admin > Security settings > API token.
  • backend_url (optional): This is the instance_url that points to a specific Peliqan environment. If no value is provided, the client will look for the PELIQAN_URL environment variable. If it is not set, then the value defaults to https://app.eu.peliqan.io/.

More info on the Peliqan environment URL and JWT token here.

Environment variables (optional)

  • PELIQAN_URL: If this variable is set, it is not needed to set the backend_url parameter while instantiating the client.

Useful Links

See here to learn more about building data apps.

Streamlit apps

If you want to run interactive Streamlit apps locally, install Streamlit first:

$ pip install streamlit

Bundler

Data apps in Peliqan are single file Python scripts. You can use the Peliqan bundler to combine a multi-file Python script (e.g. a multi-file Streamlit app) into a single file that can be deployed to Peliqan.

☝

Note that the single file script must be tested. In some cases, changes to the source code are required to make the code compatible with the bundler.

Download the bundler:

bundler.py18.5 KiB

Usage:

python bundler.py test-project/main.py

Creating data apps that can run both locally and inside of Peliqan

Inside Peliqan, the Peliqan module is automatically imported as pq and Streamlit is automatically imported as st. The constant RUN_CONTEXT is always set, e.g. with value “interactive” when the data app runs in interactive mode.

Click here for more info on run modes (RUN_CONTEXT).

Example background data app that can run both locally (outside of Peliqan) and within Peliqan:

Example interactive data app (Streamlit app) that can run both locally (outside of Peliqan) and within Peliqan:

Automated deploys (CI/CD)

You can automate the deployment of Python data apps to Peliqan by using Peliqan’s REST API as part of your CI/CD deployment pipeline - e.g. using Github actions - or by using a Python deploy script that you run locally to push data app updates to Peliqan.

Local deploy script

Deploy using Peliqan’s REST API

Data apps are called “interfaces” in the Peliqan REST API.

Relevant API endpoints:

  • Create a data app
  • Update a data app
from peliqan import Peliqan

jwt = "MY_JWT_TOKEN"             # see Admin > Security settings > API token
backend_url = "MY_PELIQAN_URL"   # optional, default: https://app.eu.peliqan.io/

pq = Peliqan(jwt, backend_url)

# Example usage
dbconn = pq.dbconnect('dw_xxx') # Enter the name of your Peliqan data warehouse
data = dbconn.fetch('dw_xxx', 'schema_name', 'table_name')
print(data)

df = dbconn.fetch('db_name', 'schema_name', 'table_name', df=True)
print(df)
import os

if 'RUN_CONTEXT' not in globals(): # Running outside of Peliqan
    from peliqan import Peliqan
    api_key = os.getenv("PELIQAN_API_KEY")
    if not api_key:
        print("PELIQAN_API_KEY environment variable is not set.")
        exit()
    pq = Peliqan(api_key)
    
    # The constant RUN_CONTEXT is set when running inside Peliqan
    RUN_CONTEXT = "background"

# Your data app code goes here
import os

if 'RUN_CONTEXT' not in globals(): # Running outside of Peliqan
    from peliqan import Peliqan
    import streamlit as st
    api_key = os.getenv("PELIQAN_API_KEY")
    if not api_key:
        st.error("PELIQAN_API_KEY environment variable is not set.")
        st.stop()
    pq = Peliqan(api_key)
    
    # The constant RUN_CONTEXT is set when running inside Peliqan
    RUN_CONTEXT = "interactive"

# Your data app code goes here
from peliqan import Peliqan

jwt = "..." # Get from env variable
pq = Peliqan(jwt)

group_id = 123  # See Peliqan > Admin > Groups

with open("my_data_app.py", "r") as f:
    raw_script = f.read()

# Update an existing data app
result = pq.update_script(script_id = 1234, raw_script = raw_script)
print(result)

# Deploy a new data app
result = pq.add_script(
        group_id = group_id, 
        group_name = 'Production data', 
        raw_script = raw_script, 
        name = 'My newly deployed data app'
    )
print(result)