Skip to main content

Wrapper for mysql.connector.python to get a pool of mysql connections

Project description

flask_mysqlpool

This package allows you to use mysql-connector-pythons pooling feature from flask

Usage

import mysql.connector
from flask import Flask, abort, jsonify
from flask_mysqlpool import MySQLPool

app = Flask(__name__)
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_PORT'] = 3306
app.config['MYSQL_USER'] = 'test'
app.config['MYSQL_PASS'] = 'test'
app.config['MYSQL_DB'] = 'world_x'
app.config['MYSQL_POOL_NAME'] = 'mysql_pool'
app.config['MYSQL_POOL_SIZE'] = 5
app.config['MYSQL_AUTOCOMMIT'] = True

db = MySQLPool(app)

@app.route('/')
def index():
    try:
        conn = db.connection.get_connection()  # get connection from pool
        cursor = conn.cursor(dictionary=True)
        cursor.execute("select * from world_x.city limit 10", )
        result = cursor.fetchall()
        conn.close()  # return connection to pool
        return jsonify(result)
    except mysql.connector.ProgrammingError as err:
        print(err)
        abort(500)

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_mysqlpool-1.0.5.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

flask_mysqlpool-1.0.5-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

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