database-factory-1.0.5


توضیحات

Database Factory;
ویژگی مقدار
سیستم عامل OS Independent
نام فایل database-factory-1.0.5
نام database-factory
نسخه کتابخانه 1.0.5
نگهدارنده []
ایمیل نگهدارنده []
نویسنده Ankit Shrivastava
ایمیل نویسنده -
آدرس صفحه اصلی https://github.com/shrivastava-v-ankit/database-factory
آدرس اینترنتی https://pypi.org/project/database-factory/
مجوز MIT
# database-factory [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![PyPI](https://img.shields.io/pypi/v/database-factory.svg)](https://pypi.org/project/database-factory) [![CircleCI](https://circleci.com/gh/shrivastava-v-ankit/database-factory.svg?style=svg)](https://circleci.com/gh/shrivastava-v-ankit/database-factory) Database factory is used to manage/create database connection with execute queries using the connection. The concept of having single source to connect various databases and perform database operations. User need not to worry on the crafting the connection string and to identify the methods for the database operations. Database factory supports DML / DDL executions and have support of Pandas DataFrame to create or replace existing tables. Database factory is wrapper on sqlalchemy for crafting the connection and supports below databases: ```bash * Sqlite3 * PostgreSQl * BigQuery * Snowflake * MariaDB * MySQL ``` Database factory can be enhanced for all the sqlalchemy supported database. ## Getting Started ```bash pip install database-factory ``` ### Using database-factory ----- ```python from database_factory.manager import DatabaseManager import tempfile temp_dir = tempfile.gettempdir() db = DatabaseManager(engine_type="sqlite", database="test_db", sqlite_db_path=temp_dir) db.create_session() db.execute_sql(sql="create table test (id int PRIMARY KEY)") db.execute_sql(sql="insert into test values (1)") db.execute_sql(sql="insert into test values (2)") rows = db.execute_sql(sql="select * from test") if rows: print(rows) df = db.get_df(sql="select * from test") print(df) db.execute_df(panda_df=df, table_name=copy_test, exist_action="replace") # db.execute_df(panda_df=df, table_name=copy_test, exist_action="replace", chunk_size=100) db.execute_sql(sql="insert into copy_test values (3)") rows_copy = db.execute_sql(sql="select * from copy_test") if rows_copy: print(rows_copy) ``` ## Appendix ### Supported database type: ---- ``` * sqlite `default` * postgres * mysql * mariadb * snowflake ``` ### Connection parameters for sqlite: ----- ```python * engine_type: sqlite * database: <name of database> * sqlite_db_path: <path where database will be created> ``` ### Connection parameters for postgres: ----- ```python * engine_type: postgres * database: <name of database> * username: <postgres user> * password: <user password> * host: <host of postgres service> * port: <port of postgres service> ``` ### Connection parameters for mysql: ----- ```python * engine_type: mysql * database: <name of database> * username: <mysql user> * password: <user password> * host: <host of mysql service> * port: <port of mysql servic\> ``` ### Connection parameters for mariadb: ----- ```python * engine_type: mariadb * database: <name of database> * username: <mariadb user> * password: <user password> * host: <host of mariadb service> * port: <port of mariadb service> ``` ### Connection parameters for snowflake: ----- ```python * engine_type: snowflake * database: <name of database> * username: <snowflake user> * password: <user password> * schema: <schema name> * snowflake_role: <snowflake role> * snowflake_warehouse: <snowflake warehouse> * snowflake_account: <snowflake account> ``` ### Connection parameters for bigquery: ----- ```python * engine_type: bigquery * database: <name of database> ``` ### Getting connection properties from AWS / GCP Secret Manager Service: ----- Note: * GCP: * On Cloud Server: * Set server to execute the all cloud api services * Attach following permissions * Project Viewer * Secret Manager Secret Accessor * On Premises: * Attach following permissions to user service account and download service account file for authentication: * Project Viewer * Secret Manager Secret Accessor * Set environment variable "GOOGLE_APPLICATION_CREDENTIALS" pointing to service account file. * AWS: * On Cloud Server: * Set execution profile with "secretsmanager:GetSecretValue" policy * On Premises: * AWS should be configured * User should have permissions of "secretsmanager:GetSecretValue" policy. ```python * engine_type: bigquery * database: <name of database> * secret_id: <Secret name of AWS / GCP Secret Manager Service> * secrete_manager_cloud: <aws or gcp as per cloud> * aws_region: <aws region: default=> us-east-1> ``` ### Development Setup #### Using virtualenv ```bash python3 -m venv venv source env/bin/activate pip install . ``` ### Contributing 1. Fork repo- https://github.com/shrivastava-v-ankit/database-factory.git 2. Create your feature branch - `git checkout -b feature/name` 3. Add Python test (pytest) and covrage report for new/changed feature. 4. Commit your changes - `git commit -am "Added name"` 5. Push to the branch - `git push origin feature/name` 6. Create a new pull request


نیازمندی

مقدار نام
==1.4.47 sqlalchemy
==1.5.3 pandas
==1.26.113 boto3
==2.17.3 google-auth
==0.1.0 google-auth-httplib2
==3.9.0 google-cloud-bigquery
==2.85.0 google-api-python-client
==2.16.1 google-cloud-secret-manager
==1.9.1 google-cloud-resource-manager
==0.10.2 pybigquery
==2.7.9 snowflake-connector-python
==1.4.7 snowflake-sqlalchemy
==1.29.4 pg8000
- pymysql
==1.5.1 asn1crypto
==1.29.113 botocore
==5.3.0 cachetools
==2022.12.7 certifi
==1.15.1 cffi
==2.0.12 charset-normalizer
==36.0.2 cryptography
==0.18.3 future
==2.11.0 google-api-core
==2.19.1 google-cloud-bigquery-storage
==2.3.2 google-cloud-core
==1.5.0 google-crc32c
==2.4.1 google-resumable-media
==1.59.0 googleapis-common-protos
==2.0.2 greenlet
==0.12.6 grpc-google-iam-v1
==1.53.0 grpcio
==0.22.0 httplib2
==3.4 idna
==1.0.1 jmespath
==1.24.2 numpy
==1.3.0 oscrypto
==23.1 packaging
==1.22.2 proto-plus
==4.22.3 protobuf
==6.0.1 pyarrow
==0.4.8 pyasn1
==0.2.8 pyasn1-modules
==2.21 pycparser
==3.17 pycryptodomex
==2.6.0 pyjwt
==1.0.3 pymysql
==22.0.0 pyopenssl
==3.0.9 pyparsing
==2.8.2 python-dateutil
==2023.3 pytz
==2.28.2 requests
==4.9 rsa
==0.6.0 s3transfer
==1.4.4 scramp
==1.16.0 six
==4.1.1 uritemplate
==1.26.15 urllib3


زبان مورد نیاز

مقدار نام
>=3.4 Python


نحوه نصب


نصب پکیج whl database-factory-1.0.5:

    pip install database-factory-1.0.5.whl


نصب پکیج tar.gz database-factory-1.0.5:

    pip install database-factory-1.0.5.tar.gz