Easy to use MySQL client for Flask apps.
Project description
Flask-MySQL-Connector
Easy to use MySQL client for Flask apps.
from flask import Flask
from flask_mysql_connector import MySQL
app = Flask(__name__)
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_DATABASE'] = 'sys'
mysql = MySQL(app)
EXAMPLE_SQL = 'select * from sys.user_summary'
# using the new_cursor() method
@app.route('/new_cursor')
def new_cursor():
cur = mysql.new_cursor(dictionary=True)
cur.execute(EXAMPLE_SQL)
output = cur.fetchall()
return str(output)
# using the connection property
@app.route('/connection')
def connection():
conn = mysql.connection
cur = conn.cursor()
cur.execute(EXAMPLE_SQL)
output = cur.fetchall()
return str(output)
# using the execute_sql() method to easily
# select sql and optionally output to Pandas
@app.route('/easy_execute')
def easy_execute():
df = mysql.execute_sql(EXAMPLE_SQL, to_pandas=True)
return str(df.to_dict())
if __name__ == '__main__':
app.run(debug=True)
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
Close
Hashes for flask_mysql_connector-1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb36ecd5f2c061d5a7cc355f5d07c808f72e13f821317745a88414a5097d6a4e |
|
MD5 | ebfbf8b828961555b469e4f6b4ffee01 |
|
BLAKE2b-256 | c2f38c27165142dc709449f00ae8f5458006ab6ea4df34eaca46a899ff917388 |