DB Engine Factory: Simplify connecting to MySQL, MSSQL, and PostgreSQL databases through a single, unified configuration.
Project description
DB Engine Factory
Version: 0.1.1
Author: Will Palmer
Description: DB Engine Factory is a Python library designed to simplify connecting to multiple database types (MySQL, MSSQL, PostgreSQL) using SQLAlchemy. Connections are configured via a central .ini file, streamlining database management for applications needing to work with diverse database systems.
Table of Contents
Installation
-
Install the package from PyPI:
pip install db-engine-factory
-
Create a configuration file: Ensure your
.iniconfiguration file (e.g.,db_config.ini) is in the project root or the directory where you run scripts.
Configuration
Setting Up Your .ini Configuration File
Create a .ini file (e.g., db_config.ini) in the project’s root directory. Each section represents a database configuration.
Example db_config.ini
# MySQL Database
[mysql_db]
type = mysql
user = myuser
password = mypassword
host = localhost
port = 3306
database = mydatabase
# MSSQL Database
[mssql_db]
type = mssql
server = sqlserver.example.com
database = mydatabase
username = myuser
password = mypassword
# PostgreSQL Database
[postgres_db]
type = postgres
user = myuser
password = mypassword
host = localhost
port = 5432
database = mydatabase
Explanation of Fields
- type: Database type (
mysql,mssql, orpostgres). - user/username: Database username.
- password: Database password.
- host/server: Database server address.
- port: Database port (
3306for MySQL,5432for PostgreSQL). - database: Name of the database.
Usage
Creating Database Engines
Use the functions in db_connection.py to create database engines. Each function accepts a db_identifier matching a section in db_config.ini.
from db_engine_factory.db_connection import create_mysql_engine, create_mssql_engine, create_postgres_engine
# Create a MySQL engine
mysql_engine = create_mysql_engine("mysql_db")
# Create an MSSQL engine
mssql_engine = create_mssql_engine("mssql_db")
# Create a PostgreSQL engine
postgres_engine = create_postgres_engine("postgres_db")
Function Parameters
- create_mysql_engine(db_identifier): Creates a MySQL engine based on the
.iniconfiguration. - create_mssql_engine(db_identifier): Creates an MSSQL engine using the specified
.inisection. - create_postgres_engine(db_identifier): Creates a PostgreSQL engine per
.iniconfiguration.
Testing Connections
Run test_db_engine_factory from the command line to test connections to all configured databases with a simple SELECT 1 query.
test_db_engine_factory
This outputs success or error messages for each database connection attempt, confirming if .ini configurations are correct.
AI Assistance Prompt
If you need help from an AI assistant, use this example prompt:
"I'm using
DB Engine Factoryto connect to MySQL, MSSQL, and PostgreSQL databases, configured in a.inifile under sections like[mysql_db],[mssql_db], and[postgres_db]. I use functions likecreate_mysql_engine(db_identifier),create_mssql_engine(db_identifier), andcreate_postgres_engine(db_identifier). Could you help troubleshoot any connection issues or verify query results?"
Running Tests
The package includes a test script for verifying database connections defined in the .ini file.
- Confirm
.inifile is correctly configured. - Run the test command:
test_db_engine_factory
This script connects to each database and runs a SELECT 1 query, displaying connection results in the console.
Contributing
To contribute:
- Fork the repository.
- Create a branch (
git checkout -b feature/YourFeature). - Commit your changes (
git commit -m 'Add a new feature'). - Push to the branch (
git push origin feature/YourFeature). - Open a pull request.
If you encounter issues or have suggestions, please open an issue on GitHub.
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
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 db_engine_factory-0.1.2.tar.gz.
File metadata
- Download URL: db_engine_factory-0.1.2.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdfaccc938310e9228b3d78ec1057f60f550088a0a6b783d43218ff08868b8e7
|
|
| MD5 |
3c84dc959eeefe326d12eb6e9be481f5
|
|
| BLAKE2b-256 |
24b865e8905ff10a6d8b97d0ef753997213c5a7d3428f8412ed821963aac233b
|
File details
Details for the file db_engine_factory-0.1.2-py3-none-any.whl.
File metadata
- Download URL: db_engine_factory-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e075b6c09f25eca4806983df473c10bf186be5f47df9c803b08461a61384d9b
|
|
| MD5 |
8ca550b1475220bc9e8e6271e5e69bd2
|
|
| BLAKE2b-256 |
6ce3c4c25029e1f2250e38fd8861253ac382610be64c83df016aff485c04d406
|