Skip to main content

This Is MySQL Package That You Can Save DataFrame As Table, Partition, Update , Primarykey And Unique In MySQL

Project description

logo MySqlSaver

Effortlessly save your pandas DataFrames into MySQL with automatic table creation and support for primary keys and partitioning.

GitHub


Installation

pip install mysqlsaver

Connection

Create a connection to your MySQL database:

from mysqlSaver import Connection

conn = Connection.connect(
    host="your_host",
    port="your_port",
    username="your_username",
    password="your_password",
    database="your_database"
)

Keys Manager

from mysqlSaver import KeyManager

key_mgr = KeyManager(conn)


key_mgr.add_primary_key('my_table', ['id'])

key_mgr.drop_primary_key('my_table')


key_mgr.add_unique_key('my_table', ['email' , 'name'])

key_mgr.drop_unique_key('my_table', 'unique_email_name')
  • Create the primarykey or unique fields
  • Drop the primarykey or unique fields

Save a DataFrame

from mysqlSaver import Saver
import pandas as pd

df = pd.DataFrame({...})
saver = Saver(conn)
saver.sql_saver(df, "table_name")

This function:

  • Creates the table if it does not exist
  • Inserts the DataFrame data

Save with Primary Key

saver.sql_saver_with_primarykey(df, "table_name", primary_key_list=["id"])

Save with Primary Key and Auto-Update

saver.sql_saver_with_primarykey_and_update(df, "table_name", primary_key_list=["id"])

This performs UPSERT using the primary key.

Save with Unique Key (No Duplicate Insertions)

saver.sql_saver_with_unique_key(df, "table_name")

Update Table Based on Primary Key

saver.sql_updater_with_primarykey(df, "table_name", primary_key_list=["id"])

Checker and Reader

from mysqlSaver import CheckerAndReceiver

checker = CheckerAndReceiver(conn)
exists = checker.table_exist("table_name")
df = checker.read_table("table_name")

Table and Database Creation

from mysqlSaver import Creator

creator = Creator(conn)
creator.database_creator("new_database")
creator.create_table(df, "new_table")

Partitioning Tables

from mysqlSaver import Partition

partitioner = Partition(conn)
partitioner.create_partition_table(
    df,
    "partitioned_table",
    range_key="your_date_column",
    primary_key_list=["id"],
    start_year_partition=2020,
    end_year_partition=2025
)

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

mysqlSaver-0.2.7.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file mysqlSaver-0.2.7.tar.gz.

File metadata

  • Download URL: mysqlSaver-0.2.7.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for mysqlSaver-0.2.7.tar.gz
Algorithm Hash digest
SHA256 a7f7f45756a3b6e601de29e5c4644c86b173551def525f1cc7f08dc1b7140149
MD5 de1311f89a673f9a85f4f4afa2ab4783
BLAKE2b-256 7dd647a2c9d58386be2208e5d975cbbc2599b144c309ec6998f10e8632db45a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page