Skip to content

Streamlit integration

This page documents the API for using the Streamlit library with PyKX.

PyKXConnection

Bases: BaseConnection[SyncQConnection]

reset

reset(**kwargs)

Close and reopen an existing Streamlit connection.

Example:

Open a connection to a locally running process on port 5050 and check if it is a healthy connection. If it is not, reset the connection.

>>> import streamlit as st
>>> import pykx as kx
>>> conn = st.connection('pykx', type=kx.streamlit.PyKXConnection,
...                      host = 'localhost', port = 5050)
>>> if not conn.is_healthy():
...     conn.reset()
>>>

is_healthy

is_healthy()

Check if an existing streamlit connection is 'healthy' and available for query.

Returns:

Type Description
bool

A boolean indicating if the connection being used is in a 'healthy' state

>>> import streamlit as st
>>> import pykx as kx
>>> conn = st.connection('pykx', type=kx.streamlit.PyKXConnection,
...                      host = 'localhost', port = 5050)
>>> conn.is_healthy()
True

query

query(query, *args, format='q', **kwargs)

Query the connected q process over IPC.

Parameters:

Name Type Description Default
query str

A q expression to be evaluated. This must be valid q, qSQL or SQL in the KX Insights style.

required
*args

Arguments to the query. Each argument will be converted into a pykx.K object. Up to 8 arguments can be provided (maximum supported by q functions).

()
format

Description of query format for internal pre-processing before the query is sent to the server. This must be one of 'q', 'qsql' or 'sql'.

'q'

Raises:

Type Description
RuntimeError

A closed IPC connection was used.

QError

Query timed out, may be raised if the time taken to make or receive a query goes over the timeout limit.

TypeError

Too many arguments were provided - q queries cannot have more than 8 parameters.

ValueError

Attempted to send a Python function over IPC.

Examples:

Open a connection to a locally running q process on port 5050 and query using 'q' format.

>>> import streamlit as st
>>> import pykx as kx
>>> conn = st.connection('pykx', type=kx.streamlit.PyKXConnection,
...                      host = 'localhost', port = 5050)
>>> df = conn.query('select from tab').pd()
>>> st.dataframe(df)

Open a connection to a locally running q process on port 5050 and query using 'qsql' format.

>>> import streamlit as st
>>> import pykx as kx
>>> conn = st.connection('pykx', type=kx.streamlit.PyKXConnection,
...                      host = 'localhost', port = 5050)
>>> df = conn.query('tab', where=kx.Column('x')>0.5, format='qsql').pd()
>>> st.dataframe(df)

Connect to a locally running q process on port 5050 and query using 'sql' format.

>>> import streamlit as st
>>> import pykx as kx
>>> conn = st.connection('pykx', type=kx.streamlit.PyKXConnection,
...                      host = 'localhost', port = 5050)
>>> df = conn.query('select * from tab where x>0.5', format='sql').pd()
>>> st.dataframe(df)