Metadata-Version: 2.1
Name: pysqltools
Version: 0.2.6
Summary: PySQLTools
License: None
Author: Pablo Minué
Requires-Python: >=3.11,<4.0
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: alabaster (>=0.7.16,<0.8.0)
Requires-Dist: black
Requires-Dist: coverage
Requires-Dist: cx-oracle (>=8.3.0,<9.0.0)
Requires-Dist: ibm-db (>=3.2.3,<4.0.0)
Requires-Dist: multimethod (>=1.11.2,<2.0.0)
Requires-Dist: mypy
Requires-Dist: mysql-connector-python (>=9.0.0,<10.0.0)
Requires-Dist: pandas (>=2.2.2,<3.0.0)
Requires-Dist: pillow (>=10.3.0,<11.0.0)
Requires-Dist: pre-commit (>=3.7.1,<4.0.0)
Requires-Dist: psycopg2-binary (>=2.9.9,<3.0.0)
Requires-Dist: pylint
Requires-Dist: pymssql (>=2.3.0,<3.0.0)
Requires-Dist: pymysql (>=1.1.1,<2.0.0)
Requires-Dist: pyodbc (>=5.1.0,<6.0.0)
Requires-Dist: pytest (>=8.2.0,<9.0.0)
Requires-Dist: pytest-cov
Requires-Dist: sphinx (>=7.3.7,<8.0.0)
Requires-Dist: sqlalchemy (>=2.0.31,<3.0.0)
Requires-Dist: sqlparse (>=0.5.0,<0.6.0)
Requires-Dist: trino (>=0.328.0,<0.329.0)
Description-Content-Type: text/markdown

# pysqltools

PySQLTools tries to ease the interaction between Python and SQL. The idea behind this project is
to provide an easy framework to manage the interaction between this two languages. It allows dynamic
queries management, using parameters in the SQL queries that can be later easily manipulated with
the provided tools.

## Install
you can install the latest distribution by 
`pip install pysqltools`

## Current Features

### Query Module
The query module provides a Query class to work with Query objects, which will allow to modify the
SQL Queries on an easy way with the class methods, and easily access the sql string with the sql
attribute of the objects.

To add parameters to the query, use {{parameter}} on the SQL String.

The current methods are:

- ctes: Generator that yields the CTEs of the Query
- selects: Generator that yields the Select statements of the Query
- Windows: Generator that yields the Window Function contents of the query
- tables: Generator that yields the detected tables on the query
- parameters: Generator that yields all the parameters on the Query
- format: allows to assign values to the parameters in the query. Current supported types are str, int, float, datetime.datetime, list[int, float, str]
To call the format function, just call the parameters you have defined on your query. Example:
query:
`select * from {{table_param}} limit 20`

function call:
`query = Query(sql = sql).format(table_param = "MyTable")`

### Insert Module

More to be developed. For now, it contains a Generator `generate_insert_query` twith the following inputs:
- df: pd.DataFrame containing the data we want to insert
- table: name of the table we want to insert into
- schema: name of the schema were the table is located
- batch_size: How many rows on one insert query
Note: if no table is provided, a parameter {{table}} will be automatically created on the Query object. It can be later changed using the .format() method.


The Generator yields Insert Queries (with `batch_size` rows) that can be iterated to execute.

### Connection Module

Allows to instantiate a SQL Connection to execute and fetch results (i.e., use the insert_pandas method from the insert module) Supported connections:

- ibm_db
- mysql
- pymssql
- pymysql
- sqlalchemy
- trino

### Table Module

Allows to create tables on a SQL Database given a pandas DataFrame. Also contains the option to insert the data of the dataframe in the 
new table by calling the insert module
