Install Safe SQL from PyPI
Safe SQL adds safety checks around SQL operations so common mistakes do not turn into production incidents.
Safe SQL is a Python library and CLI that validates SQL queries, previews risky changes, checks schemas, and adds guardrails around destructive operations.
Updating or deleting production data is high stakes, and small mistakes can be expensive. Safe SQL exists to catch common pitfalls before queries run and to make database workflows safer by default.
Active utility for safer SQL execution, with practical safeguards for development and operational workflows.
Here are the key features of Safe SQL:
-
Improved Query Parsing: Before update/delete queries, safe-sql provides a SELECT query for the user to perform sanity check.
-
Mode Specifier: Safe SQL provides 3 modes(read, write, admin), and implements safety checks before query execution.
-
Enhanced Safet Checks: Common pitfalls such as showing number of rows affected, notifying the user when missing WHERE clause with UPDATE and DELETE and checks when data is modified.
-
Schema Validation: Safe SQL checks if all columns used in the query exists.
-
Backup Creation: Before executing unsafe queries, Safe SQL creates a backup of the affected rows in a new table.
-
Query Caching: Safe SQL provides methods to cache query results and retrieve them, for frequently executed read queries. All queries are executed within a transaction.
-
CLI Interface: Safe SQL is managed through poetry dependency manager, and a robust CLI is provided to execute queries.
Working with databases is high stakes. Backups help, but they do not remove the need for strong guardrails at query time. Safe SQL focuses on practical checks that reduce avoidable mistakes before they hit production. Contributions are always welcome.
Safe SQL is managed through poetry, so to install the package use the following command(after cloning the repository and cd-ing into the project folder):
poetry install
To run the Safe SQL using query using the command line, use :
poetry run safe_sql execute --connection-string "your_connection_string" --mode write --query "Your SQL query"
Safe SQL is available on PyPI, and can be installed with the follwing command :
pip install safe-sql
Behind the scene, Safe SQL uses SQLAlchemy to interact with the database, so you don't have to deal with different dialect of MySQL, PostgreSQL, Oracle and can more efficiently query your data.
Safe SQL manages all the interaction with the databased based on the --connection-string CLI argument. After that, just set the mode and give the query, and leave the rest to Safe SQL.
PRs are always welcome. You can always work on these tasks :
- Adding functionality for other common pitfalls.