Name | sqlalchemy-helper-tool JSON |
Version |
1.5.0
JSON |
| download |
home_page | None |
Summary | Package to work with mysql database from python |
upload_time | 2025-07-11 22:36:35 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.7 |
license | Copyright 2025 Anabel Reyes
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
keywords |
database
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# sqlalchemy_helper_tool
A lightweight Python utility class for simplified interaction with MySQL databases using SQLAlchemy and Pandas. It provides convenient methods to read, write, and modify data or schema with minimal boilerplate.
## Features
- Easy connection setup to a MySQL database using SQLAlchemy
- Execute raw SQL queries
- Inspect tables and columns
- Read SQL results into Pandas DataFrames
- Append, replace, or ignore duplicate rows when writing
- Dynamically add or remove columns
- Parameterized queries
- Auto-handle nulls in inserts
- Safe "replace" of data while preserving table schema
## Installation
Install via pip (requires `sqlalchemy`, `pymysql`, and `pandas`):
```bash
pip install sqlalchemy_helper_tool
```
Clone this repository if needed:
```bash
git clone https://github.com/anakings/sqlalchemy_helper_tool.git
```
## Usage
```python
from sqlalchemy_helper_tool import DbApi
db = DbApi(
server='localhost',
database='my_db',
username='user',
password='pass'
)
# Run a SQL query
result = db.execute_query("SELECT COUNT(*) FROM users")
# Read a SQL query as DataFrame
df = db.read_sql("SELECT * FROM users LIMIT 10")
# Check if a table exists
exists = db.table_in_db("users")
# Add a new column after an existing one
db.add_column("users", "new_col", "existing_col")
# Write DataFrame ignoring duplicates
db.write_sql_key(df, "users")
# Append rows to an existing table
db.write_sql_df_append(df, "users")
# Replace all data in a table but keep schema
db.write_sql_df_replace(df, "users")
# Replace values in a specific column using a key
db.replace_sql_values(df, "users", column_replace="status", columns_key="id")
# Delete all rows in a table
db.delete_table("users")
# Drop a column
db.delete_column("users", "new_col")
```
## Class: `DbApi`
### Initialization
```python
DbApi(server, database, username, password, dict_params=None)
```
### Key Methods
| Method | Description |
|--------|-------------|
| `execute_query(query)` | Executes a raw SQL query |
| `read_sql(query, dict_params=None)` | Executes a SQL query and returns a DataFrame |
| `table_in_db(table_name)` | Checks if table exists |
| `table_info(table_name)` | Returns column metadata |
| `read_columns_table_db(table_name)` | Returns column names as list |
| `add_column(table_name, column_name, after_column)` | Adds a column |
| `delete_column(table_name, column_name)` | Removes a column |
| `delete_table(table_name)` | Deletes all rows in a table |
| `write_sql_key(df, table_name)` | Inserts ignoring duplicates |
| `write_sql_key2(df, table_name)` | Like above, but handles nulls and escapes column names |
| `write_sql_df_append(df, table_name)` | Appends to table |
| `write_sql_df_replace(df, table_name)` | Deletes all rows and inserts new ones, preserving schema |
| `replace_sql_values(df, table_name, column_replace, columns_key)` | Replaces specific values via ON DUPLICATE KEY UPDATE |
## Requirements
- Python 3.6+
- SQLAlchemy
- pymysql
- pandas
## License
MIT License
## Author
[Anabel Reyes](https://github.com/anakings)
Raw data
{
"_id": null,
"home_page": null,
"name": "sqlalchemy-helper-tool",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "Anabel Reyes <anakings95@gmail.com>",
"keywords": "Database",
"author": null,
"author_email": "Anabel Reyes <anakings95@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/aa/cf/f05d2ebe6cc7eb029bd28bb276cfb06f859675ea453610e90da835811681/sqlalchemy_helper_tool-1.5.0.tar.gz",
"platform": null,
"description": "\r\n# sqlalchemy_helper_tool\r\n\r\nA lightweight Python utility class for simplified interaction with MySQL databases using SQLAlchemy and Pandas. It provides convenient methods to read, write, and modify data or schema with minimal boilerplate.\r\n\r\n## Features\r\n\r\n- Easy connection setup to a MySQL database using SQLAlchemy\r\n- Execute raw SQL queries\r\n- Inspect tables and columns\r\n- Read SQL results into Pandas DataFrames\r\n- Append, replace, or ignore duplicate rows when writing\r\n- Dynamically add or remove columns\r\n- Parameterized queries\r\n- Auto-handle nulls in inserts\r\n- Safe \"replace\" of data while preserving table schema\r\n\r\n## Installation\r\n\r\nInstall via pip (requires `sqlalchemy`, `pymysql`, and `pandas`):\r\n\r\n```bash\r\npip install sqlalchemy_helper_tool\r\n```\r\n\r\nClone this repository if needed:\r\n\r\n```bash\r\ngit clone https://github.com/anakings/sqlalchemy_helper_tool.git\r\n```\r\n\r\n## Usage\r\n\r\n```python\r\nfrom sqlalchemy_helper_tool import DbApi\r\n\r\ndb = DbApi(\r\n server='localhost',\r\n database='my_db',\r\n username='user',\r\n password='pass'\r\n)\r\n\r\n# Run a SQL query\r\nresult = db.execute_query(\"SELECT COUNT(*) FROM users\")\r\n\r\n# Read a SQL query as DataFrame\r\ndf = db.read_sql(\"SELECT * FROM users LIMIT 10\")\r\n\r\n# Check if a table exists\r\nexists = db.table_in_db(\"users\")\r\n\r\n# Add a new column after an existing one\r\ndb.add_column(\"users\", \"new_col\", \"existing_col\")\r\n\r\n# Write DataFrame ignoring duplicates\r\ndb.write_sql_key(df, \"users\")\r\n\r\n# Append rows to an existing table\r\ndb.write_sql_df_append(df, \"users\")\r\n\r\n# Replace all data in a table but keep schema\r\ndb.write_sql_df_replace(df, \"users\")\r\n\r\n# Replace values in a specific column using a key\r\ndb.replace_sql_values(df, \"users\", column_replace=\"status\", columns_key=\"id\")\r\n\r\n# Delete all rows in a table\r\ndb.delete_table(\"users\")\r\n\r\n# Drop a column\r\ndb.delete_column(\"users\", \"new_col\")\r\n```\r\n\r\n## Class: `DbApi`\r\n\r\n### Initialization\r\n\r\n```python\r\nDbApi(server, database, username, password, dict_params=None)\r\n```\r\n\r\n### Key Methods\r\n\r\n| Method | Description |\r\n|--------|-------------|\r\n| `execute_query(query)` | Executes a raw SQL query |\r\n| `read_sql(query, dict_params=None)` | Executes a SQL query and returns a DataFrame |\r\n| `table_in_db(table_name)` | Checks if table exists |\r\n| `table_info(table_name)` | Returns column metadata |\r\n| `read_columns_table_db(table_name)` | Returns column names as list |\r\n| `add_column(table_name, column_name, after_column)` | Adds a column |\r\n| `delete_column(table_name, column_name)` | Removes a column |\r\n| `delete_table(table_name)` | Deletes all rows in a table |\r\n| `write_sql_key(df, table_name)` | Inserts ignoring duplicates |\r\n| `write_sql_key2(df, table_name)` | Like above, but handles nulls and escapes column names |\r\n| `write_sql_df_append(df, table_name)` | Appends to table |\r\n| `write_sql_df_replace(df, table_name)` | Deletes all rows and inserts new ones, preserving schema |\r\n| `replace_sql_values(df, table_name, column_replace, columns_key)` | Replaces specific values via ON DUPLICATE KEY UPDATE |\r\n\r\n## Requirements\r\n\r\n- Python 3.6+\r\n- SQLAlchemy\r\n- pymysql\r\n- pandas\r\n\r\n## License\r\n\r\nMIT License\r\n\r\n## Author\r\n\r\n[Anabel Reyes](https://github.com/anakings)\r\n",
"bugtrack_url": null,
"license": "Copyright 2025 Anabel Reyes\r\n \r\n Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\r\n \r\n 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\r\n \r\n 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\r\n \r\n 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\r\n \r\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \u201cAS IS\u201d AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
"summary": "Package to work with mysql database from python",
"version": "1.5.0",
"project_urls": {
"Documentation": "https://github.com/anakings/sqlalchemy_helper_tool/blob/feature/sqlalchemy_helper_tool/README.md",
"Homepage": "https://github.com/anakings/sqlalchemy_helper_tool"
},
"split_keywords": [
"database"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "760995f2f035ca24e6f159f74a2514ed2d8b73863a7ba8066562bc69cf48349d",
"md5": "03a371acad2cdb0f00b086f83838df99",
"sha256": "b8791b9bda92106743838d321d6d3862b55c4e43c1d5dbf966a94b20dc60e4e0"
},
"downloads": -1,
"filename": "sqlalchemy_helper_tool-1.5.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "03a371acad2cdb0f00b086f83838df99",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 7141,
"upload_time": "2025-07-11T22:36:34",
"upload_time_iso_8601": "2025-07-11T22:36:34.575961Z",
"url": "https://files.pythonhosted.org/packages/76/09/95f2f035ca24e6f159f74a2514ed2d8b73863a7ba8066562bc69cf48349d/sqlalchemy_helper_tool-1.5.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "aacff05d2ebe6cc7eb029bd28bb276cfb06f859675ea453610e90da835811681",
"md5": "54a69b1014dd2cde56793dff153dfdc0",
"sha256": "426f2693c39b09d69cb6295042d7bc6c12ba50848a8f0f16623a2441ec027204"
},
"downloads": -1,
"filename": "sqlalchemy_helper_tool-1.5.0.tar.gz",
"has_sig": false,
"md5_digest": "54a69b1014dd2cde56793dff153dfdc0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 5992,
"upload_time": "2025-07-11T22:36:35",
"upload_time_iso_8601": "2025-07-11T22:36:35.413668Z",
"url": "https://files.pythonhosted.org/packages/aa/cf/f05d2ebe6cc7eb029bd28bb276cfb06f859675ea453610e90da835811681/sqlalchemy_helper_tool-1.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-11 22:36:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "anakings",
"github_project": "sqlalchemy_helper_tool",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "sqlalchemy-helper-tool"
}