flask.signals Namespace Example Code

Namespace is a class used within the flask.signals module, but it is actually imported from the Blinker project. Blinker is a fast dispatching system for event subscriptions, also known as "signals". Flask uses this library instead of implementing its own event subscription signaling model. Namespace is defined within Blinker as a mapping of signal names to signals, and it serves the same purpose in the Flask project.

got_request_exception is another callable from the flask.signals package with code examples.

Example 1 from flask-login

Flask-Login (project documentation and PyPI package) is a Flask extension that provides user session management, which handles common tasks such as logging in and out of a web application and managing associated user session data. Flask-Login is open sourced under the MIT license.

flask-login / flask_login / signals.py

# signals.py

from flask.signals import Namespace

_signals = Namespace()

user_logged_in = _signals.signal('logged-in')

user_logged_out = _signals.signal('logged-out')

user_loaded_from_cookie = _signals.signal('loaded-from-cookie')

user_loaded_from_header = _signals.signal('loaded-from-header')

user_loaded_from_request = _signals.signal('loaded-from-request')

user_login_confirmed = _signals.signal('login-confirmed')

user_unauthorized = _signals.signal('unauthorized')

user_needs_refresh = _signals.signal('needs-refresh')

user_accessed = _signals.signal('accessed')

session_protected = _signals.signal('session-protected')

## ... source file continues with no further Namespace examples...

Example 2 from flask-sqlalchemy

flask-sqlalchemy (project documentation and PyPI information) is a Flask extension that makes it easier to use SQLAlchemy when building Flask apps. flask-sqlalchemy provides helper functions that reduce the amount of common boilerplate code that you have to frequently write yourself if you did not use this library when combining Flask with SQLAlchemy.

flask-sqlalchemy is provided as open source under the BSD 3-Clause "New" or "Revised" License.

flask-sqlalchemy / src/flask_sqlalchemy / init.py

# __init__.py
import functools
import os
import sys
import warnings
from math import ceil
from operator import itemgetter
from threading import Lock
from time import perf_counter

import sqlalchemy
from flask import _app_ctx_stack
from flask import abort
from flask import current_app
from flask import request
from flask.signals import Namespace
from sqlalchemy import event
from sqlalchemy import inspect
from sqlalchemy import orm
from sqlalchemy.engine.url import make_url
from sqlalchemy.orm.exc import UnmappedClassError
from sqlalchemy.orm.session import Session as SessionBase

from .model import DefaultMeta
from .model import Model

    from sqlalchemy.orm import declarative_base
    from sqlalchemy.orm import DeclarativeMeta
except ImportError:
    from sqlalchemy.ext.declarative import declarative_base
    from sqlalchemy.ext.declarative import DeclarativeMeta

    from greenlet import getcurrent as _ident_func
except ImportError:
    from threading import get_ident as _ident_func

__version__ = "3.0.0.dev0"

_signals = Namespace()
models_committed = _signals.signal("models-committed")
before_models_committed = _signals.signal("before-models-committed")

def _sa_url_set(url, **kwargs):
        url = url.set(**kwargs)
    except AttributeError:
        for key, value in kwargs.items():
            setattr(url, key, value)

    return url

def _sa_url_query_setdefault(url, **kwargs):
    query = dict(url.query)

    for key, value in kwargs.items():
        query.setdefault(key, value)

    return _sa_url_set(url, query=query)

def _make_table(db):

## ... source file continues with no further Namespace examples...

Example 3 from Flask-User

Flask-User (PyPI information and project documentation) is a Flask extension that makes it easier to add custom user account management and authentication to the projects you are building. The extension supports persistent data storage through both relational databases and MongoDB. The project is provided as open source under the MIT license.

Flask-User / flask_user / signals.py

# signals.py

from flask.signals import Namespace

_signals = Namespace()                              # Place Flask-User signals in our own namespace

user_changed_password = _signals.signal('user.user_changed_password')

user_changed_username = _signals.signal('user.user_changed_username')

user_confirmed_email = _signals.signal('user.user_confirmed_email')

user_forgot_password = _signals.signal('user.forgot_password')

user_logged_in = _signals.signal('user.user_logged_in')

user_logged_out = _signals.signal('user.user_logged_out')

user_registered = _signals.signal('user.user_registered')

user_reset_password = _signals.signal('user.user_reset_password')

user_sent_invitation = _signals.signal('user.user_sent_invitation')

## ... source file continues with no further Namespace examples...

Sponsored By

Sentry logo

Software errors are inevitable. Chaos is not. Try Sentry for free.

AssemblyAI logo

The most accurate speech-to-text API. Built for Python developers.

Full Stack Python

Full Stack Python is an open book that explains concepts in plain language and provides helpful resources for those topics.
Updates via Twitter & Facebook.

Matt Makai 2012-2021