Home / Function/ get_namespace() — flask Function Reference

get_namespace() — flask Function Reference

Architecture documentation for the get_namespace() function in config.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  4547c641_144e_31b0_3192_eceb552bfdef["get_namespace()"]
  1e067a59_9e9f_8edb_0434_65b5c5690e36["Config"]
  4547c641_144e_31b0_3192_eceb552bfdef -->|defined in| 1e067a59_9e9f_8edb_0434_65b5c5690e36
  style 4547c641_144e_31b0_3192_eceb552bfdef fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/config.py lines 323–364

    def get_namespace(
        self, namespace: str, lowercase: bool = True, trim_namespace: bool = True
    ) -> dict[str, t.Any]:
        """Returns a dictionary containing a subset of configuration options
        that match the specified namespace/prefix. Example usage::

            app.config['IMAGE_STORE_TYPE'] = 'fs'
            app.config['IMAGE_STORE_PATH'] = '/var/app/images'
            app.config['IMAGE_STORE_BASE_URL'] = 'http://img.website.com'
            image_store_config = app.config.get_namespace('IMAGE_STORE_')

        The resulting dictionary `image_store_config` would look like::

            {
                'type': 'fs',
                'path': '/var/app/images',
                'base_url': 'http://img.website.com'
            }

        This is often useful when configuration options map directly to
        keyword arguments in functions or class constructors.

        :param namespace: a configuration namespace
        :param lowercase: a flag indicating if the keys of the resulting
                          dictionary should be lowercase
        :param trim_namespace: a flag indicating if the keys of the resulting
                          dictionary should not include the namespace

        .. versionadded:: 0.11
        """
        rv = {}
        for k, v in self.items():
            if not k.startswith(namespace):
                continue
            if trim_namespace:
                key = k[len(namespace) :]
            else:
                key = k
            if lowercase:
                key = key.lower()
            rv[key] = v
        return rv

Subdomains

Defined In

Frequently Asked Questions

What does get_namespace() do?
get_namespace() is a function in the flask codebase, defined in src/flask/config.py.
Where is get_namespace() defined?
get_namespace() is defined in src/flask/config.py at line 323.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free