---
title: "Attachments"
description: "Learn more about how Sentry can store additional files in the same request as event attachments."
url: https://docs.sentry.io/platforms/python/enriching-events/attachments/
---

# Attachments | Sentry for Python

Sentry can enrich your events for further investigation by storing additional files, such as config or log files, as attachments.

## [Uploading Attachments](https://docs.sentry.io/platforms/python/enriching-events/attachments.md#uploading-attachments)

Because attachments live on the [Scope](https://docs.sentry.io/platforms/python/enriching-events/scopes.md), the SDK sends all attachments on a given `Scope` with every non-transaction event captured within the `Scope`. It's also possible to send an attachment with all events, including transactions by setting the `add_to_transactions` option to `True`.

```python
# Add an attachment
import sentry_sdk

scope = sentry_sdk.get_current_scope()
scope.add_attachment(bytes=b"Hello World!", filename="attachment.txt")
scope.add_attachment(path="/path/to/attachment/file.txt")
```

The `add_attachment` method has the following parameters:

* `bytes`: Raw bytes of the attachment, or a function that returns the raw bytes. Must be provided unless a `path` to the attachment file is provided.
* `filename`: The filename of the attachment which we display in Sentry. Optional only if a `path` is provided, since we can infer the `filename` from the `path`.
* `path`: Path to a file to attach. Must be provided unless `bytes` is provided.
* `content_type`: The attachment's [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml). If not provided, it will be guessed from the attachment's file name provided via `filename` or inferred from `path`.
* `add_to_transactions`: Whether to add this attachment to transactions. Defaults to `False`.

Sentry allows at most 40MB for a compressed request, and at most 200MB of uncompressed attachments per event, including the crash report file (if applicable). Uploads exceeding this size are rejected with HTTP error `413 Payload Too Large` and the data is dropped immediately. To add larger or more files, consider secondary storage options.

Attachments persist for 30 days; if your total storage included in your quota is exceeded, attachments will not be stored. You can delete attachments or their containing events at any time. Deleting an attachment does not affect your quota - Sentry counts an attachment toward your quota as soon as it is stored.

Learn more about how attachments impact your [quota](https://docs.sentry.io/pricing/quotas.md).

## [Add or Modify Attachments Before Sending](https://docs.sentry.io/platforms/python/enriching-events/attachments.md#add-or-modify-attachments-before-sending)

It's possible to add, remove, or modify attachments before an event is sent by way of the [`before_send`](https://docs.sentry.io/platforms/python/configuration/options.md#before-send)hook or an [event processor](https://docs.sentry.io/platforms/python/enriching-events/event-processors.md).

```python
from sentry_sdk.scope import add_global_event_processor
from sentry_sdk.types import Event, Hint
from sentry_sdk.attachments import Attachment

@add_global_event_processor
def event_processor(event: Event, hint: Hint):
    hint["attachments"] = [Attachment(bytes=b"Hello World!", filename="attachment.txt")]
    return event
```

### [Access to Attachments](https://docs.sentry.io/platforms/python/enriching-events/attachments.md#access-to-attachments)

To limit access to attachments, navigate to your organization's **General Settings**, then select the *Attachments Access* dropdown to set appropriate access — any member of your organization, the organization billing owner, member, admin, manager, or owner.

By default, access is granted to all members when storage is enabled. If a member does not have access to the project, the ability to download an attachment is not available; the button will be greyed out in Sentry. The member may only view that an attachment is stored.

## [Viewing Attachments](https://docs.sentry.io/platforms/python/enriching-events/attachments.md#viewing-attachments)

Attachments display on the bottom of the **Issue Details** page for the event that is shown.

Alternately, attachments also appear in the *Attachments* tab on the **Issue Details** page, where you can view the *Type* of attachment, as well as associated events. Click the Event ID to open the **Issue Details** of that specific event.
