Python Dependencies Required for the dbquery Plugin: Complete Guide
The dbquery plugin requires ten specific Python packages including dify_plugin, SQLAlchemy, pandas, and database-specific drivers like PyMySQL and psycopg2-binary, all pinned to exact versions in db_query/requirements.txt.
The dbquery plugin, developed in the junjiem/dify-plugin-tools-dbquery repository, enables Dify to execute SQL queries across multiple database systems through a unified interface. Understanding the Python dependencies required for the dbquery plugin is essential for troubleshooting installation issues and ensuring compatibility with your existing Python environment.
Core Python Dependencies in db_query/requirements.txt
All runtime requirements are explicitly declared in db_query/requirements.txt at the repository root. The plugin depends on the following packages:
Dify Plugin SDK
dify_plugin==0.2.1— The core SDK that enables the plugin to register with Dify's plugin system, handle incoming requests, and return structured responses. This is the foundational dependency that defines the plugin's interface with the Dify platform.
SQL Parsing and Formatting
sqlparse==0.5.3— Used indb_query/tools/sql_query.pyto parse and normalize raw SQL strings before execution. This ensures consistent formatting and enables safe handling of user-provided queries.
Database Connectivity Stack
-
SQLAlchemy==2.0.35— The primary ORM and database toolkit used indb_query/provider/db_query.pyanddb_query/tools/db_util.pyto create database engines and manage connections abstractly. -
PyMySQL==1.1.1— MySQL/MariaDB driver required by SQLAlchemy when connecting to MySQL databases. -
oracledb==2.2.1— Oracle Database driver for SQLAlchemy connections to Oracle instances. -
psycopg2-binary==2.9.10— PostgreSQL driver enabling SQLAlchemy to connect to PostgreSQL databases. -
pymssql==2.3.4— Microsoft SQL Server driver for SQLAlchemy connections to SQL Server instances.
Data Processing and Output Formatting
-
pandas==2.2.3— Provides the DataFrame API used indb_query/tools/db_util.pyto manipulate query results before returning them to Dify. -
tabulate==0.9.0— Renders query results as formatted Unicode tables suitable for display in Dify's interface.
Installing the dbquery Plugin Dependencies
To install the exact versions required by the plugin, use the requirements.txt file directly:
pip install -r https://raw.githubusercontent.com/junjiem/dify-plugin-tools-dbquery/main/db_query/requirements.txt
For local development after cloning the repository:
git clone https://github.com/junjiem/dify-plugin-tools-dbquery.git
cd dify-plugin-tools-dbquery
pip install -r db_query/requirements.txt
How Dependencies Power the Plugin Architecture
The Python dependencies required for the dbquery plugin work together across several key files:
In db_query/provider/db_query.py, SQLAlchemy creates database engines using connection strings, while pandas transforms result sets into DataFrames for processing. The sqlparse library, called from db_query/tools/sql_query.py, normalizes SQL syntax before execution to prevent formatting errors.
Database-specific drivers (PyMySQL, psycopg2-binary, oracledb, pymssql) are loaded dynamically by SQLAlchemy based on the connection URL scheme (e.g., mysql+pymysql://, postgresql+psycopg2://). This abstraction allows db_query/tools/db_util.py to handle connections uniformly without database-specific logic.
Finally, tabulate converts the processed DataFrame into a readable Markdown table, which the dify_plugin SDK packages into the response payload sent back to the Dify platform.
Summary
- The dbquery plugin requires ten specific Python packages defined in
db_query/requirements.txt. - Core infrastructure includes
dify_plugin(SDK),SQLAlchemy(database abstraction), andpandas(data processing). - Database drivers cover MySQL (
PyMySQL), PostgreSQL (psycopg2-binary), Oracle (oracledb), and SQL Server (pymssql). - Utilities include
sqlparse(SQL parsing),tabulate(output formatting), andpandas(result manipulation). - Install all dependencies using
pip install -r db_query/requirements.txtto ensure version compatibility.
Frequently Asked Questions
What is the minimum Python version required for the dbquery plugin?
The repository does not explicitly specify a minimum Python version in the requirements file. However, given that pandas==2.2.3 and SQLAlchemy==2.0.35 require Python 3.9 or higher, you should use Python 3.9+ to ensure all dependencies install correctly.
Can I use different versions of SQLAlchemy or pandas with this plugin?
No, you should not upgrade or downgrade these packages independently. The requirements.txt file pins exact versions (SQLAlchemy==2.0.35, pandas==2.2.3) because the plugin code in db_query/provider/db_query.py and db_query/tools/db_util.py relies on specific APIs and behaviors present only in these versions. Using different versions may cause connection failures or data processing errors.
How do I install the dbquery plugin dependencies in a virtual environment?
Create and activate a virtual environment, then install the requirements:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r db_query/requirements.txt
This isolation prevents conflicts with system Python packages and ensures the exact dependency versions required by the dbquery plugin are available.
Which database drivers are included in the dbquery plugin requirements?
The plugin includes drivers for four major relational databases: PyMySQL for MySQL and MariaDB, psycopg2-binary for PostgreSQL, oracledb for Oracle Database, and pymssql for Microsoft SQL Server. SQLAlchemy automatically selects the appropriate driver based on the database connection URL you provide when configuring the plugin in Dify.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →