A Flask extension for real-time analytics dashboards
Project description
Flask-RealTimeAnalytics
A Flask extension for real-time analytics dashboards, tracking user behavior, API usage, and performance metrics with WebSocket updates. Integrates seamlessly with SQLAlchemy-supported databases.
Features
- Real-time tracking of requests, response times, and user data.
- WebSocket-powered dashboard for live analytics.
- Database-agnostic (PostgreSQL, MySQL, SQLite, etc.) via SQLAlchemy.
- Easy integration with existing Flask applications.
Installation
Install via pip:
pip install Flask-RealTimeAnalytics
Setup
Prerequisites
- Python 3.8+ (Tested up to 3.12)
- Flask 3.1.0+
- SQLAlchemy 2.0.40+ (e.g., via Flask-SQLAlchemy)
- A configured database (PostgreSQL, MySQL, SQLite, etc.)
Inline Flask Setup
For simple Flask applications without an application factory:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_realtime_analytics import FlaskRealTimeAnalytics
app = Flask(__name__, template_folder='flask_realtime_analytics/templates')
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://user:pass@localhost/dbname'
db = SQLAlchemy(app)
analytics = FlaskRealTimeAnalytics(app, db)
@app.route('/')
def index():
return 'Hello, World!'
if __name__ == '__main__':
analytics.socketio.run(app, debug=True)
Visit /analytics to view the real-time dashboard.
Application Factory Setup
For Flask applications using the application factory pattern (create_app()):
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_realtime_analytics import FlaskRealTimeAnalytics
db = SQLAlchemy()
analytics = FlaskRealTimeAnalytics()
def create_app():
app = Flask(__name__, template_folder='flask_realtime_analytics/templates')
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://user:pass@localhost/dbname'
db.init_app(app)
analytics.init_app(app, db)
@app.route('/')
def index():
return 'Hello, World!'
return app
if __name__ == '__main__':
app = create_app()
with app.app_context():
db.create_all() # Create tables
FlaskRealTimeAnalytics(app, db).socketio.run(app, debug=True)
Visit /analytics to view the real-time dashboard.
Configuration
- Database: Ensure SQLALCHEMY_DATABASE_URI is set to your database (e.g., postgresql://user:pass@localhost/dbname or sqlite:///analytics.db).
- Templates: Place analytics.html (included in the package) in your Flask template_folder.
- SocketIO: Runs with analytics.socketio.run() instead of app.run() to support WebSockets.
Documentation
Full documentation is available on ReadTheDocs.
Contributing
We welcome contributions! Follow these steps to contribute:
- Fork the Repository: Fork Flask-RealTimeAnalytics on GitHub.
- Create a Branch: Create a feature or bugfix branch (git checkout -b feature/new-feature).
- Make Changes: Implement your changes, ensuring code style consistency (use black or flake8).
- Write Tests: Add or update tests in tests/ using pytest.
- Commit Changes: Write clear commit messages (e.g., "Add support for X feature").
- Submit a Pull Request: Open a pull request with a detailed description of your changes.
- Report Issues: Submit bugs or feature requests via GitHub Issues.
Please follow the Code of Conduct and ensure your contributions align with the project's MIT License.
Development
To set up a development environment:
- Clone the repository:
git clone https://github.com/yourusername/flask-realtime-analytics.git
cd flask-realtime-analytics
- Create and activate a virtual environment:
python3.12 -m venv .venv
source .venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Run tests:
pytest tests/
- Build documentation:
cd docs && make html
License
This project is licensed under the MIT License.
Acknowledgements
Built with Flask, Flask-SocketIO, and SQLAlchemy. Inspired by the Flask community's open-source contributions.
Contact
For questions or support, open an issue on GitHub or reach out via tony.rolfe@ibm.com.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_realtimeanalytics-0.1.0.tar.gz.
File metadata
- Download URL: flask_realtimeanalytics-0.1.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2209fd1eab0ccac45fa4386cc44379ef0145967eeb4db719d4eb1dafbf74a718
|
|
| MD5 |
f9e9d0924a4703f432dc1d548a54f265
|
|
| BLAKE2b-256 |
33f818925bb8a7336d6a86b6205c779d9503bdd130766ca8b0edfee94fa77eb1
|
File details
Details for the file flask_realtimeanalytics-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flask_realtimeanalytics-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99982c4c95db74db6d868a56e8d0011c58ba410076f070340873c20e4c1bddea
|
|
| MD5 |
e85113d42bde78339523aa230646e1e0
|
|
| BLAKE2b-256 |
8e497ae1f4b53284b282def89612d74b8e75f907702f9d1c82d334ae9f58957a
|