Skip to main content

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:

  1. Fork the Repository: Fork Flask-RealTimeAnalytics on GitHub.
  2. Create a Branch: Create a feature or bugfix branch (git checkout -b feature/new-feature).
  3. Make Changes: Implement your changes, ensuring code style consistency (use black or flake8).
  4. Write Tests: Add or update tests in tests/ using pytest.
  5. Commit Changes: Write clear commit messages (e.g., "Add support for X feature").
  6. Submit a Pull Request: Open a pull request with a detailed description of your changes.
  7. 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:

  1. Clone the repository:
git clone https://github.com/yourusername/flask-realtime-analytics.git
cd flask-realtime-analytics
  1. Create and activate a virtual environment:
python3.12 -m venv .venv
source .venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Run tests:
pytest tests/
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_realtimeanalytics-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_realtimeanalytics-0.1.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

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

Hashes for flask_realtimeanalytics-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2209fd1eab0ccac45fa4386cc44379ef0145967eeb4db719d4eb1dafbf74a718
MD5 f9e9d0924a4703f432dc1d548a54f265
BLAKE2b-256 33f818925bb8a7336d6a86b6205c779d9503bdd130766ca8b0edfee94fa77eb1

See more details on using hashes here.

File details

Details for the file flask_realtimeanalytics-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_realtimeanalytics-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99982c4c95db74db6d868a56e8d0011c58ba410076f070340873c20e4c1bddea
MD5 e85113d42bde78339523aa230646e1e0
BLAKE2b-256 8e497ae1f4b53284b282def89612d74b8e75f907702f9d1c82d334ae9f58957a

See more details on using hashes here.

Supported by

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