Provide extras for optional dependencies

This commit is contained in:
Adrian Chaves 2026-06-11 08:39:55 +02:00
parent 93a627ba1c
commit 98a4c98ef5
12 changed files with 113 additions and 55 deletions

View File

@ -27,6 +27,6 @@ repos:
hooks:
- id: sphinx-lint
- repo: https://github.com/scrapy/sphinx-scrapy
rev: 0.8.6
rev: 0.8.7
hooks:
- id: sphinx-scrapy

View File

@ -158,6 +158,7 @@ scrapy_intersphinx_enable = [
"itemloaders",
"parsel",
"pytest",
"pypug",
"sphinx",
"tox",
"twisted",

View File

@ -89,6 +89,54 @@ just like any other Python package.
(See :ref:`platform-specific guides <intro-install-platform-notes>`
below for non-Python dependencies that you may need to install beforehand).
.. _extras:
Optional extras
===============
Scrapy provides optional :ref:`extras <pypug:dependency-specifiers-extras>`
that install additional dependencies to enable specific features. To install
Scrapy with one or more extras, list them in square brackets:
.. code-block:: console
pip install scrapy[s3,images]
The following extras are available:
.. list-table::
:header-rows: 1
* - Extra
- Provides
* - ``bpython``
- :ref:`bpython shell <shell-config>`
* - ``brotli``
- :ref:`Brotli response decompression <http-compression>`
* - ``gcs``
- :ref:`Google Cloud Storage <topics-feed-storage-gcs>` for
:ref:`feed exports <topics-feed-exports>` and
:ref:`media pipelines <media-pipeline-gcs>`
* - ``http2``
- :ref:`twisted-http2-handler`
* - ``httpx``
- :ref:`httpx-handler`
* - ``images``
- :ref:`Images pipeline <images-pipeline>`
* - ``ipython``
- :ref:`IPython shell <shell-config>`
* - ``robotparser``
- :ref:`Robotexclusionrulesparser robots.txt parsing <rerp-parser>`
* - ``s3``
- :ref:`Amazon S3 <topics-feed-storage-s3>` storage for
:ref:`feed exports <topics-feed-exports>`,
:ref:`media pipelines <media-pipelines-s3>`, and
:ref:`S3 downloads <s3-handler>`
* - ``uvloop``
- `uvloop <https://github.com/MagicStack/uvloop>`_ event loop
* - ``zstd``
- :ref:`Zstandard response decompression <http-compression>`
.. _intro-install-platform-notes:

View File

@ -5,4 +5,4 @@ sphinx
sphinx-notfound-page
sphinx-rtd-theme
sphinx-rtd-dark-mode
sphinx-scrapy @ git+https://github.com/scrapy/sphinx-scrapy.git@0.8.6
sphinx-scrapy @ git+https://github.com/scrapy/sphinx-scrapy.git@0.8.7

View File

@ -153,7 +153,7 @@ sphinx-rtd-theme==3.1.0
# via
# -r docs/requirements.in
# sphinx-rtd-dark-mode
sphinx-scrapy @ git+https://github.com/scrapy/sphinx-scrapy.git@b1d55db4d16a5425fc68576d63519bbfe26dd9c0
sphinx-scrapy @ git+https://github.com/scrapy/sphinx-scrapy.git@568cf4279dd1f7da4068fa291c8725bab57cfe98
# via -r docs/requirements.in
sphinx-sitemap==2.9.0
# via sphinx-scrapy

View File

@ -169,6 +169,8 @@ of this package for more information.
H2DownloadHandler
-----------------
.. note:: Requires the :ref:`http2 <extras>` extra.
.. autoclass:: scrapy.core.downloader.handlers.http2.H2DownloadHandler
| Supported scheme: ``https``.
@ -181,9 +183,6 @@ for them.
It's implemented using :mod:`twisted.web.client` and the ``h2`` library.
For this handler to work you need to install the ``Twisted[http2]`` extra
dependency.
If you want to use this handler you need to replace the default one for the
``https`` scheme:
@ -269,9 +268,13 @@ Other limitations:
- HTTPS proxies to HTTPS destinations are not supported.
.. _httpx-handler:
HttpxDownloadHandler
--------------------
.. note:: Requires the :ref:`httpx <extras>` extra.
.. versionadded:: 2.15.0
.. autoclass:: scrapy.core.downloader.handlers._httpx.HttpxDownloadHandler
@ -284,8 +287,6 @@ HttpxDownloadHandler
This handler supports ``http://host/path`` and ``https://host/path`` URLs and
uses the HTTP/1.1 or HTTP/2 protocol for them.
It's implemented using the ``httpx`` library and needs it to be installed.
If you want to use this handler you need to replace the default ones for the
``http`` and ``https`` schemes:
@ -327,8 +328,8 @@ HTTPX_HTTP2_ENABLED
Default: ``False``
Whether to enable HTTP/2 support in this handler. The ``httpx[http2]`` extra
needs to be installed if you want to enable this setting.
Whether to enable HTTP/2 support in this handler. Requires installing
``httpx[http2]``.
.. versionadded:: VERSION
@ -374,9 +375,13 @@ This handler supports ``ftp://host/path`` FTP URIs.
It's implemented using :mod:`twisted.protocols.ftp`.
.. _s3-handler:
S3DownloadHandler
-----------------
.. note:: Requires the :ref:`s3 <extras>` extra.
.. autoclass:: scrapy.core.downloader.handlers.s3.S3DownloadHandler
| Supported scheme: ``s3``.
@ -385,5 +390,3 @@ S3DownloadHandler
| :ref:`Requires a Twisted reactor <asyncio-without-reactor>`: no.
This handler supports ``s3://bucket/path`` S3 URIs.
It's implemented using the ``botocore`` library and needs it to be installed.

View File

@ -681,6 +681,8 @@ We assume that the spider will not issue Cache-Control directives
in requests unless it actually needs them, so directives in requests are
not filtered.
.. _http-compression:
HttpCompressionMiddleware
-------------------------
@ -692,14 +694,12 @@ HttpCompressionMiddleware
This middleware allows compressed (gzip, deflate) traffic to be
sent/received from web sites.
This middleware also supports decoding `brotli-compressed`_ as well as
`zstd-compressed`_ responses, provided that `brotli`_ or `zstandard`_ is
installed, respectively.
This middleware also supports decoding `brotli-compressed`_ responses with
the :ref:`brotli <extras>` extra, and `zstd-compressed`_
responses with the :ref:`zstd <extras>` extra.
.. _brotli-compressed: https://www.ietf.org/rfc/rfc7932.txt
.. _brotli: https://pypi.org/project/Brotli/
.. _zstd-compressed: https://www.ietf.org/rfc/rfc8478.txt
.. _zstandard: https://pypi.org/project/zstandard/
HttpCompressionMiddleware Settings
@ -1201,8 +1201,7 @@ Based on `Robotexclusionrulesparser <https://pypi.org/project/robotexclusionrule
In order to use this parser:
* Install ``Robotexclusionrulesparser`` by running
``pip install robotexclusionrulesparser``
* Install the :ref:`robotparser <extras>` extra.
* Set :setting:`ROBOTSTXT_PARSER` setting to
``scrapy.robotstxt.RerpRobotParser``

View File

@ -92,7 +92,6 @@ Marshal
- Value for the ``format`` key in the :setting:`FEEDS` setting: ``marshal``
- Exporter used: :class:`~scrapy.exporters.MarshalItemExporter`
.. _topics-feed-storage:
Storages
@ -106,14 +105,13 @@ The storages backends supported out of the box are:
- :ref:`topics-feed-storage-fs`
- :ref:`topics-feed-storage-ftp`
- :ref:`topics-feed-storage-s3` (requires boto3_)
- :ref:`topics-feed-storage-gcs` (requires `google-cloud-storage`_)
- :ref:`topics-feed-storage-s3` (requires the :ref:`s3 <extras>` extra)
- :ref:`topics-feed-storage-gcs` (requires the :ref:`gcs <extras>` extra)
- :ref:`topics-feed-storage-stdout`
Some storage backends may be unavailable if the required external libraries are
not available. For example, the S3 backend is only available if the boto3_
library is installed.
Some storage backends may be unavailable if the required :ref:`extras <extras>`
are not installed. For example, the S3 backend requires the :ref:`s3 <extras>`
extra.
.. _topics-feed-uri-params:
@ -204,7 +202,7 @@ The feeds are stored on `Amazon S3`_.
- ``s3://aws_key:aws_secret@mybucket/path/to/export.csv``
- Required external libraries: `boto3`_ >= 1.20.0
- Required extras: :ref:`s3 <extras>`
The AWS credentials can be passed as user/password in the URI, or they can be
passed through the following settings:
@ -244,7 +242,7 @@ The feeds are stored on `Google Cloud Storage`_.
- ``gs://mybucket/path/to/export.csv``
- Required external libraries: `google-cloud-storage`_.
- Required extras: :ref:`gcs <extras>`
For more information about authentication, please refer to `Google Cloud documentation <https://docs.cloud.google.com/docs/authentication>`_.
@ -261,7 +259,6 @@ storage backend is: ``True``.
This storage backend uses :ref:`delayed file delivery <delayed-file-delivery>`.
.. _google-cloud-storage: https://docs.cloud.google.com/storage/docs/reference/libraries#client-libraries-install-python
.. _topics-feed-storage-stdout:
@ -788,6 +785,5 @@ source spider in the feed URI:
.. _URIs: https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
.. _Amazon S3: https://aws.amazon.com/s3/
.. _boto3: https://github.com/boto/boto3
.. _Canned ACL: https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl
.. _Google Cloud Storage: https://cloud.google.com/storage/

View File

@ -61,6 +61,8 @@ this:
Using the Images Pipeline
=========================
.. note:: Requires the :ref:`images <extras>` extra.
Using the :class:`ImagesPipeline` is a lot like using the :class:`FilesPipeline`,
except the default field names used are different: you use ``image_urls`` for
the image URLs of an item and it will populate an ``images`` field for the information
@ -70,12 +72,6 @@ The advantage of using the :class:`ImagesPipeline` for image files is that you
can configure some extra functions like generating thumbnails and filtering
the images based on their size.
The Images Pipeline requires Pillow_ 8.3.2 or greater. It is used for
thumbnailing and normalizing images to JPEG/RGB format.
.. _Pillow: https://github.com/python-pillow/Pillow
.. _topics-media-pipeline-enabling:
Enabling your Media Pipeline
@ -232,12 +228,13 @@ set the :setting:`FEED_STORAGE_FTP_ACTIVE` setting to ``True``.
Amazon S3 storage
-----------------
.. note:: Requires the :ref:`s3 <extras>` extra.
.. setting:: FILES_STORE_S3_ACL
.. setting:: IMAGES_STORE_S3_ACL
If botocore_ >= 1.13.45 is installed, :setting:`FILES_STORE` and
:setting:`IMAGES_STORE` can represent an Amazon S3 bucket. Scrapy will
automatically upload the files to the bucket.
:setting:`FILES_STORE` and :setting:`IMAGES_STORE` can represent an Amazon S3
bucket. Scrapy will automatically upload the files to the bucket.
For example, this is a valid :setting:`IMAGES_STORE` value:
@ -272,7 +269,6 @@ For self-hosting you also might feel the need not to use SSL and not to verify S
AWS_USE_SSL = False # or True (None by default)
AWS_VERIFY = False # or True (None by default)
.. _botocore: https://github.com/boto/botocore
.. _canned ACLs: https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl
.. _Minio: https://github.com/minio/minio
.. _Zenko CloudServer: https://www.zenko.io/cloudserver/
@ -283,13 +279,13 @@ For self-hosting you also might feel the need not to use SSL and not to verify S
Google Cloud Storage
---------------------
.. note:: Requires the :ref:`gcs <extras>` extra.
.. setting:: FILES_STORE_GCS_ACL
.. setting:: IMAGES_STORE_GCS_ACL
:setting:`FILES_STORE` and :setting:`IMAGES_STORE` can represent a Google Cloud Storage
bucket. Scrapy will automatically upload the files to the bucket. (requires `google-cloud-storage`_ )
.. _google-cloud-storage: https://docs.cloud.google.com/storage/docs/reference/libraries#client-libraries-install-python
:setting:`FILES_STORE` and :setting:`IMAGES_STORE` can represent a Google Cloud
Storage bucket. Scrapy will automatically upload the files to the bucket.
For example, these are valid :setting:`IMAGES_STORE` and :setting:`GCS_PROJECT_ID` settings:

View File

@ -17,19 +17,17 @@ spider, without having to run the spider to test every change.
Once you get familiarized with the Scrapy shell, you'll see that it's an
invaluable tool for developing and debugging your spiders.
.. _shell-config:
Configuring the shell
=====================
If you have `IPython`_ installed, the Scrapy shell will use it (instead of the
standard Python console). The `IPython`_ console is much more powerful and
provides smart auto-completion and colorized output, among other things.
With the :ref:`ipython <extras>` extra, the Scrapy shell will use IPython_
instead of the :term:`REPL`. IPython provides smart auto-completion, colorized
output, and more.
We highly recommend you install `IPython`_, especially if you're working on
Unix systems (where `IPython`_ excels). See the `IPython installation guide`_
for more info.
Scrapy also has support for `bpython`_, and will try to use it where `IPython`_
is unavailable.
Scrapy also has support for `bpython`_ via the :ref:`bpython <extras>` extra,
and will try to use it where IPython is unavailable.
Through Scrapy's settings you can configure it to use any one of
``ipython``, ``bpython`` or the standard ``python`` shell, regardless of which
@ -40,7 +38,6 @@ variable; or by defining it in your :ref:`scrapy.cfg <topics-config-settings>`::
shell = bpython
.. _IPython: https://ipython.org/
.. _IPython installation guide: https://ipython.org/install/
.. _bpython: https://bpython-interpreter.org/
Launch the shell

View File

@ -60,6 +60,24 @@ Source = "https://github.com/scrapy/scrapy"
Tracker = "https://github.com/scrapy/scrapy/issues"
"Release notes" = "https://docs.scrapy.org/en/latest/news.html"
[project.optional-dependencies]
bpython = ["bpython>=0.7.1"]
brotli = [
"brotli>=1.2.0; implementation_name != 'pypy'",
"brotlicffi>=1.2.0.0; implementation_name == 'pypy'",
]
gcs = ["google-cloud-storage>=1.29.0"]
http2 = ["Twisted[http2]>=21.7.0"]
httpx = ["httpx>=0.27.1"]
images = ["Pillow>=8.3.2"]
ipython = ["ipython>=7.1.0"]
robotparser = ["robotexclusionrulesparser>=1.6.2"]
s3 = ["boto3>=1.20.0"]
uvloop = [
"uvloop>=0.16.0; platform_system != 'Windows' and implementation_name != 'pypy'",
]
zstd = ["zstandard>=0.16.0; implementation_name != 'pypy'"]
[project.scripts]
scrapy = "scrapy.cmdline:execute"

View File

@ -5,7 +5,7 @@
[tox]
requires =
sphinx-scrapy[tox] @ git+https://github.com/scrapy/sphinx-scrapy.git@0.8.6
sphinx-scrapy[tox] @ git+https://github.com/scrapy/sphinx-scrapy.git@0.8.7
envlist = pre-commit,pylint,typing,py,docs
minversion = 1.7.0