Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Document that get_project_settings() returns project settings only (#8051)

Adrianf6b1f54963c8
diff --git a/docs/topics/api.rst b/docs/topics/api.rst
index 24f46f656..d6e8a54f9 100644
--- a/docs/topics/api.rst
+++ b/docs/topics/api.rst
@@ -166,6 +166,8 @@ Settings API
.. autofunction:: get_settings_priority
+.. autofunction:: scrapy.utils.project.get_project_settings
+
.. autoclass:: Settings
:show-inheritance:
:members:
diff --git a/docs/topics/settings.rst b/docs/topics/settings.rst
index 06a03e69e..90d2eca29 100644
--- a/docs/topics/settings.rst
+++ b/docs/topics/settings.rst
@@ -137,6 +137,10 @@ Scrapy projects include a settings module, usually a file called
``settings.py``, where you should populate most settings that apply to all your
spiders.
+:func:`scrapy.utils.project.get_project_settings` returns these settings, e.g.
+to pass them to :class:`~scrapy.crawler.AsyncCrawlerProcess` when :ref:`running
+Scrapy from a script <run-from-script>`.
+
.. seealso:: :ref:`topics-settings-module-envvar`
.. _addon-settings:
diff --git a/scrapy/utils/project.py b/scrapy/utils/project.py
index 3e75c7729..831ac7770 100644
--- a/scrapy/utils/project.py
+++ b/scrapy/utils/project.py
@@ -64,6 +64,12 @@ def data_path(path: str | os.PathLike[str], createdir: bool = False) -> str:
def get_project_settings() -> Settings:
+ """Return a :class:`~scrapy.settings.Settings` object with the
+ :ref:`project settings <project-settings>` of the current project.
+
+ Settings from sources with a higher precedence, such as :ref:`spider
+ settings <spider-settings>`, are applied when a crawl starts.
+ """
if ENVVAR not in os.environ:
project = os.environ.get("SCRAPY_PROJECT", "default")
init_env(project)