# Feed exports

One of the most frequently required features when implementing scrapers is
properly storing the scraped data and, quite often, that means generating an
“export file” with the scraped data (commonly called an “export feed”) to be
consumed by other systems.

Scrapy provides this functionality out of the box with the Feed Exports, which
allows you to generate feeds with the scraped items, using multiple
serialization formats and storage backends.

This page provides detailed documentation for all feed export features. If you
are looking for a step-by-step guide, check out [Zyte’s export guides](https://docs.zyte.com/web-scraping/guides/export/index.html#exporting-scraped-data).

## Serialization formats

For serializing the scraped data, the feed exports use the [Item exporters](exporters.md). These formats are supported out of the box:

- JSON
- JSON lines
- CSV
- XML

But you can also extend the supported formats through the
`FEED_EXPORTERS` setting.

### JSON

- Value for the `format` key in the `FEEDS` setting: `json`
- Exporter used: [`JsonItemExporter`](exporters.md)
- See [this warning](exporters.md) if you’re using JSON with
  large feeds.

### JSON lines

- Value for the `format` key in the `FEEDS` setting: `jsonlines`
- Exporter used: [`JsonLinesItemExporter`](exporters.md)

### CSV

- Value for the `format` key in the `FEEDS` setting: `csv`
- Exporter used: [`CsvItemExporter`](exporters.md)
- To specify columns to export, their order and their column names, use
  `FEED_EXPORT_FIELDS`. Other feed exporters can also use this
  option, but it is important for CSV because unlike many other export
  formats CSV uses a fixed header.

### XML

- Value for the `format` key in the `FEEDS` setting: `xml`
- Exporter used: [`XmlItemExporter`](exporters.md)

### Pickle

- Value for the `format` key in the `FEEDS` setting: `pickle`
- Exporter used: [`PickleItemExporter`](exporters.md)

### Marshal

- Value for the `format` key in the `FEEDS` setting: `marshal`
- Exporter used: [`MarshalItemExporter`](exporters.md)

## Storages

When using the feed exports you define where to store the feed using one or
multiple [URIs](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier) (through the `FEEDS` setting). The feed exports support
multiple storage backend types that are defined by the URI scheme.

The storages backends supported out of the box are:

- Local filesystem
- FTP
- FTPS
- S3 (requires the [s3](../intro/install.md "Optional extras") extra)
- Google Cloud Storage (GCS) (requires the [gcs](../intro/install.md "Optional extras") extra)
- Standard output

Some storage backends may be unavailable if the required [extras](../intro/install.md "Optional extras")
are not installed. For example, the S3 backend requires the [s3](../intro/install.md "Optional extras")
extra.

## Storage URI parameters

The storage URI can also contain parameters that get replaced when the feed is
being created. These parameters are:

- `%(time)s` - gets replaced by a timestamp when the feed is being created
- `%(name)s` - gets replaced by the spider name

Any other named parameter is replaced by the spider attribute of the same name.
For example, `%(site_id)s` would be replaced by the `spider.site_id`
attribute the moment the feed is being created.

Here are some examples to illustrate:

- Store in FTP using one directory per spider:
  - `ftp://user:password@ftp.example.com/scraping/feeds/%(name)s/%(time)s.json`
- Store in S3 using one directory per spider:
  - `s3://mybucket/scraping/feeds/%(name)s/%(time)s.json`

> [!NOTE]
> [Spider arguments](spiders.md) become spider attributes, hence
> they can also be used as storage URI parameters.

> [!NOTE]
> Only `%(...)s` parameters are replaced. Any other percent
> character is kept as-is, so percent-encoded URIs (e.g. `%20` for a
> space or percent-encoded FTP credentials) and [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)
> keys containing `%(...)s` parameters both work as expected.

## Storage backends

### Local filesystem

The feeds are stored in the local filesystem.

- URI scheme: `file`
- Example URI: `file:///tmp/export.csv`
- Required external libraries: none

Note that for the local filesystem storage you can omit the scheme if you
specify a path (e.g. `/tmp/export.csv`). Alternatively, you can use a
[`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path) object.

Supported modes (see FEED_MODE): `"append"`, `"create"` and
`"overwrite"`. If `FEED_MODE` is `None`, `"append"` is used.

### FTP

The feeds are stored on an FTP server.

- URI scheme: `ftp`
- Example URI: `ftp://user:pass@ftp.example.com/path/to/export.csv`
- Required external libraries: none

FTP sends credentials and data in cleartext. Use FTPS
instead where possible.

FTP supports two different connection modes: [active or passive](https://stackoverflow.com/a/1699163). Scrapy uses the passive connection
mode by default. To use the active connection mode instead, set the
`FEED_STORAGE_FTP_ACTIVE` setting to `True`.

Supported modes (see FEED_MODE): `"append"`, `"create"` and
`"overwrite"`. If `FEED_MODE` is `None`, `"overwrite"` is used.

> [!NOTE]
> Some FTP servers may not support appending to files (the `APPE` FTP
> command).

> [!NOTE]
> FTP has no atomic create-if-absent command, so `"create"` is
> best-effort: the target is checked for existence right before it is
> written. Servers that do not support the `SIZE` command are
> reported as not having the target.

This storage backend uses delayed file delivery.

### FTPS

The feeds are stored in a FTP server, over a TLS connection, with the
certificate of the server verified.

> [!WARNING]
> Added in version 2.18.0.

- URI scheme: `ftps`
- Example URI: `ftps://user:pass@ftp.example.com/path/to/export.csv`
- Required external libraries: none

See FTP for connection modes, supported modes (see FEED_MODE) and file delivery.

> [!NOTE]
> For SFTP, an unrelated protocol built on SSH, use
> [scrapy-feedexporter-sftp](https://github.com/scrapy-plugins/scrapy-feedexporter-sftp).

### S3

The feeds are stored on [Amazon S3](https://aws.amazon.com/s3/).

- URI scheme: `s3`
- Example URIs:
  - `s3://mybucket/path/to/export.csv`
  - `s3://aws_key:aws_secret@mybucket/path/to/export.csv`
- Required extras: [s3](../intro/install.md "Optional extras")

The AWS credentials can be passed as user/password in the URI, or they can be
passed through the following settings:

- [`AWS_ACCESS_KEY_ID`](settings.md)
- [`AWS_SECRET_ACCESS_KEY`](settings.md)
- [`AWS_SESSION_TOKEN`](settings.md) (only needed for [temporary security credentials](https://docs.aws.amazon.com/IAM/latest/UserGuide/security-creds.html))

You can also define a custom ACL, custom endpoint, region name and connection
pool size for exported feeds using these settings:

- `FEED_STORAGE_S3_ACL`
- [`AWS_ENDPOINT_URL`](settings.md)
- [`AWS_REGION_NAME`](settings.md)
- [`AWS_MAX_POOL_CONNECTIONS`](settings.md)

Supported modes (see FEED_MODE): `"create"` and `"overwrite"`. If
`FEED_MODE` is `None`, `"overwrite"` is used.

`"create"` mode [does not support files larger than 5 GB](https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html).

This storage backend uses delayed file delivery.

### Google Cloud Storage (GCS)

The feeds are stored on [Google Cloud Storage](https://cloud.google.com/storage/).

- URI scheme: `gs`
- Example URIs:
  - `gs://mybucket/path/to/export.csv`
- Required extras: [gcs](../intro/install.md "Optional extras")

For more information about authentication, please refer to [Google Cloud documentation](https://docs.cloud.google.com/docs/authentication).

You can set a *Project ID* and *Access Control List (ACL)* through the following settings:

- [`FEED_STORAGE_GCS_ACL`](settings.md)
- [`GCS_PROJECT_ID`](settings.md)

Supported modes (see FEED_MODE): `"append"`, `"create"` and
`"overwrite"`. If `FEED_MODE` is `None`, `"overwrite"` is used.

Appending turns the feed into a [composite object](https://docs.cloud.google.com/storage/docs/composite-objects), which has a CRC32C
checksum but no MD5 hash.

> [!WARNING]
> Added in version 2.20.0: Appending support.

This storage backend uses delayed file delivery.

### Standard output

The feeds are written to the standard output of the Scrapy process.

- URI scheme: `stdout`
- Example URI: `stdout:`
- Required external libraries: none

The mode (see FEED_MODE) is ignored by this storage backend.

### Delayed file delivery

As indicated above, some of the described storage backends use delayed file
delivery.

These storage backends do not upload items to the feed URI as those items are
scraped. Instead, Scrapy writes items into a temporary local file, and only
once all the file contents have been written (i.e. at the end of the crawl) is
that file uploaded to the feed URI.

If you want item delivery to start earlier when using one of these storage
backends, use `FEED_EXPORT_BATCH_ITEM_COUNT` to split the output items
in multiple files, with the specified maximum item count per file. That way, as
soon as a file reaches the maximum item count, that file is delivered to the
feed URI, allowing item delivery to start way before the end of the crawl.

### Custom storage backends

To write your own storage backend, define a class that follows
`FeedStorageProtocol` and assign it to a
URI scheme through the `FEED_STORAGES` setting.

### *class* scrapy.extensions.feedexport.FeedStorageProtocol(uri, \*, feed_options=None)

Protocol that all Feed Storages must follow.

* **Parameters:**
  * **uri** – Feed URI.
  * **feed_options** – Feed options of the feed.

A feed storage may define a `from_crawler(cls, crawler, uri, *,
feed_options=None)` class method instead of `__init__`, to also get the
[`Crawler`](api.md) object.

#### supported_modes *: frozenset[str]*

Optional set of supported values of the `mode` feed option, e.g. `frozenset({"create", "overwrite"})`.

> [!WARNING]
> Added in version 2.20.0.

Setting `mode` to an unsupported value raises an exception, which
prevents the crawl from running. A storage class that does not define
this attribute is assumed to predate the `mode` feed option, and
setting that option on a feed that uses it logs a warning about the
option being possibly ignored.

A storage class that declares support for `"create"` must enforce it
when writing the feed, ideally atomically, raising
`FileExistsError` if the target exists. Scrapy then handles that
file as described in `FEED_MODE`.

#### open(spider: [Spider](spiders.md)) → IO[bytes] | Coroutine[Any, Any, IO[bytes]]

Open the storage for *spider* and return the file-like object that
item exporters write into.

> [!WARNING]
> Changed in version 2.20.0: This method may now be a coroutine function (`async def`).

#### store(file: IO[bytes]) → Coroutine[Any, Any, None] | Deferred[None] | None

Store *file*, the file-like object returned by `open()`, and
close it.

> [!WARNING]
> Changed in version 2.20.0: This method may now be a coroutine function (`async def`).

If your storage backend blocks, subclass
`BlockingFeedStorage` instead: it writes
items into a temporary local file (see delayed file delivery) and calls your `_store_in_thread()` method in a
separate thread once the crawl is done, keeping the reactor free.

### *class* scrapy.extensions.feedexport.BlockingFeedStorage

Base class for feed storages that store feeds using blocking code.

#### *abstractmethod* \_store_in_thread(file: IO[bytes]) → None

Store *file* and close it.

This method runs in a separate thread, so it may use blocking code.

A storage backend receives a file. To send items to a service as they are
scraped, write an [item pipeline](item-pipeline.md) instead.

## Item filtering

You can filter items that you want to allow for a particular feed by using the
`item_classes` option in feeds options. Only items of
the specified types will be added to the feed.

The `item_classes` option is implemented by the `ItemFilter`
class, which is the default value of the `item_filter` feed option.

You can create your own custom filtering class by implementing `ItemFilter`’s
method `accepts` and taking `feed_options` as an argument.

For instance:

```python
class MyCustomFilter:
    def __init__(self, feed_options):
        self.feed_options = feed_options

    def accepts(self, item):
        if "field1" in item and item["field1"] == "expected_data":
            return True
        return False
```

You can assign your custom filtering class to the `item_filter` option of a feed.
See `FEEDS` for examples.

### ItemFilter

### *class* scrapy.extensions.feedexport.ItemFilter(feed_options: dict[str, Any] | None)

This will be used by FeedExporter to decide if an item should be allowed
to be exported to a particular feed.

* **Parameters:**
  **feed_options** (*dict*) – feed specific options passed from FeedExporter

#### accepts(item: Any) → bool

Return `True` if item should be exported or `False` otherwise.

* **Parameters:**
  **item** ([Scrapy items](items.md)) – scraped item which user wants to check if is acceptable
* **Returns:**
  True if accepted, False otherwise
* **Return type:**
  bool

## Item processing

> [!WARNING]
> Added in version 2.20.0.

The `item_processor` feed option takes a callable, or
its import path, that receives an accepted item and returns an iterable of the
items to export in its place:

```python
def split_variants(item):
    for variant in item["variants"]:
        yield {**item, "variants": None, **variant}
```

Returning an empty iterable drops the item from that feed, and returning more
than one item writes one entry per returned item.

Item processors run after item filtering, and only affect
the feed that declares them. Items are exported as returned, so the
[`item_scraped`](signals.md) signal, [item pipelines](item-pipeline.md) and
the `item_scraped_count` stat still see the item as scraped; use item
processors for output formatting, and item pipelines for anything that should
apply to the item itself. The number of exported entries is reported per
storage class, as the `feedexport/item_count/<storage class>` stat.

## Post-Processing

Scrapy provides an option to activate plugins to post-process feeds before they are exported
to feed storages. In addition to using builtin plugins (see Built-in Plugins), you
can create your own plugins (see Custom Plugins).

These plugins can be activated through the `postprocessing` option of a feed.
The option must be passed a list of post-processing plugins in the order you want
the feed to be processed. These plugins can be declared either as an import string
or with the imported class of the plugin. Parameters to plugins can be passed
through the feed options. See feed options for examples.

### Built-in Plugins

### *class* scrapy.extensions.postprocessing.GzipPlugin(file: BinaryIO, feed_options: dict[str, Any])

Compresses received data using [gzip](https://en.wikipedia.org/wiki/Gzip).

Accepted `feed_options` parameters:

- gzip_compresslevel
- gzip_mtime
- gzip_filename

See [`gzip.GzipFile`](https://docs.python.org/3/library/gzip.html#gzip.GzipFile) for more info about parameters.

### *class* scrapy.extensions.postprocessing.LZMAPlugin(file: BinaryIO, feed_options: dict[str, Any])

Compresses received data using [lzma](https://en.wikipedia.org/wiki/Lempel–Ziv–Markov_chain_algorithm).

Accepted `feed_options` parameters:

- lzma_format
- lzma_check
- lzma_preset
- lzma_filters

See [`lzma.LZMAFile`](https://docs.python.org/3/library/lzma.html#lzma.LZMAFile) for more info about parameters.

### *class* scrapy.extensions.postprocessing.Bz2Plugin(file: BinaryIO, feed_options: dict[str, Any])

Compresses received data using [bz2](https://en.wikipedia.org/wiki/Bzip2).

Accepted `feed_options` parameters:

- bz2_compresslevel

See [`bz2.BZ2File`](https://docs.python.org/3/library/bz2.html#bz2.BZ2File) for more info about parameters.

### Custom Plugins

Each plugin is a class that must implement the following methods:

### \_\_init_\_(self, file, feed_options)

Initialize the plugin.

* **Parameters:**
  * **file** – file-like object having at least the write, tell and close methods implemented
  * **feed_options** (`dict`) – feed-specific options

### write(self, data)

Process and write data (`bytes` or `memoryview`) into the plugin’s target file.
It must return number of bytes written.

### close(self)

Clean up the plugin.

For example, you might want to close a file wrapper that you might have
used to compress data written into the file received in the `__init__`
method.

> [!WARNING]
> Do not close the file from the `__init__` method.

To pass a parameter to your plugin, use feed options. You
can then access those parameters from the `__init__` method of your plugin.

## Settings

These are the settings used for configuring the feed exports:

- `FEEDS` (mandatory)
- `FEED_EXPORT_ENCODING`
- `FEED_MODE`
- `FEED_STORE_EMPTY`
- `FEED_EXPORT_FIELDS`
- `FEED_EXPORT_INDENT`
- `FEED_STORAGES`
- `FEED_STORAGE_FTP_ACTIVE`
- `FEED_STORAGE_S3_ACL`
- `FEED_EXPORTERS`
- `FEED_EXPORT_BATCH_ITEM_COUNT`
- [`UPLOAD_TIMEOUT`](settings.md)

### FEEDS

Default: `{}`

A dictionary in which every key is a feed URI (or a [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)
object) and each value is a nested dictionary containing configuration
parameters for the specific feed.

This setting is required for enabling the feed export feature.

See Storage backends for supported URI schemes.

For instance:

```python
{
    "items.json": {
        "format": "json",
        "encoding": "utf8",
        "store_empty": False,
        "item_classes": [MyItemClass1, "myproject.items.MyItemClass2"],
        "fields": None,
        "indent": 4,
        "item_export_kwargs": {
            "export_empty_fields": True,
        },
    },
    "/home/user/documents/items.xml": {
        "format": "xml",
        "fields": ["name", "price"],
        "item_filter": MyCustomFilter1,
        "encoding": "latin1",
        "indent": 8,
    },
    pathlib.Path("items.csv.gz"): {
        "format": "csv",
        "fields": ["price", "name"],
        "item_filter": "myproject.filters.MyCustomFilter2",
        "postprocessing": [MyPlugin1, "scrapy.extensions.postprocessing.GzipPlugin"],
        "gzip_compresslevel": 5,
    },
}
```

The following is a list of the accepted keys and the setting that is used
as a fallback value if that key is not provided for a specific feed definition:

- `format`: the serialization format (see Serialization formats).

  If not set, it is inferred from the file extension of the feed URI, e.g.
  `json` for a URI ending in `.json`. It is mandatory if it cannot
  be inferred this way.
- `batch_item_count`: falls back to
  `FEED_EXPORT_BATCH_ITEM_COUNT`.
- `encoding`: falls back to `FEED_EXPORT_ENCODING`.
- `fields`: falls back to `FEED_EXPORT_FIELDS`.
- `item_classes`: list of [item classes](items.md) to export.

  If undefined or empty, all items are exported.
- `item_filter`: a filter class (see Item filtering) to filter items to export.

  `ItemFilter` is used be default.
- `item_processor`: an item processor (see Item processing) to reshape
  items before they are exported.
  > [!WARNING]
  > Added in version 2.20.0.

  If undefined, items are exported as scraped.
- `indent`: falls back to `FEED_EXPORT_INDENT`.
- `item_export_kwargs`: `dict` with keyword arguments for the corresponding [item exporter class](exporters.md).
- `mode`: falls back to `FEED_MODE`.
  > [!WARNING]
  > Added in version 2.20.0.
- `store_empty`: falls back to `FEED_STORE_EMPTY`.
- `uri_params`: falls back to `FEED_URI_PARAMS`.
- `postprocessing`: list of plugins (see Post-Processing) to use for post-processing.

  The plugins will be used in the order of the list passed.

### FEED_EXPORT_ENCODING

Default: `"utf-8"` ([fallback](settings.md "6. Default global settings"): `None`)

The encoding to be used for the feed.

If set to `None`, it uses UTF-8 for everything except JSON output, which uses
safe numeric encoding (`\uXXXX` sequences) for historic reasons.

Use `"utf-8"` if you want UTF-8 for JSON too.

### FEED_EXPORT_FIELDS

Default: `None`

Use the `FEED_EXPORT_FIELDS` setting to define the fields to export, their
order and their output names. See [`BaseItemExporter.fields_to_export`](exporters.md) for more information.

### FEED_EXPORT_INDENT

Default: `0`

Amount of spaces used to indent the output on each level. If `FEED_EXPORT_INDENT`
is a non-negative integer, then array elements and object members will be pretty-printed
with that indent level. An indent level of `0` (the default), or negative,
will put each item on a new line. `None` selects the most compact representation.

Currently implemented only by [`JsonItemExporter`](exporters.md)
and [`XmlItemExporter`](exporters.md), i.e. when you are exporting
to `.json` or `.xml`.

### FEED_MODE

> [!WARNING]
> Added in version 2.20.0.

Default: `"create"` ([fallback](settings.md "6. Default global settings"): `None`)

What to do when the target of a feed already exists.

Supported values, which match the corresponding `open()` modes:

- `"append"` (`a`): append to the existing target.
- `"create"` (`x`): do not write, keeping the existing target untouched.
- `"overwrite"` (`w`): replace the existing target.

Can be overridden with the `mode` feed option.

Not every storage backend (see Storage backends) supports every
mode; see the documentation of your storage backend.

If `None`, the mode depends on the backend being used, e.g. appending for the
local filesystem and overwriting for S3.

When the mode of a feed is `"create"` and its target already exists, Scrapy
logs an error, increases the `feedexport/conflicts/<storage class name>`
[stat](stats.md), and does not write that file, i.e. the items that it
would have contained are lost.

> [!NOTE]
> When resuming a crawl (see [`JOBDIR`](settings.md)), the feed of the
> previous run already exists, so a feed that must survive a resumed crawl
> needs the `"append"` mode.

### FEED_STORE_EMPTY

Default: `True`

Whether to export empty feeds (i.e. feeds with no items).
If `False`, and there are no items to export, no new files are created and
existing files are not modified, even if the `mode` feed option is `"overwrite"`.

### FEED_STORAGES

Default: `{}`

A dict containing additional feed storage backends supported by your project.
The keys are URI schemes and the values are paths to storage classes.

### FEED_STORAGE_FTP_ACTIVE

Default: `False`

Whether to use the active connection mode when exporting feeds to an FTP server
(`True`) or use the passive connection mode instead (`False`, default).

For information about FTP connection modes, see [What is the difference between
active and passive FTP?](https://stackoverflow.com/a/1699163).

### FEED_STORAGE_S3_ACL

Default: `''` (empty string)

A string containing a custom ACL for feeds exported to Amazon S3 by your project.

For a complete list of available values, access the [Canned ACL](https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl) section on Amazon S3 docs.

### FEED_STORAGES_BASE

Default:

```python
{
    "": "scrapy.extensions.feedexport.FileFeedStorage",
    "file": "scrapy.extensions.feedexport.FileFeedStorage",
    "stdout": "scrapy.extensions.feedexport.StdoutFeedStorage",
    "s3": "scrapy.extensions.feedexport.S3FeedStorage",
    "gs": "scrapy.extensions.feedexport.GCSFeedStorage",
    "ftp": "scrapy.extensions.feedexport.FTPFeedStorage",
    "ftps": "scrapy.extensions.feedexport.FTPFeedStorage",
}
```

A dict containing the built-in feed storage backends supported by Scrapy, see
Storage backend classes. You can disable any of these backends by assigning
`None` to their URI scheme in `FEED_STORAGES`. E.g., to disable the
built-in FTP storage backend (without replacement), place this in your
`settings.py`:

```python
FEED_STORAGES = {
    "ftp": None,
}
```

### FEED_EXPORTERS

Default: `{}`

A dict containing additional exporters supported by your project. The keys are
serialization formats and the values are paths to [Item exporter](exporters.md) classes.

### FEED_EXPORTERS_BASE

Default:

```python
{
    "json": "scrapy.exporters.JsonItemExporter",
    "jsonlines": "scrapy.exporters.JsonLinesItemExporter",
    "jsonl": "scrapy.exporters.JsonLinesItemExporter",
    "jl": "scrapy.exporters.JsonLinesItemExporter",
    "csv": "scrapy.exporters.CsvItemExporter",
    "xml": "scrapy.exporters.XmlItemExporter",
    "marshal": "scrapy.exporters.MarshalItemExporter",
    "pickle": "scrapy.exporters.PickleItemExporter",
}
```

A dict containing the built-in feed exporters supported by Scrapy. You can
disable any of these exporters by assigning `None` to their serialization
format in `FEED_EXPORTERS`. E.g., to disable the built-in CSV exporter
(without replacement), place this in your `settings.py`:

```python
FEED_EXPORTERS = {
    "csv": None,
}
```

### FEED_EXPORT_BATCH_ITEM_COUNT

Default: `0`

If assigned an integer number higher than `0`, Scrapy generates multiple output files
storing up to the specified number of items in each output file.

When generating multiple output files, you must use at least one of the following
placeholders in the feed URI to indicate how the different output file names are
generated:

* `%(batch_time)s` - gets replaced by a timestamp when the feed is being created
  (e.g. `2020-03-28T14-45-08.237134`)
* `%(batch_id)d` - gets replaced by the 1-based sequence number of the batch.

  Use [printf-style string formatting](https://docs.python.org/3/builtins/stdtypes.html#old-string-formatting) to
  alter the number format. For example, to make the batch ID a 5-digit
  number by introducing leading zeroes as needed, use `%(batch_id)05d`
  (e.g. `3` becomes `00003`, `123` becomes `00123`).

For instance, if your settings include:

```python
FEED_EXPORT_BATCH_ITEM_COUNT = 100
```

And your [`crawl`](commands.md) command line is:

```
scrapy crawl spidername -o "dirname/%(batch_id)d-filename%(batch_time)s.json"
```

The command line above can generate a directory tree like:

```
->projectname
-->dirname
--->1-filename2020-03-28T14-45-08.237134.json
--->2-filename2020-03-28T14-45-09.148903.json
--->3-filename2020-03-28T14-45-10.046092.json
```

Where the first and second files contain exactly 100 items. The last one contains
100 items or fewer.

### FEED_URI_PARAMS

Default: `None`

A string with the import path of a function to set the parameters to apply with
[printf-style string formatting](https://docs.python.org/3/builtins/stdtypes.html#old-string-formatting) to the
feed URI.

The function signature should be as follows:

#### scrapy.extensions.feedexport.uri_params(params, spider)

Return a `dict` of key-value pairs to apply to the feed URI using
[printf-style string formatting](https://docs.python.org/3/builtins/stdtypes.html#old-string-formatting).

* **Parameters:**
  * **params** (*dict*) – 

    default key-value pairs

    Specifically:
    - `batch_id`: ID of the file batch. See
      `FEED_EXPORT_BATCH_ITEM_COUNT`.

      If `FEED_EXPORT_BATCH_ITEM_COUNT` is `0`, `batch_id`
      is always `1`.
    - `batch_time`: UTC date and time, in ISO format with `:`
      replaced with `-`.

      See `FEED_EXPORT_BATCH_ITEM_COUNT`.
    - `time`: `batch_time`, with microseconds set to `0`.
  * **spider** ([*scrapy.Spider*](spiders.md)) – source spider of the feed items

> [!CAUTION]
> The function must return a new dictionary instead of modifying
> the received `params` in-place.

For example, to include the [`name`](spiders.md) of the
source spider in the feed URI:

1. Define the following function somewhere in your project:
   ```python
   # myproject/utils.py
   def uri_params(params, spider):
       return {**params, "spider_name": spider.name}
   ```
2. Point `FEED_URI_PARAMS` to that function in your settings:
   ```python
   # myproject/settings.py
   FEED_URI_PARAMS = "myproject.utils.uri_params"
   ```
3. Use `%(spider_name)s` in your feed URI:
   ```
   scrapy crawl <spider_name> -o "%(spider_name)s.jsonl"
   ```

## Storage backend classes

These are the classes that `FEED_STORAGES_BASE` assigns to the
built-in URI schemes.

### *class* scrapy.extensions.feedexport.FileFeedStorage(uri: str, \*, feed_options: dict[str, Any] | None = None)

Local filesystem storage backend.

*uri* may be a `file://` URI or a plain path. Missing parent directories
are created when the feed is opened.

### *class* scrapy.extensions.feedexport.FTPFeedStorage(uri: str, use_active_mode: bool = False, \*, feed_options: dict[str, Any] | None = None, timeout: float | None = None)

FTP storage backend, which also handles
FTPS when *uri* uses the `ftps` scheme.

### *class* scrapy.extensions.feedexport.GCSFeedStorage(uri: str, project_id: str | None, acl: str | None, \*, feed_options: dict[str, Any] | None = None, timeout: float | None = None)

GCS (see Google Cloud Storage (GCS)) storage backend.

### *class* scrapy.extensions.feedexport.S3FeedStorage(uri: str, access_key: str | None = None, secret_key: str | None = None, acl: str | None = None, endpoint_url: str | None = None, \*, feed_options: dict[str, Any] | None = None, session_token: str | None = None, region_name: str | None = None, max_pool_connections: int | None = None, upload_timeout: float | None = None)

Amazon S3 (see S3) storage backend.

### *class* scrapy.extensions.feedexport.StdoutFeedStorage(uri: str, \_stdout: IO[bytes] | None = None, \*, feed_options: dict[str, Any] | None = None)

Standard output storage backend.
