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 Downloads

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

The package is now available on PyPI: https://pypi.org/project/async-mariadb-connector/

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.1.tar.gz (15.7 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.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: async_mariadb_connector-0.1.1.tar.gz
  • Upload date:
  • Size: 15.7 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.1.tar.gz
Algorithm Hash digest
SHA256 4f0ec8e040119802e348db5208eb99bc47fec0dae43f57b128b2686e9b1f0cc0
MD5 43877f6b5824c087b2b573a785176fe7
BLAKE2b-256 462e7530f5720af691478a401f1439fb13d4a7ef87807b0e5c16d8d9807585e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: async_mariadb_connector-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1e14b8f86e27169e2a5298aec1203d174b0d031d0ade418eff547ea6d5e4254a
MD5 ee864a8dea9ed9933fbcc50212964df1
BLAKE2b-256 628be2749a9d9fe5dbc0a14c096a41e05e49e27321641ce52cb3661942bb68cc

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