Metadata-Version: 2.4
Name: remote-read-sql
Version: 1.1.0
Summary: Securely read sql into a pandas dataframe from a remote mysql DB
Keywords: pandas,ssh,mysql,remote,dataframe
Author: Erik van Widenfelt
Author-email: Erik van Widenfelt <ew2789@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 5 - Production/Stable
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: mysqlclient>=2.2.7
Requires-Dist: pandas>=2.3.3
Requires-Dist: paramiko==2.9.3
Requires-Dist: python-dotenv>=1.1.1
Requires-Dist: sphinx>=8.2.3
Requires-Dist: sqlalchemy>=2.0.44
Requires-Dist: sqlglot>=27.28.1
Requires-Dist: sshtunnel>=0.4.0
Requires-Python: >=3.12
Description-Content-Type: text/x-rst

Remote read_sql
===============

Read SQL into a pandas data frame from a remote server

Installation
------------

.. code-block:: bash

    pip install remote-read-sql

Usage
-----

In this example, `remote_read_sql` opens an ssh tunnel and connects to the mysql server locally on port 3306. The SQL query is sanitized and passed to pandas `read_sql`.

After reading the data into the dataframe, the ssh and db connections are closed.

.. code-block:: python

    # change to your own paths
    ssh_config = Path("~/.my_ssh_config")
    my_cnf_path = Path("~/.my.cnf")
    db_name = "my_database"

    # combine kwargs into a dictionary
    opts = {
        "ssh_config_path": ssh_config,
        "my_cnf_path": my_cnf_path,
        "my_cnf_connection_name": "remote_server",
        "db_name": db_name,
    }

    # open ssh, open db, read sql into dataframe, close db, close ssh
    df = remote_read_sql("SELECT * FROM subject_glucose", **opts)

    # inspect the dataframe
    df.head()
