Django Session Space Analysis Tool
This is a Django management command (as in https://docs.djangoproject.com/en/dev/howto/custom-management-commands/) that analyzes and reports on the size of sessions in the DB. It is intended to make it easier to understand how much space session data takes up.
Why?
I noticed that a relatively small number of sessions in my Django app were consuming 50+KiB of data each, and wanted to understand why. It isn’t feasible or appealing to analyze large numbers of Django sessions by hand, and I couldn’t find any existing tools that did batch analysis, so I wrote this tool.
Installation
Install the distribution from PyPI, e.g. pip install django-analyze-sessions
Then, add analyze_sessions to INSTALLED_APPS in your Django project.
That’s it. You can now run django-admin.py and confirm that the command shows up.
Example Uses
Break down the space usage of all sessions with more than 15KB of session data::
django-admin.py analyze-sessions --bigger-than=15000
Processed 2 sessions out of 5125 total sessions
Average size was 16885.50 bytes
Saw the following keys:
foo (2 times, avg. size 15723.00 bytes)
bar (2 times, avg. size 618.50 bytes)
baz (2 times, avg. size 211.50 bytes)
Break down the space usage of all sessions whose keys are in the given input file (useful for when you want to select sessions on more than encoded size)::
django-admin.py analyze-sessions --ids-from=/tmp/ids-to-check
Processed 2 sessions out of 5125 total sessions
Average size was 16885.50 bytes
Saw the following keys:
foo (2 times, avg. size 15723.00 bytes)
bar (2 times, avg. size 618.50 bytes)
baz (2 times, avg. size 211.50 bytes)
Known Issues and Bugs
The custom WHERE clause used to filter on session size may only work on MySQL (I don’t have access to a Django installation on another DBMS, so I can’t vouch for how well it’ll work there).
The tool could stand to be smarter about size abbreviations (e.g., by learning how to interpret 100KB, or abbreviating output)
The packaging (such as it is) isn’t very good.
Metadata
Release files for django-analyze-sessions 0.1.1
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 | |
|---|---|---|---|---|
| django-analyze-sessions-0.1.1.tar.gz | 5.0 kB | Without provenance | Details |
Release files / django-analyze-sessions-0.1.1.tar.gz
| Download URL | django-analyze-sessions-0.1.1.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
abbb664ec13cb8dfb2632d0ebefbe358a515d54616d3f7b1902e6aa6c56bd9b4
|
|
BLAKE2b-256 checksum How to use checksums |
2b877425e07f0439294b3d6ee781523175a1a06a1778c8250a388d3b115b0180
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-analyze-sessions 0.1.1
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.