Skip to main content

A high-level database connector for MariaDB

Project description

TonyDBC

Latest version: 1.0.7

Available on PyPI: https://pypi.org/project/tonydbc/

2024-01-07: Release announcement on Medium

Supports high-level database operations within Python. TonyDBC is short for Tony’s Database Connector, named for Maria’s lover in West Side Story.

TonyDBC uses the MariaDB/Connector but adds these features:

  • Support for the object-oriented context manager design pattern, which automatically closes connections.
  • A way to convert between pandas DataFrames and MariaDB tables, including serialization of complex data types like dictionaries and numpy arrays.
  • A way to autoresume when the connection is lost.
  • Support for fast INSERT and UPDATE from DataFrame.to_sql. Currently pandas’ implemention using sqlalchemy is 300x slower.
  • A way to quickly and automatically clone a database from a DDL script and copy the contents from the production database.
  • Batch INSERT and UPDATE offline and resume when Internet is available.
  • Logging database actions using the standard logging module.
  • In a CI/CD context, automatically connecting to the correct production or test database.
  • Support for the np.Int64Dtype data type.
  • Support for pandas timestamps.
  • Able to bulk insert data containing NULLs

Installation

To install TonyDBC from PyPI:

pip install tonydbc

Usage

A typical use case:

from tonydbc import TonyDBC, load_dotenvs

load_dotenvs()

sql_params = {
    "host": os.environ["MYSQL_HOST"],
    "user": os.environ["MYSQL_USER"],
    "password": os.environ["MYSQL_PASSWORD"],
    "database": os.environ["MYSQL_DATABASE"],
    "port": int(os.environ["MYSQL_PORT"]),
}

with TonyDBC(**sql_params) as db:
    # Do stuff
    pass

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

tonydbc-1.0.7.tar.gz (28.7 kB view hashes)

Uploaded Source

Built Distribution

tonydbc-1.0.7-py3-none-any.whl (30.2 kB view hashes)

Uploaded Python 3

Supported by

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