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
- Share state between a local Data App and a Data App on 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 peliqanUpgrade to latest version
$ pip install peliqan --upgradeUsage
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_urlthat points to a specific Peliqan environment. If no value is provided, the client will look for thePELIQAN_URLenvironment 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_urlparameter 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 streamlitBundler
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:
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 and “scheduled” or “background” otherwise.
Click here for more info on run modes (RUN_CONTEXT).
Example Data App that can run both on Peliqan and outside of Peliqan (e.g. locally on your computer):
Run this script locally on your computer as follows:
- Background mode:
python script.py - Interactive mode (Streamlit):
streamlit run script.py.
Share state between a local Data App and a Data App on Peliqan
Example code to share state with an app on Peliqan:
Note: when running a Data App outside of Peliqan, by default pq.get_state() and pq.set_state(state)will read and write the state locally in a temporary file. The above code however, shares the state with a Data App running on Peliqan. Make sure that PELIQAN_INTERFACE_ID is set as a local environment variable, with the id of the Data App on 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: