Skip to main content

A Python module for simplifying interactions with PostgreSQL databases, with rich console output for better readability and debugging.

Project description

sonnixgres

A Python module for simplifying interactions with PostgreSQL databases, with rich console output for better readability and debugging.

Installation

Install sonnixgres using pip:

pip install sonnixgres

Usage

First, ensure that your PostgreSQL credentials are set as environment variables. sonnixgres uses these variables to establish database connections.

from sonnixgres import create_connection, query_database, save_results_to_csv, create_and_populate_table, update_records, create_view
import pandas as pd

# Establish a database connection
connection = create_connection()

# Example usage of each function

Functions

create_connection()

Establishes a connection to the PostgreSQL database using credentials from environment variables.

query_database(connection, query, params=None, close_connection=True)

Executes a SQL query on the database and returns the result as a Pandas DataFrame.

  • connection: The database connection object.
  • query: SQL query string.
  • params: Optional parameters for the SQL query.
  • close_connection: Whether to close the database connection after executing the query.

save_results_to_csv(dataframe, filename)

Saves a Pandas DataFrame to a CSV file.

  • dataframe: The DataFrame to be saved.
  • filename: The name of the file where data will be saved.

create_and_populate_table(connection, table_name, dataframe, populate=False)

Creates a new table in the database and optionally populates it with data from a DataFrame.

  • connection: The database connection object.
  • table_name: Name of the table to be created.
  • dataframe: DataFrame whose data will be used to populate the table.
  • populate: If True, the table will be populated with data from the DataFrame.

update_records(connection, update_query, params=None, close_connection=True)

Updates records in a database table.

  • connection: The database connection object.
  • update_query: SQL update query string.
  • params: Optional parameters for the SQL update query.
  • close_connection: Whether to close the database connection after executing the update.

create_view(connection, view_name, view_query, close_connection=True)

Creates a new view in the database.

  • connection: The database connection object.
  • view_name: Name of the view to be created.
  • view_query: SQL query string for creating the view.
  • close_connection: Whether to close the database connection after creating the view.

License

BSD License

Contributions

Contributions are welcome. Please open an issue or submit a pull request with your improvements.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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

sonnixgres-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

sonnixgres-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file sonnixgres-0.1.0.tar.gz.

File metadata

  • Download URL: sonnixgres-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.0 Linux/6.5.0-14-generic

File hashes

Hashes for sonnixgres-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ad3242111f6463464215a28a4ce51902b761623eb2720c730f452e4abf4b4db1
MD5 0bc7f5ba48ddcafb058c455ed05d358c
BLAKE2b-256 7642f417db8937aa309cd0e38d8ed5ef567633d95357c867a16d891429f6945f

See more details on using hashes here.

File details

Details for the file sonnixgres-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sonnixgres-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.0 Linux/6.5.0-14-generic

File hashes

Hashes for sonnixgres-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a7694f4b6faa45afe685f9b6657c8716dda84daaad528aecd31ee4a4060fd01
MD5 7f40bf9fef45d619e1e717def6e6662c
BLAKE2b-256 5dce4d82c4e77b7419af29870683127c4fcf5e8f04587d39f93e39381e930cc2

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