---
title: "Bulk Insert Attachments"
url: "https://docs.ravendb.net/6.2/document-extensions/attachments/bulk-insert"
version: "6.2"
language: "python"
---

# Bulk Insert Attachments

> Client language: Python. Also available for [C#](https://docs.ravendb.net/6.2/document-extensions/attachments/bulk-insert.md), [Node.js](https://docs.ravendb.net/6.2/document-extensions/attachments/bulk-insert.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - [bulk\_insert](https://docs.ravendb.net/6.2/client-api/bulk-insert/how-to-work-with-bulk-insert-operation.md) is RavenDB's
>   high-performance data insertion operation.  
>   Use its `attachments_for` interface to add attachments to multiple documents with great speed.
>
> - Use `store`
>
> - In this page:
>   - [Usage flow](#usage-flow)
>   - [Usage example](#usage-example)

## Usage flow

- Create a `bulk_insert` instance.

- Pass the Document ID to the instance's `attachments_for` method.

- To add an attachment, call the `store` method.  
  Pass it the attachment's name, stream, and type (optional).  
  `store` can be called repeatedly, as many times as needed.

- Note:  
  If an attachment with the specified name already exists on the document,  
  the bulk insert operation will overwrite it.

## Usage example

In this example, we attach a file to all User documents that match a query.

```python
# Choose user profiles for which to attach a file
with store.open_session() as session:
  user_ids = [
      session.advanced.get_document_id(user)
      for user in list(session.query(object_type=User).where_less_than("Age", 30))
  ]

# Prepare content to attach
bytes_to_attach = b"some contents here"

# Create a BulkInsert instance
with store.bulk_insert() as bulk_insert:
  for user_id in user_ids:
      # Call 'attachments_for', pass the document ID for which to attach the file
      attachments_bulk_insert = bulk_insert.attachments_for(user_id)

      # Call 'store' to add the file to the BulkInsert instance
      # The data stored in bulk_insert will be streamed to the server in batches
      attachments_bulk_insert.store("AttachmentName", bytes_to_attach)
```

## See also

- [Storing](https://docs.ravendb.net/6.2/document-extensions/attachments/storing.python.md)
- [Loading](https://docs.ravendb.net/6.2/document-extensions/attachments/loading.python.md)
- [Deleting](https://docs.ravendb.net/6.2/document-extensions/attachments/deleting.python.md)
