Skip to main content

PySQLTools

Project description

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
  • pyodbc
  • sqlalchemy
  • trino

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

pysqltools-0.2.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

pysqltools-0.2.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file pysqltools-0.2.1.tar.gz.

File metadata

  • Download URL: pysqltools-0.2.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-36-generic

File hashes

Hashes for pysqltools-0.2.1.tar.gz
Algorithm Hash digest
SHA256 000e5b12100ce4fb54e5edf41e1a9c04d12ed4a394cd2f95dffe4d21f0af2ecc
MD5 90b471d376eef1103c12090f04be9750
BLAKE2b-256 94a6733b39c7b35e4c5420801e2701f66bdd768131303ad0d289d65c2e2ebc3c

See more details on using hashes here.

File details

Details for the file pysqltools-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pysqltools-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.8.0-36-generic

File hashes

Hashes for pysqltools-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce27c23beafeb6e7e8ea8fe34b146e4a07378ea951e4537e1f43f47a30f2c3a0
MD5 1488e5221be7082036c462c49e9f9511
BLAKE2b-256 53ec8c76ec7af0f711310bd8f1305f9e91365e9fffbb0455603c8f759a8d95f9

See more details on using hashes here.

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