Skip to main content

Adds lightweight request metrics to flask applications

Project description

flask-view-counter

Flask-view-counter is a simple addon for flask applications that lets you track pageloads. It requires flask-sqlalchemy (for now), so if you are already using it, you can get pageload metrics for free. Flask-view-counter provides a decorator for views that records information about the request. Additionally, tools for querying the generated data are provided. Display of the data is left as an exercise to the user, in order to keep dependencies (and the extension) as small and simple as possible. SQLAlchemy must of course be setup and configured properly.

Example usage

app.py

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_view_counter import ViewCounter

app = Flask(__name__)
app.config.from_object(select_config())

db = SQLAlchemy(app)

view_counter = ViewCounter(app, db)

from app import routes

routes.py

from app import app, view_counter

@app.route('/')
@view_counter.count
def index():
	return "Hello World"

Flask-view-counter will then record the decorated view, logging details about the user.

A word of caution, make sure you are decorating a view function, that is, the function which actually returns a valid wsgi response. The primary place you will encounter this is in calls to abort(). In this case, your "view" won't return anything at all, and instead the error handler will return the response. Consequently, if you want to know about this error (presumably you do!), then you must decorate a custom error handler function for that error code. I.E

@app.route(/imight400/<yes>/)
@viewcounter.count
def might400(yes):
	if yes == "yes":
		abort(400)  # When we abort here, viewcounter can't see what is 
					# happening, define a custom error handler if you want to
					# know about this
	return "OK!"

@app.errorhandler(400)
@viewcounter.count
def bad_request(e):
	# with the error handler decorated, flask-view-counter will record this
	# error. You can use any of the return formats that flask allows.
	return render_template("400.html", error=e), 400

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-view-counter-0.1.2.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

flask_view_counter-0.1.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file flask-view-counter-0.1.2.tar.gz.

File metadata

  • Download URL: flask-view-counter-0.1.2.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

File hashes

Hashes for flask-view-counter-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e8ba980dbf21d4f860236da99660f1ef69ee99b4dd46f3dd3e95d182db4f4ea5
MD5 65d117871f81127555e49a937943d883
BLAKE2b-256 e45becef9595a4cd8aea3ca45835bc3471a783bd1a8eb1b827d7a807e9e4e253

See more details on using hashes here.

File details

Details for the file flask_view_counter-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: flask_view_counter-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

File hashes

Hashes for flask_view_counter-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 66d44c73bfe83fcdeee706bb25f92b0f8291d0084be0df78703d4909d5568a54
MD5 1d657f5b6ce36e104578aa25b6704a7c
BLAKE2b-256 ce91fdb8d5fb9da3a753e8ef99f8972e95a0f3cfbac085a02d33f7bce7e8ce0d

See more details on using hashes here.

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