Skip to main content

A Python package to execute SQL queries and procedures and manage backups.

Project description

Database Query and Backup Script - Summary

This script provides the get_query_from_db and exec_procedure_from_db functions, designed to interact with a SQL Server database. It supports executing queries or stored procedures, and optionally creating backups of tables.

Function Usage

  • get_query_from_db(query, table_to_backup, env_file_name=None, params=None):

    • Executes a SQL query on the database.
    • Parameters:
      • query: A SQL query string to execute on the database.
      • table_to_backup: The name of a table to back up. Set this to None if no backup is needed.
      • env_file_name (optional): The path to the .env file containing database credentials. Defaults to .env.
      • params (optional): A dictionary of parameters to bind to the query.
    • Returns:
      • A pandas DataFrame with the query results.
  • exec_procedure_from_db(procedure_name, table_to_backup, env_file_name=None, params=None):

    • Executes a stored procedure on the database.
    • Parameters:
      • procedure_name: The name of the stored procedure to execute.
      • table_to_backup: The name of a table to back up. Set this to None if no backup is needed.
      • env_file_name (optional): The path to the .env file containing database credentials. Defaults to .env.
      • params (optional): A dictionary of parameters to bind to the procedure.
    • Returns:
      • A pandas DataFrame with the procedure's output.

Setup Instructions

  1. Environment Variables:
    • The script requires a .env file to load database credentials and connection details.
    • Required variables:
      USER=
      PASSWORD=
      HOST=
      NAME=
      DRIVER=ODBC+Driver+17+for+SQL+Server
      
      Fill in the variables with your database details. Leave DRIVER unchanged unless you are using a different driver.

Installation

Install the package directly from PyPI:

pip install Credito_SQLViaCode

#### Examples:

- **Execute a Query**:
   ```python
   from SQLViaCode import get_query_from_db

   query = "SELECT * FROM your_table"
   result_df = get_query_from_db(query, "your_table_to_backup")
   print(result_df)

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

sql_via_code-0.0.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

sql_via_code-0.0.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file sql_via_code-0.0.1.tar.gz.

File metadata

  • Download URL: sql_via_code-0.0.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.6

File hashes

Hashes for sql_via_code-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e3c05921145212a3caeb2ff7ae91e5cd46de532777f2a99e8794e7635b00e7d1
MD5 5d7f2ced48db4238e535cd06d8ccddc4
BLAKE2b-256 aa795912438a59f2365afe43276c2bcb8a3353ee46111e6e4401c9b335f30a72

See more details on using hashes here.

File details

Details for the file sql_via_code-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: sql_via_code-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.6

File hashes

Hashes for sql_via_code-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6eed4f90d0122d393cbc1637319ce097c82cd37ffff03bf9be7fa7dd587bf519
MD5 9c49dca1631527eac7f7bce8822fbad8
BLAKE2b-256 349c72e94913813458d0bdf5556ac51853acc4cfc7b72f382c277a768d8d995d

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