Create a connection pool and returns a connection pool object.

See also: MariaDB Connector/Python 1.0


A connection pool holds a number of open connections and handles thread safety when providing connections to threads.

The size of a connection pool is configurable at creation time, but cannot be changed afterwards. The maximum size of a connection pool is limited to 64 connections.

Threads using the pool fetch a connection via get_connection() and return it to the pool by calling close() on the connection (or using the default close on the object's destruction).

The connection parameters include all the keyword parameters that can be used with connect() as well as a few pool-specific parameters:


The name of the pool.


The number of connections that the pool can hold. The default when omitted is 5.


When set to True the connection is reset when close() is called (instead of just being returned to the pool without changes).


The following will create a connection pool object, then fetch a connection, use it, and return it to the pool:

import mariadb

pool = mariadb.ConnectionPool(
    pool_name = 'pool1',
    pool_size = 3,
    pool_reset_connection = False,
    host = '',
    user = 'root',
    password = 'secret',
    database = 'test',

# These would normally be allocated in separate threads:
conn1 = pool.get_connection()
conn2 = pool.get_connection()
conn3 = pool.get_connection()
# Attempting to fetch a 4th connection would throw an exception
# given the pool_size == 3 option above.

cursor = conn1.cursor()
cursor.execute('INSERT INTO sample VALUES (?, ?)', (1, 2))

cursor = conn2.cursor()
cursor.execute('INSERT INTO sample VALUES (?, ?)', (3, 4))

cursor = conn3.cursor()
cursor.execute('INSERT INTO sample VALUES (?, ?)', (5, 6))