Starlette-Flash
Flash messages for Starlette framework.
Installation
Install starlette_flash using pip or uv:
pip install starlette_flash
# or
uv add starlette_flash
Quick start
See example application in examples/ directory of this repository.
Setup
Flash messages are stored in the session. Add SessionMiddleware to your app:
from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.middleware.sessions import SessionMiddleware
app = Starlette(
middleware=[Middleware(SessionMiddleware, secret_key="your-secret-key")],
)
Flashing messages
To flash a message use the flash helper.
from starlette_flash import flash
def index_view(request):
flash(request).add('This is a message.', 'success')
Using helpers
Shorthand helpers that set the category automatically:
- success
- error
- info
- warning
- debug
from starlette_flash import flash
def index_view(request):
flash(request).success('Saved.')
flash(request).error('Something went wrong.')
flash(request).info('Did you know?')
flash(request).warning('Proceed with caution.')
flash(request).debug('Value was 42.')
Helpers return self, so calls can be chained:
flash(request).info('Step 1 done.').success('All steps complete.')
Reading messages
To get all flash messages without removing them from the session, use all():
from starlette_flash import flash
def index_view(request):
flash(request).success('This is a message.')
messages = flash(request).all()
print(messages) # [{'category': 'success', 'message': 'This is a message.'}]
Consuming messages
consume() returns all messages and clears the bag in one call:
from starlette_flash import flash
def index_view(request):
flash(request).success('This is a message.')
messages = flash(request).consume()
print(messages) # [{'category': 'success', 'message': 'This is a message.'}]
print(flash(request).all()) # [], messages have been consumed
Iterating the bag also consumes messages:
from starlette_flash import flash
def index_view(request):
flash(request).success('This is a message.')
for message in flash(request):
print(message)
print(flash(request).all()) # [], messages have been consumed
Template integration
get_messages_for_template is a convenience function that consumes and returns all messages,
suitable for use in Jinja2 globals or context processors:
from starlette_flash import get_messages_for_template
templates.env.globals['get_flashed_messages'] = get_messages_for_template
Then in your template:
{% for message in get_flashed_messages(request) %}
<div class="alert alert-{{ message.category }}">{{ message.message }}</div>
{% endfor %}
Metadata
Release files for starlette_flash 1.2.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 | Actions |
|---|---|---|---|---|
| starlette_flash-1.2.1.tar.gz | 3.9 kB | Without provenance | Details for starlette_flash-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| starlette_flash-1.2.1-py3-none-any.whl | Python 3 | none | any | Details for starlette_flash-1.2.1-py3-none-any.whl |
Total release size: 8.8 kB
Release files / starlette_flash-1.2.1.tar.gz
| Download URL | starlette_flash-1.2.1.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
856f5958b0adb44a1894d0750621d81e34bc596d606f52191da51af2585d524e
|
|
BLAKE2b-256 checksum How to use checksums |
3d095bf791e7e09e5058927c491464aade6f629b44d6d5956203819070a3e548
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / starlette_flash-1.2.1-py3-none-any.whl
| Download URL | starlette_flash-1.2.1-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
efddb765fb65f3cb514239079b6223d518bfc64183210ff31ae9107279b6b345
|
|
BLAKE2b-256 checksum How to use checksums |
07747ae5bf076a90b5930368d396ee8be524ff34e2cff9d51884dcb098bd2bef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for starlette_flash 1.2.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.