Skip to main content

A lightweight, production-grade, and asynchronous Python connector for MariaDB.

Project description

Async MariaDB Python Connector

PyPI version Python Version License: MIT Build Status

A lightweight, production-grade, and asynchronous Python connector for MariaDB, designed for high-performance data operations in modern AI/ML and web applications.


The Problem: MariaDB's Python Ecosystem Has a Performance Bottleneck

MariaDB is a powerful and reliable database, but the official Python connector (mariadb) operates synchronously. This means your application blocks and waits for every single query to finish, creating a massive performance bottleneck in modern, I/O-bound applications.

This is especially problematic for:

  • AI/ML Pipelines: Loading large datasets for training or performing bulk embedding inserts for RAG systems becomes slow and inefficient.
  • Web APIs: High-traffic web servers struggle to handle concurrent requests when each database call is a blocking operation.
  • Data Processing: Any workflow requiring many simultaneous database interactions is severely limited.

The Solution: A High-Level, Production-Ready Async Connector

This project, async-mariadb-connector, was built to solve this exact problem. It provides a high-level, asynchronous interface to MariaDB that is not only fast but also robust and easy to use.

While low-level async drivers like aiomysql exist, they lack the "batteries-included" features required for production environments. This library bridges that gap.

How Well Is It Built?

This is not just a simple wrapper. It is a complete, production-grade library with features designed for real-world use:

  • Truly Asynchronous: Built on asyncio to eliminate I/O blocking and enable massive concurrency.
  • Automatic Connection Pooling: Efficiently manages database connections for optimal performance, right out of the box.
  • Resilient by Design: Features automatic connection retries with exponential backoff, so your application can survive transient database or network issues.
  • Seamless Pandas Integration: Includes high-performance bulk_insert for DataFrames and fetch_all_df to move data effortlessly between your database and your data science tools.
  • Memory-Efficient Streaming: A fetch_stream method allows you to process huge datasets row-by-row, without risking memory overloads.
  • Professionally Tested: Comes with a comprehensive test suite (17 tests) ensuring reliability and correctness.

See the Performance for Yourself

Don't just take our word for it. The performance gains are measurable and significant.

Check out the detailed results in our Benchmarks to see how this connector is ~30% faster on concurrent read operations.

Strong MariaDB Integration

This library is specifically designed and tested for MariaDB:

  • Tested Against: MariaDB 11.8.3
  • Full Type Support: JSON, DECIMAL, utf8mb4 (emojis), TIMESTAMP, TEXT/LONGTEXT
  • Optimized For: Connection pooling, strict SQL mode, InnoDB transactions
  • Docker Ready: One-command setup with docker-compose up

For detailed MariaDB-specific features, configurations, and best practices, see MariaDB Integration Notes.

Future-Ready for AI and Modern Applications

This connector is designed for the future of data engineering and AI. The combination of non-blocking I/O, efficient bulk operations, and direct DataFrame integration makes it the ideal choice for:

  • Building high-performance RAG pipelines with vector embeddings stored in MariaDB.
  • Creating fast, scalable data APIs for web and mobile applications.
  • Powering ETL and data processing workflows that require high concurrency.

Installation

pip install async-mariadb-connector

(Note: This package is ready for PyPI but has not been published yet. To install locally, use pip install .)

Quick Start

First, spin up MariaDB with docker-compose:

docker-compose up -d

Then set up your .env file (copy from .env.example):

# .env
DB_HOST=127.0.0.1
DB_PORT=3307
DB_USER=root
DB_PASSWORD=root
DB_NAME=test_db

Now, you can connect and run queries asynchronously:

import asyncio
import pandas as pd
from async_mariadb_connector import AsyncMariaDB

async def main():
    db = AsyncMariaDB()

    try:
        # Fetch all users into a DataFrame
        all_users_df = await db.fetch_all_df("SELECT * FROM users")
        print("All users:")
        print(all_users_df)

    finally:
        await db.close()

if __name__ == "__main__":
    asyncio.run(main())

Connect with the Author

This project was created by Chanikya Nelapatla.

License

This project is licensed under the MIT License.

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

async_mariadb_connector-0.1.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

async_mariadb_connector-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file async_mariadb_connector-0.1.0.tar.gz.

File metadata

  • Download URL: async_mariadb_connector-0.1.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/44.0 requests/2.32.5 requests-toolbelt/1.0.0 urllib3/2.5.0 tqdm/4.67.1 importlib-metadata/8.6.1 keyring/25.6.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.11.3

File hashes

Hashes for async_mariadb_connector-0.1.0.tar.gz
Algorithm Hash digest
SHA256 53d6ef8bee29de68af215cbcca132afc7cb5474049a460163b12a123c55bc78f
MD5 4e137489068c15d2bcad3064678381d5
BLAKE2b-256 e3947539327a90adc532c3620aac23ae2a63a71ad09b8656b89d65ac9f14c2c9

See more details on using hashes here.

File details

Details for the file async_mariadb_connector-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: async_mariadb_connector-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/44.0 requests/2.32.5 requests-toolbelt/1.0.0 urllib3/2.5.0 tqdm/4.67.1 importlib-metadata/8.6.1 keyring/25.6.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.11.3

File hashes

Hashes for async_mariadb_connector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4af815819898ed8b07ea76e9b2b4a2134d185ddadf3d14583f6661a63332ba96
MD5 ef0461e8ae214ba357d17fd1dc401e67
BLAKE2b-256 10c45b63f6cd36c9f10f13299d6b64d34d9b70fddb19e0bd894ec2d661b4ac6f

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