{"id":14981105,"url":"https://github.com/cedricvlt/streamlit-condition-tree","last_synced_at":"2025-10-29T04:31:41.985Z","repository":{"id":196192326,"uuid":"694865036","full_name":"cedricvlt/streamlit-condition-tree","owner":"cedricvlt","description":"A Streamlit component to build a condition tree","archived":false,"fork":false,"pushed_at":"2024-04-10T13:54:00.000Z","size":415,"stargazers_count":47,"open_issues_count":1,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-08T10:47:29.655Z","etag":null,"topics":["conditions","elasticsearch","filters","jsonlogic","mongodb","spel","sql","streamlit-component"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cedricvlt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-21T21:22:22.000Z","updated_at":"2024-07-14T11:26:19.193Z","dependencies_parsed_at":null,"dependency_job_id":"1fcc3fff-6ec9-4e95-b7a7-0024ae53f355","html_url":"https://github.com/cedricvlt/streamlit-condition-tree","commit_stats":null,"previous_names":["cedricvlt/streamlit-condition-tree"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedricvlt%2Fstreamlit-condition-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedricvlt%2Fstreamlit-condition-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedricvlt%2Fstreamlit-condition-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedricvlt%2Fstreamlit-condition-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cedricvlt","download_url":"https://codeload.github.com/cedricvlt/streamlit-condition-tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238768421,"owners_count":19527197,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conditions","elasticsearch","filters","jsonlogic","mongodb","spel","sql","streamlit-component"],"created_at":"2024-09-24T14:02:55.433Z","updated_at":"2025-10-29T04:31:36.657Z","avatar_url":"https://github.com/cedricvlt.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nBased on [react-awesome-query-builder](https://github.com/ukrbublik/react-awesome-query-builder)\n\nCheck out [live demo](https://condition-tree-demo.streamlit.app/) !\n\nThis component allows users to build complex condition trees that can be used to filter a dataframe or build a query.\n\n\u003cimg src=\"preview.jpg\" width=\"500\" alt=\"preview\"\u003e\n\n\n## Install\n\n`pip install streamlit-condition-tree`\n\n\n## Features\n- Highly configurable\n- Fields can be of type:\n  - simple (string, number, bool, date/time/datetime, list)\n  - structs (will be displayed in selectbox as tree)\n- Comparison operators can be:\n  - binary (== != \u003c \u003e ..)\n  - unary (is empty, is null)\n  - 'between' (for numbers, dates, times)\n  - complex operators like 'proximity'\n- RHS can be:\n  - values\n  - another fields (of same type)\n  - functions (arguments also can be values/fields/funcs)\n- LHS can be field or function\n- Reordering (drag-n-drop) support for rules and groups of rules\n- Export to MongoDb, SQL, JsonLogic, SpEL or ElasticSearch\n\n## Basic usage\n\n### Filter a dataframe\n\n```python\nimport pandas as pd\nfrom streamlit_condition_tree import condition_tree, config_from_dataframe\n\n# Initial dataframe\ndf = pd.DataFrame({\n    'First Name': ['Georges', 'Alfred'],\n    'Age': [45, 98],\n    'Favorite Color': ['Green', 'Red'],\n    'Like Tomatoes': [True, False]\n})\n\n# Basic field configuration from dataframe\nconfig = config_from_dataframe(df)\n\n# Condition tree\nquery_string = condition_tree(\n  config,\n  always_show_buttons=True,\n  placeholder=\"Empty condition tree\"\n)\n\n# Filtered dataframe\ndf = df.query(query_string)\n```\n\n### Build a query\n\n```python\nimport streamlit as st\nfrom streamlit_condition_tree import condition_tree\n\n# Build a custom configuration\nconfig = {\n    'fields': {\n        'name': {\n            'label': 'Name',\n            'type': 'text',\n        },\n        'age': {\n            'label': 'Age',\n            'type': 'number',\n            'fieldSettings': {\n                'min': 0\n            },\n        },\n        'like_tomatoes': {\n            'label': 'Likes tomatoes',\n            'type': 'boolean',\n        }\n    }\n}\n\n# Condition tree\nreturn_val = condition_tree(\n    config,\n    return_type='sql'\n)\n\n# Generated SQL\nst.write(return_val)\n```\n\n## API\n\n### Parameters\n\n```python\ndef condition_tree(\n    config: dict,\n    return_type: str [Optional],\n    tree: dict [Optional],\n    min_height: int [Optional],\n    placeholder: str [Optional],\n    always_show_buttons: bool [Optional],\n    key: str [Optional]\n)\n```\n\n- **config**: Python dictionary (mostly used to define the fields) that resembles the JSON counterpart of\n  the React component.\n   \nA basic configuration can be built from a DataFrame with `config_from_dataframe`.  \nFor a more advanced configuration, see the component [doc](https://github.com/ukrbublik/react-awesome-query-builder/blob/master/CONFIG.adoc)\nand [demo](https://ukrbublik.github.io/react-awesome-query-builder/).\nCustom javascript functions must be wrapped into the JsCode class (see [Advanced config](https://condition-tree-demo.streamlit.app/Advanced_config))\n\n- **return_type**: Format of the returned value :\n  - queryString\n  - mongodb\n  - sql\n  - spel\n  - elasticSearch\n  - jsonLogic  \n\n  Default : queryString (can be used to filter a pandas DataFrame using DataFrame.query)\n\n\n- **tree**: Input condition tree (see section below)\n  \n  Default : None\n\n\n- **min_height**: Minimum height of the component frame\n  \n  Default : 400\n\n\n- **placeholder**: Text displayed when the condition tree is empty\n  \n  Default : None\n\n\n- **always_show_buttons**: Show buttons (create rule, etc.) even when they are not hovered\n\n  Default: True\n\n\n- **key**: Fixed identity if you want to change its arguments over time and not have it be re-created.  \nCan also be used to access the generated condition tree (see section below).\n\n  Default : None\n\n\n### Export \u0026 import a condition tree\n\nWhen a key is defined for the component, the condition tree generated is accessible through `st.session_state[key]` as a dictionary.  \nIt can be loaded as an input tree through the `tree` parameter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedricvlt%2Fstreamlit-condition-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcedricvlt%2Fstreamlit-condition-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedricvlt%2Fstreamlit-condition-tree/lists"}