Skip to main content

Query tool to generate query from selection

Project description

Query Tool

Query Tool - a powerful and user-friendly streamlit component designed to simplify your data analysis. With its intuitive interface, you can easily select the desired databases, columns, and tables, and apply filters, dimensions, and measures to analyze your data. Whether you're a beginner or an experienced analyst, "query_tool" is the perfect tool for your data analysis needs.

Installation

You can install the Data Grid package from PyPI using pip:

pip install bp-query-tool

Usage

To use the Query Tool component in your Streamlit application, follow these steps:

  1. Import the necessary modules:
import query_tool as qt
  1. Add the Query Tool component to your application:
qt.query_tool(
    query=query,
    title="Query Tool",
    databases=databases,
    tables=tables,
    columns=columns,
    on_database_change=on_database_change,
    on_table_change=on_table_change,
    on_generate_query=on_generate_query,
    on_copy_query=on_copy_query,
    on_execute_query=on_execute_query,
    key="query_builder",
)
  1. Run your Streamlit application:
streamlit run your_app.py

Example

import query_tool as qt

databases = ['COMPANY_DB', 'SALES_DB']
tables = [
    {
        'database': 'COMPANY_DB',
        'tables': ['EMPLOYEES', 'DEPARTMENTS']
    },
    {
        'database': 'SALES_DB',
        'tables': ['CUSTOMERS', 'ORDERS']
    }
]
columns = [
    {
        'fqtn': 'COMPANY_DB.EMPLOYEES',
        'columns': ['ID', 'NAME', 'EMAIL', 'POSITION']
    },
    {
        'fqtn': 'COMPANY_DB.DEPARTMENTS',
        'columns': ['ID', 'NAME', 'LOCATION', 'MANAGER']
    },
    {
        'fqtn': 'SALES_DB.CUSTOMERS',
        'columns': ['ID', 'NAME', 'EMAIL', 'PHONE']
    },
    {
        'fqtn': 'SALES_DB.ORDERS',
        'columns': ['ID', 'PRODUCT', 'QUANTITY', 'DATE']
    }
]

def on_database_change(database):
    print(database)

def on_table_change(database, table):
    print(database, table)

def on_generate_query(selection, query):
    print(selection, query)

def on_copy_query(query):
    print(query)

def on_execute_query(query):
    print(query)

qt.query_tool(
    query=query,
    title="Query Tool",
    databases=databases,
    tables=tables,
    columns=columns,
    on_database_change=on_database_change,
    on_table_change=on_table_change,
    on_generate_query=on_generate_query,
    on_copy_query=on_copy_query,
    on_execute_query=on_execute_query,
    key="query_builder",
)

Screenshot

Screenshot

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bp_query_tool-1.0.3.tar.gz (314.4 kB view hashes)

Uploaded Source

Built Distribution

bp_query_tool-1.0.3-py3-none-any.whl (317.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page