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
Metadata
Release files for flask-view-counter 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| flask-view-counter-0.1.2.tar.gz | 3.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flask_view_counter-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.7 kB
Release files / flask-view-counter-0.1.2.tar.gz
| Download URL | flask-view-counter-0.1.2.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8ba980dbf21d4f860236da99660f1ef69ee99b4dd46f3dd3e95d182db4f4ea5
|
|
BLAKE2b-256 checksum How to use checksums |
e45becef9595a4cd8aea3ca45835bc3471a783bd1a8eb1b827d7a807e9e4e253
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / flask_view_counter-0.1.2-py3-none-any.whl
| Download URL | flask_view_counter-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66d44c73bfe83fcdeee706bb25f92b0f8291d0084be0df78703d4909d5568a54
|
|
BLAKE2b-256 checksum How to use checksums |
ce91fdb8d5fb9da3a753e8ef99f8972e95a0f3cfbac085a02d33f7bce7e8ce0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for flask-view-counter 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.