open_resource() — flask Function Reference
Architecture documentation for the open_resource() function in app.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD c92a3a8a_766d_75a0_8dd5_ab00df390e5d["open_resource()"] 9f8cc56e_d5c4_e7a8_438a_3124c0dd5de5["Flask"] c92a3a8a_766d_75a0_8dd5_ab00df390e5d -->|defined in| 9f8cc56e_d5c4_e7a8_438a_3124c0dd5de5 3dfbf89e_0efa_e73a_439f_b07e59e5d57d["open()"] c92a3a8a_766d_75a0_8dd5_ab00df390e5d -->|calls| 3dfbf89e_0efa_e73a_439f_b07e59e5d57d style c92a3a8a_766d_75a0_8dd5_ab00df390e5d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/flask/app.py lines 413–444
def open_resource(
self, resource: str, mode: str = "rb", encoding: str | None = None
) -> t.IO[t.AnyStr]:
"""Open a resource file relative to :attr:`root_path` for reading.
For example, if the file ``schema.sql`` is next to the file
``app.py`` where the ``Flask`` app is defined, it can be opened
with:
.. code-block:: python
with app.open_resource("schema.sql") as f:
conn.executescript(f.read())
:param resource: Path to the resource relative to :attr:`root_path`.
:param mode: Open the file in this mode. Only reading is supported,
valid values are ``"r"`` (or ``"rt"``) and ``"rb"``.
:param encoding: Open the file with this encoding when opening in text
mode. This is ignored when opening in binary mode.
.. versionchanged:: 3.1
Added the ``encoding`` parameter.
"""
if mode not in {"r", "rt", "rb"}:
raise ValueError("Resources can only be opened for reading.")
path = os.path.join(self.root_path, resource)
if mode == "rb":
return open(path, mode) # pyright: ignore
return open(path, mode, encoding=encoding)
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does open_resource() do?
open_resource() is a function in the flask codebase, defined in src/flask/app.py.
Where is open_resource() defined?
open_resource() is defined in src/flask/app.py at line 413.
What does open_resource() call?
open_resource() calls 1 function(s): open.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free