SQLPy
SQLPy (sql_pydb) is a Python library to bridge the gap between Python and Database Tables.
Instalation Guide
pip install sql_pydb
- sql_pydb requires the following packages: Pandas, Numpy, pyodbc, python-dateutil
Overview:
- You can connect to MSSQL and SQLite.
- You can perform operations such as:
- Create Database(s)
- Create Table(s)
- Drop Column(s)
- Add Column(s)
- Alter Column Types (If database supports it)
- Performs a Try Cast check to be safe. (i.e. VARCHAR to INTEGER)
- Read from Table
- Delete from Table
- Drop Table(s)
Usage
- Example: Upload Pandas DataFrame to a MSSQL Database
from sql_pydb.Database import DatabaseType
from sql_pydb.Table import TableActions
table = TableActions(database=DATABASE, table_name=TABLE_NAME,
driver="ODBC Driver 17 for SQL Server",
server="url,port",
username="admin",
password="admin",
db_type=DatabaseType.MSSQL)
df = pd.read_csv("...file.csv")
table.identify_schema(df) # Figures out the best column types. Only needed 1 time per TableActions instance
table.sync_schema(update_column_types=True, add_new_columns=True, delete_old_columns=False) # Optional
status = table.insert_df(df, batch=1_000)
assert status == True
- Example: Upload Pandas DataFrame to a SQLite Database
from sql_pydb.Database import DatabaseType
from sql_pydb.Table import TableActions
table = TableActions(table_name=TABLE_NAME,
sqlite_path = SQLITE_PATH, # "./path/file.db"
db_type=DatabaseType.SQLITE)
df = pd.read_csv("...file.csv")
table.identify_schema(df) # Figures out the best column types. Only needed 1 time per TableActions instance
table.sync_schema(update_column_types=True, add_new_columns=True, delete_old_columns=False) # Optional
status = table.insert_df(df, batch=1_000)
assert status == True
- Example: Query Table
table = TableActions(...)
# ...
command = table.generate_select_all_sql()
df = table.run_query(command) # Returns pd.DataFrame
- Example: Execute Transactions
table = TableActions(...)
# ...
command1 = table.generate_add_columns_sql()
command2 = table.generate_drop_column_sql(column_name="UNUSED_COLUMN")
# ...
commandX = table.generate_insert_sql(df_new_records)
status = table.run_transaction([command1, command2, ..., commandX])
assert status == True
- Example: Create Table
from sql_pydb.Column import Column
from sql_pydb.Table import TableActions
table = TableActions(...)
# ...
user_defined_columns = [
Column("FIRST_NAME", data_type="VARCHAR", size=100),
...
Column("ADDRESS", data_type="VARCHAR"), # Default 255 for strings
]
table.identify_schema(df, user_defined_columns)
# Option 1: Let it automatically sync with the new defined columns
status = table.sync_schema(update_column_types=True, add_new_columns=True, delete_old_columns=False)
# Option 2: Manually create the table
command = table.generate_create_table_sql()
status = table.run_transaction([command])
assert status == True
- You may choose to replace
user_defined_columnswith a pd.DataFrame with["COLUMN", "DATA_TYPE", "SIZE"]columns.["DATABASE", "TABLE"]columns may also be passed in.
Support:
- If you have a question or need additional support, please create an issue ticket on SQLPy GitHub Repo.
Additional:
Metadata
Release files for sql-pydb 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sql_pydb-0.7.0.tar.gz | 12.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sql_pydb-0.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.0 kB
Release files / sql_pydb-0.7.0.tar.gz
| Download URL | sql_pydb-0.7.0.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
57a47bc506bc23cdcd29abaf1471ff0f8f3b7a5848d7525a2b7e759256443384
|
|
BLAKE2b-256 checksum How to use checksums |
3f47198d9970511c2096260724283b60a4f14e982312295b585a1f0173218e81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Release files / sql_pydb-0.7.0-py3-none-any.whl
| Download URL | sql_pydb-0.7.0-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
968207c67af127f0d923df910ad833f212acbbd075178f085a4d7f357ab2a222
|
|
BLAKE2b-256 checksum How to use checksums |
7fece1a543cce610086df8584df85439ccd5fb65da52ac65a390493efe48c3f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Security for sql-pydb 0.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.