Business intelligence · Python · live
NEWT Customer Dashboard
A Flask business-intelligence dashboard over Fibernetics' billing database that turns raw invoice line-items into revenue and growth insight. Backend engineering: every query is parameterized against injection, results are paginated, and the CSV export uses a server-side cursor so it streams in constant memory no matter how large the result set. Login-gated and deployed on Mosaic.
app.py — streaming CSV export ›
# Exports can be huge, so stream them: a server-side cursor keeps the # result set on MySQL's side and we yield one CSV row at a time. @app.get('/api/invoices/download') def download(): where_sql, params = build_where(request.args) # parameterized · injection-safe def generate(): buf = io.StringIO(); writer = csv.writer(buf) writer.writerow(COLUMNS); yield buf.getvalue() conn = get_connection(cursorclass=pymysql.cursors.SSCursor) with conn.cursor() as cur: cur.execute(f'SELECT {COLUMN_LIST_SQL} FROM FSFEN{where_sql}', params) for row in cur: # streamed from the server buf.seek(0); buf.truncate(0) writer.writerow(row); yield buf.getvalue() return Response(generate(), mimetype='text/csv')