Skip to main content

Based on react-awesome-query-builder

Check out live demo !

This component allows users to build complex condition trees that can be used to filter a dataframe or build a query.

preview

Install

pip install streamlit-condition-tree

Features

  • Highly configurable
  • Fields can be of type:
    • simple (string, number, bool, date/time/datetime, list)
    • structs (will be displayed in selectbox as tree)
  • Comparison operators can be:
    • binary (== != < > ..)
    • unary (is empty, is null)
    • 'between' (for numbers, dates, times)
    • complex operators like 'proximity'
  • RHS can be:
    • values
    • another fields (of same type)
    • functions (arguments also can be values/fields/funcs)
  • LHS can be field or function
  • Reordering (drag-n-drop) support for rules and groups of rules
  • Export to MongoDb, SQL, JsonLogic, SpEL or ElasticSearch

Basic usage

Filter a dataframe

import pandas as pd
from streamlit_condition_tree import condition_tree, config_from_dataframe

# Initial dataframe
df = pd.DataFrame({
    'First Name': ['Georges', 'Alfred'],
    'Age': [45, 98],
    'Favorite Color': ['Green', 'Red'],
    'Like Tomatoes': [True, False]
})

# Basic field configuration from dataframe
config = config_from_dataframe(df)

# Condition tree
query_string = condition_tree(config)

# Filtered dataframe
df = df.query(query_string)

Build a query

import streamlit as st
from streamlit_condition_tree import condition_tree

# Build a custom configuration
config = {
    'fields': {
        'name': {
            'label': 'Name',
            'type': 'text',
        },
        'qty': {
            'label': 'Age',
            'type': 'number',
            'fieldSettings': {
                'min': 0
            },
        },
        'like_tomatoes': {
            'label': 'Likes tomatoes',
            'type': 'boolean',
        }
    }
}

# Condition tree
return_val = condition_tree(
    config,
    return_type='sql'
)

# Generated SQL
st.write(return_val)

API

Parameters

def condition_tree(
    config: dict,
    return_type: str,
    tree: dict,
    min_height: int,
    placeholder: str,
    key: str
)
  • config: Python dictionary (mostly used to define the fields) that resembles the JSON counterpart of the React component.

A basic configuration can be built from a DataFrame with config_from_dataframe.
For a more advanced configuration, see the component doc and demo.
Note: Javascript functions (ex: validators) are not yet supported.

  • return_type: Format of the returned value :

    • queryString
    • mongodb
    • sql
    • spel
    • elasticSearch
    • jsonLogic

    Default : queryString (can be used to filter a pandas DataFrame using DataFrame.query)

  • tree: Input condition tree (see section below)

    Default : None

  • min_height: Minimum height of the component frame

    Default : 400

  • placeholder: Text displayed when the condition tree is empty

    Default : None

  • key: Fixed identity if you want to change its arguments over time and not have it be re-created.
    Can also be used to access the generated condition tree (see section below).

    Default : None

Export & import a condition tree

When a key is defined for the component, the condition tree generated is accessible through st.session_state[key] as a dictionary.
It can be loaded as an input tree through the tree parameter.

Potential future improvements

  • Javascript support: allow injection of javascript code in the configuration (e.g. validators)

Metadata

Release files for streamlit-condition-tree-jb 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streamlit-condition-tree-jb 0.1.2
File Size Uploaded Provenance Actions
streamlit-condition-tree-jb-0.1.2.tar.gz 2.4 MB Without provenance Details for streamlit-condition-tree-jb-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-condition-tree-jb 0.1.2
File Interpreter ABI Platform Actions
streamlit_condition_tree_jb-0.1.2-py3-none-any.whl Python 3 none any Details for streamlit_condition_tree_jb-0.1.2-py3-none-any.whl

Total release size: 4.8 MB

Release files / streamlit-condition-tree-jb-0.1.2.tar.gz

Download URL streamlit-condition-tree-jb-0.1.2.tar.gz
Size 2.4 MB
Tags Source
SHA-256 checksum
How to use checksums
be1eda9b8892d274f1d6fc960187bcf78dd4d0eb4781204aa820c32aa2798471
BLAKE2b-256 checksum
How to use checksums
c585485d72f896d37315d00c6571ad4bed3e85981cb3f418468dbe724676f449
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.13

Release files / streamlit_condition_tree_jb-0.1.2-py3-none-any.whl

Download URL streamlit_condition_tree_jb-0.1.2-py3-none-any.whl
Size 2.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
e012b69d62f9754fb526a57fdf88abc3a5a35ef661d03663d4955ed0c9cb8890
BLAKE2b-256 checksum
How to use checksums
6d3ac7feb2e063e3a734dfc189dce910ce3f5163541cd45c635525a646904b69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.13

Security for streamlit-condition-tree-jb 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page