Wrapper for importing CSV and Text files into MySQL and Postgress
Project description
SqlDbWrpr
| Category | Status' and Links |
|---|---|
| General | |
| CD/CI | |
| PyPI | |
| Github |
Short description
SqlDbWrpr is a Python wrapper that streamlines schema creation plus CSV import/export workflows for SQL backends.
Module Overview
SqlDbWrpr is a Python utility for creating SQL database schemas and moving CSV data into and out of those schemas. It currently provides wrappers for MySQL and PostgreSQL.
Schemas can be supplied in two ways:
- A legacy
db_structuredictionary. - SQLAlchemy metadata, either directly through
p_sqlalchemy_metadataor throughp_sqlalchemy_base.metadata.
When both are supplied, p_db_structure takes precedence for backward compatibility. If no supported schema source is supplied, SchemaSourceError is raised.
Key Features
- Schema Management: Create databases, tables, primary keys, foreign keys, and indexes from a legacy dictionary or SQLAlchemy metadata.
- Data Import/Export:
- Import CSV data from files or in-memory rows, including single-volume and numbered multi-volume files.
- Export full tables or custom SQL query results to CSV, including optional multi-volume exports.
- Database Support: Includes MySQL and PostgreSQL wrappers with dialect-specific SQL rendering.
- User and Permission Management: Create MySQL users and grant database rights.
- Batch Processing: Configure import batch sizes for larger CSV loads.
Project Structure
src/sqldbwrpr/: Core library implementation, including MySQL and PostgreSQL wrappers.tests/: Unit and integration-oriented test coverage for wrapper behaviour.scripts/: SQL setup/bootstrap assets used for database initialization.- Root automation scripts (
*.ps1) and CI configuration under.github/workflows/support setup and delivery.
Getting Started
Installation
pip install SqlDbWrpr
Quick Start With A Legacy Structure
from sqldbwrpr.sqldbwrpr import MySQL
field_defaults = {
"PrimaryKey": ["", ""],
"FKey": [],
"Index": [],
"NN": "",
"B": "",
"UN": "",
"ZF": "",
"AI": "",
"G": "",
"DEF": "",
}
db_structure = {
"Users": {
"ID": {
"Type": ["int"],
"Params": {
**field_defaults,
"PrimaryKey": ["Y", "A"],
"NN": "Y",
"AI": "Y",
},
"Possible Values": "",
"Comment": "",
},
"Username": {
"Type": ["varchar", 50],
"Params": {**field_defaults, "NN": "Y"},
"Possible Values": "",
"Comment": "",
},
}
}
db = MySQL(
p_host_name="localhost",
p_user_name="root",
p_password="yourpassword",
p_db_name="my_database",
p_db_structure=db_structure,
p_recreate_db=True,
)
db.import_csv("Users", p_csv_db=[("Username",), ("alice",)], p_vol_type="Single")
db.export_to_csv("exported_users.csv", "Users")
Quick Start With SQLAlchemy Metadata
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import String
from sqlalchemy import Table
from sqldbwrpr.sqldbwrpr import PostgreSQL
metadata = MetaData()
Table(
"Users",
metadata,
Column("ID", Integer, primary_key=True, autoincrement=True),
Column("Username", String(50), nullable=False),
)
db = PostgreSQL(
p_host_name="localhost",
p_user_name="postgres",
p_password="yourpassword",
p_db_name="my_database",
p_sqlalchemy_metadata=metadata,
p_recreate_db=True,
)
db.import_csv("Users", p_csv_db=[("Username",), ("alice",)], p_vol_type="Single")
Updating ReleaseNotes Instructions
- Run the
pushpy.ps1script or manually commit the current changes. - Generate the release notes
- Use one of the following AI propmpts in Notion to generate the release notes.
or
-
Use the following template and manually update the ReleaseNotes.md file.
# Release ?.?.? ## Summary of Changes - bla, bla, bla ## Next Heading - bla, bla, bla --- -
You can repeat step 1 multiple times.
-
You can repeat step 2 multiple times but update the ReleaseNotes that has not been published.
-
Run the
pushpr.ps1script once you are ready to create the PR to publish the release. TOy can also manually create the tag, touch a file, commit and push the changes. -
Merge the PR in GitHub.
-
Confirm the following:
-
The release update reflects in GitHub
-
The release update notification was sent
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqldbwrpr-5.1.0.tar.gz.
File metadata
- Download URL: sqldbwrpr-5.1.0.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.13.14 Linux/6.17.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7378f61b8281eb1eb165f65e063bcf2075ec13d24137a0163ebf19dc3dc976e
|
|
| MD5 |
84bc66fd2d524b2bbbcb51f7a4a0d551
|
|
| BLAKE2b-256 |
070555e63c5e7edb59f587c9013ea3f6b7b791bc28defb1f90711e2980580394
|
File details
Details for the file sqldbwrpr-5.1.0-py3-none-any.whl.
File metadata
- Download URL: sqldbwrpr-5.1.0-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.13.14 Linux/6.17.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8c78b9c079ffebc4456f4c24f03d691c737c46bfe40e0ae7c4022ddc990855f
|
|
| MD5 |
364e37b35f87e57c7ab34d3424b717ab
|
|
| BLAKE2b-256 |
8c0a17b30cee91e1441914666b692555c1ad6c9d86a7577cf73e12518e5d9084
|