Skip to main content

A Flask mysql pool extension based on DBUtils

Project description

Flask-MySQLPooled

Flask-MySQLPooled is a Flask extension that allows you to access a MySQL database by connection pool.

Installation

Flask-MySQLPooled can be installed in the usual way:

python setup.py install

It is even easier to download and install the package in one go using pip:

pip install Flask-MySQLPooled

Configuration

Flask-MySQLPooled provides these settings:

name default value remarks
MySQLPooled_DATABASE_HOST ‘localhost’
MySQLPooled_DATABASE_PORT 3306
MySQLPooled_DATABASE_USER None
MySQLPooled_DATABASE_PASSWORD None
MySQLPooled_DATABASE_DB None
MySQLPooled_DATABASE_CHARSET 'utf8'
MySQLPooled_USE_UNICODE True
MySQLPooled_DATABASE_SOCKET None
MySQLPooled_SQL_MODE None
MySQLPooled_MINCACHED 0
MySQLPooled_MAXCACHED 1
MySQLPooled_MAXCONNECTIONS 1
MySQLPooled_BLOCKING False
MySQLPooled_MAXUSAGE None
MySQLPooled_SETSESSION None
MySQLPooled_RESET True
MySQLPooled_FAILURES None
MySQLPooled_PING 1

Usage

Initialize the extension:

from flask_mysqlpooled import MySQLPooled
    
mysql_pool = MySQLPooled()
mysql_pool.init_app(app)
# or
mysql_pool = MySQLPooled(app)

Obtain a cursor:

cursor = mysql_pool.get_db().cursor()

Multiple connection example:

import pymysql
from flask import Flask
from flask_mysqlpooled import MySQLPooled

app = Flask(__name__)

mysql_pool_1 = MySQLPooled(app,
                        prefix='MySQLPooled1',
                        host='host1',
                        user='user1',
                        password='password1',
                        db='db1',
                        autocommit=True,
                        cursorclass=pymysql.cursors.DictCursor,
                        mincached=0,
                        maxcached=3)
mysql_pool_2 = MySQLPooled(app,
                        prefix='MySQLPooled2',
                        host='host2',
                        user='user2',
                        password='password2',
                        db='db2',
                        autocommit=True,
                        cursorclass=pymysql.cursors.DictCursor,
                        mincached=0,
                        maxcached=3)

@app.route('/')
def index():
    cursor1 = mysql_pool_1.get_db().cursor()
    cursor2 = mysql_pool_2.get_db().cursor()
    # ...

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

Flask-MySQLPooled-0.1.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

Flask_MySQLPooled-0.1.1-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file Flask-MySQLPooled-0.1.1.tar.gz.

File metadata

  • Download URL: Flask-MySQLPooled-0.1.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.2

File hashes

Hashes for Flask-MySQLPooled-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9585c904ffcd0cbd9a0fbe541cde787cbe6a5d27e9b03806e29ec805d2faa6d7
MD5 e4e46ef6a5d0a02074dda0f82f475a79
BLAKE2b-256 cf1d661850de899ffe2456aa8f611a200834d5eff6067a553c3677d607fd31f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Flask_MySQLPooled-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.2

File hashes

Hashes for Flask_MySQLPooled-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 38415b90ad555cfdc5b1d3bc40f0adcb6e7d0ee66178284e81bf7c52c78becfb
MD5 bf42904dd6c29c2c8043ab7ad396b67a
BLAKE2b-256 359c81d8eb1aeeb1a57220681aedb7061cc72ab30d0069cb068a1701ea0235e6

See more details on using hashes here.

Supported by

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