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.

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

Delete Module

Contains the function delete_from_dataframe. This function allows to generate a Query object that will contain a SQL to delete all the rows in the target table that meet the conditions on the dataframe rows

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-1.1.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

pysqltools-1.1.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pysqltools-1.1.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.5 Darwin/24.3.0

File hashes

Hashes for pysqltools-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e394d793650909330a78cae62bda3e1840f1151270f4b3c5a3b27f6e1e3ed771
MD5 19d09705d6b8b4b0d378c38102f456a4
BLAKE2b-256 8373154fdf60c06f3027dd41896eb6d71671084566a9f3c673a9b57c1ea20429

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pysqltools-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.5 Darwin/24.3.0

File hashes

Hashes for pysqltools-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d2cf8cdd6ed83195f4df17cd75af4b7fe3bf8de3acba3ca5bdb0606d7556041
MD5 26fcab0c9f8f64bf3eaff2b447196c1e
BLAKE2b-256 265b2ce554aaeb44e2911926154adba0cca196296a7aafbc8ce1dbb46945b027

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