Skip to main content

Fetch and execute MySQL queries by proc_name, returning a pandas DataFrame.

Project description

dbprocedures

A lightweight Python library that fetches a registered SQL query by name from a MySQL table and returns its result as a pandas DataFrame.


Installation

From a local folder

pip install /path/to/dbprocedures/

From a Git repository (internal)

pip install git+https://your-internal-git-repo/dbprocedures.git

Prerequisites

1. Environment Variables

Set the following environment variables before using the library:

Variable Description Example
DB_HOST MySQL server hostname your-db-host.example.com
DB_PORT MySQL server port 3306
DB_NAME Database name your_database_name
DB_USER MySQL username your_username
DB_PASSWORD MySQL password yourpassword

Linux / macOS:

export DB_HOST=your-db-host.example.com
export DB_PORT=3306
export DB_NAME=your_database_name
export DB_USER=your_username
export DB_PASSWORD=yourpassword

Windows (PowerShell):

$env:DB_HOST = "your-db-host.example.com"
$env:DB_PORT = "3306"
$env:DB_NAME = "your_database_name"
$env:DB_USER = "your_username"
$env:DB_PASSWORD = "yourpassword"

2. Registry Table

The MySQL database must have a table (default name: proc_query_registry) with these columns:

Column Type Description
proc_name VARCHAR Unique name for the query
query TEXT The SQL query to execute

Example:

CREATE TABLE proc_query_registry (
    proc_name VARCHAR(255) PRIMARY KEY,
    query     TEXT NOT NULL
);

Usage

from dbprocedures import run_proc

df = run_proc("my_proc_name")
print(df.head())

Custom registry table name

df = run_proc("my_proc_name", registry_table="my_custom_table")

How It Works

  1. Reads DB credentials from environment variables.
  2. Connects to MySQL using pymysql.
  3. Looks up the SQL query in proc_query_registry where proc_name matches.
  4. Executes that query on the same DB connection.
  5. Returns the result as a pandas.DataFrame.

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

dbprocedures-0.1.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbprocedures-0.1.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file dbprocedures-0.1.2.tar.gz.

File metadata

  • Download URL: dbprocedures-0.1.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for dbprocedures-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2707a4f7d171a66edb35f8258ca38c72daebda99f622d9c12b4ea3b670b42626
MD5 bc3ea973e20f777d4ed1fcf9c46d56b4
BLAKE2b-256 102553165ac957bc3bfcd02466dc48adbb7c0d3aed8c8e6b46f37709dce1a0f5

See more details on using hashes here.

File details

Details for the file dbprocedures-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: dbprocedures-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for dbprocedures-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 71c72cca742e7bc4367a209b78af07684f7f1442862c20b5dde602d088e9021f
MD5 cc7b1d1839d638d4a570bc139dee9188
BLAKE2b-256 e0ea092d9968dbafa7646b89248c402be4e0428b16586243ca7b2ff4e5ff76d6

See more details on using hashes here.

Supported by

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