Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

mariadb-pool

mariadb-pool is the connection pooling add-on for the mariadb connector. It provides synchronous and asynchronous connection pools with automatic connection management, health checking, and monitoring.

Installation

Install MariaDB Connector/Python with pool support:

pip install mariadb[pool]

Or install the pool package separately:

pip install mariadb-pool

Features

  • Easy Connection Management: Automatic connection pooling via mariadb.ConnectionPool
  • URI Support: Create pools with connection URIs for clean configuration
  • Dynamic Pool Sizing: Automatically adjusts between min and max connections
  • Connection Health Checking: Periodic validation of idle connections
  • Thread-Safe: Fully thread-safe for multi-threaded applications
  • Pool Statistics: Monitor pool usage and performance
  • Context Manager Support: Clean connection handling with with statements

Quick Start

Synchronous Connection Pool

The cleanest way to create a connection pool with separated pool and connection parameters:

import mariadb

# Create pool with clean parameter separation
pool = mariadb.create_pool(
    host="localhost",
    port=3306,
    user="root",
    password="password",
    database="mydb",
    min_size=5,
    max_size=10,
    ping_threshold=0.25,  # Only ping connections idle > 250ms
    max_idle_time=600.0,
    reset_connection=True
)

# Get connection from pool
with pool.acquire() as conn:
    with conn.cursor() as cursor:
        cursor.execute("SELECT * FROM users")
        results = cursor.fetchall()

# Close pool when done
pool.close()

Using ConnectionPool Constructor

Alternatively, use the traditional constructor:

import mariadb

# Create pool with connection parameters
pool = mariadb.ConnectionPool(
    pool_name="mypool",
    host="localhost",
    port=3306,
    user="root",
    password="password",
    database="mydb",
    max_size=10,
    pool_reset_connection=True
)

# Use context manager to ensure connection is returned to pool
with pool.get_connection() as conn:
    with conn.cursor() as cursor:
        cursor.execute("SELECT * FROM users")
        results = cursor.fetchall()

pool.close()

Asynchronous Connection Pool

The cleanest way to create an async pool - automatically pre-filled and ready to use:

import mariadb
import asyncio

async def main():
    # Create async pool with clean parameter separation
    # Pool is automatically opened and pre-filled with connections
    pool = await mariadb.create_async_pool(
        host="localhost",
        port=3306,
        user="root",
        password="password",
        database="mydb",
        min_size=5,
        max_size=20,
        ping_threshold=0.25,  # Only ping connections idle > 250ms
        max_idle_time=600.0,
        reset_connection=True
    )
    
    # Acquire connection from pool
    async with await pool.acquire() as conn:
        async with conn.cursor() as cursor:
            await cursor.execute("SELECT * FROM users")
            results = await cursor.fetchall()
    
    # Close pool if unneeded anymore
    await pool.close()

asyncio.run(main())

Pool Configuration Options

The pool accepts the following configuration parameters:

Pool-Specific Parameters

Parameter Type Default Description
min_size int 10 Minimum number of connections to maintain
max_size int 10 Maximum number of connections allowed (max: 64)
max_idle_time float 600.0 Maximum idle time (seconds) before closing connection
max_lifetime float 3600.0 Maximum lifetime (seconds) of a connection
validation_interval float 30.0 Interval (seconds) between connection validations
acquire_timeout float 30.0 Timeout (seconds) when acquiring a connection
enable_health_check bool True Enable periodic health checks on idle connections
reset_connection bool False Reset connection state when returned to pool
ping_threshold float 0.25 Only ping connections idle > threshold seconds (0 = always ping)

Performance Tip: The ping_threshold option significantly improves performance by avoiding unnecessary database pings. Connections that have been idle for less than the threshold (default: 250ms) are assumed healthy and returned immediately. Only connections idle longer than the threshold are verified with a ping. Set to 0 to ensure checking connection states.

Note: If you set only min_size or only max_size (without setting the other), both will be set to the same value to create a fixed-size pool.

mariadb.ConnectionPool Parameters

Additional parameters supported by mariadb.ConnectionPool:

Parameter Type Default Description
pool_name str Required Unique name for the pool
pool_reset_connection bool True Alias for reset_connection (mapped by wrapper)
pool_validation_interval float - Alias for validation_interval (mapped by wrapper)

Metadata

Release files for mariadb-pool 2.0.0rc2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mariadb-pool 2.0.0rc2
File Size Uploaded Provenance
mariadb_pool-2.0.0rc2.tar.gz 11.0 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mariadb-pool 2.0.0rc2
File Interpreter ABI Platform
mariadb_pool-2.0.0rc2-py3-none-any.whl Python 3 none any Details

Total release size: 45.7 kB

Release files / mariadb_pool-2.0.0rc2.tar.gz

Download URL mariadb_pool-2.0.0rc2.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1a70946c87647e1eb607585ceba82790c6697c6c8b2edff398c2e2b699a6984a
BLAKE2b-256 checksum
How to use checksums
51a47b1956b0f65240f229ed93f865b9ae0fca101939739e53e850250d037f6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 4, 2026.

Transparency log

Release files / mariadb_pool-2.0.0rc2-py3-none-any.whl

Download URL mariadb_pool-2.0.0rc2-py3-none-any.whl
Size 34.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
530d10579939f20472d79cc762772a84fdbb061cdf4c66e9ccd9a774b7f05f56
BLAKE2b-256 checksum
How to use checksums
2090e5fe0d92f3b6c67d1d307809924ce9e0c7daa3969f2dc8957b9ead0ae7a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 4, 2026.

Transparency log

Security for mariadb-pool 2.0.0rc2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mariadb_pool-2.0.0rc2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page