---
title: "Migrate from Raven"
description: "Learn about migrating from raven to sentry-python"
url: https://docs.sentry.io/platforms/python/migration/raven-to-sentry-sdk/
---

# Migrate from Raven | Sentry for Python

This guide describes the common patterns involved in migrating from `raven-python` to the `sentry-python` SDK.

## [Installation](https://docs.sentry.io/platforms/python/migration/raven-to-sentry-sdk.md#installation)

The installation is now the same regardless of framework or library you integrate with. There are no alternative initialization routines other than `sentry_sdk.init`. For integration-specific instructions please refer to [our list of guides for the new SDK](https://docs.sentry.io/platforms/python.md).

**Old**:

```python
import raven
client = raven.Client("___PUBLIC_DSN___", release="1.3.0")
```

**New**:

```python
import sentry_sdk
sentry_sdk.init(
    dsn="___PUBLIC_DSN___",
    release="1.3.0",
)
```

## [Set a Global Tag](https://docs.sentry.io/platforms/python/migration/raven-to-sentry-sdk.md#set-a-global-tag)

**Old**:

```python
client.tags_context({'key': 'value'})
```

**New**:

```python
sentry_sdk.set_tag('key', 'value')
```

## [Capture Custom Exception](https://docs.sentry.io/platforms/python/migration/raven-to-sentry-sdk.md#capture-custom-exception)

**Old**:

```python
try:
    throwing_function()
except Exception:
    client.captureException(extra={'debug': False})
```

**New**:

```python
with sentry_sdk.push_scope() as scope:
    scope.set_extra('debug', False)

    try:
        throwing_function()
    except Exception as e:
        sentry_sdk.capture_exception(e)
```

## [Capture a Message](https://docs.sentry.io/platforms/python/migration/raven-to-sentry-sdk.md#capture-a-message)

**Old**:

```python
client.captureMessage('test', level='info', extra={'debug': False})
```

**New**:

```python
with sentry_sdk.push_scope() as scope:
    scope.set_extra('debug', False)
    sentry_sdk.capture_message('test', 'info')
```

## [Breadcrumbs](https://docs.sentry.io/platforms/python/migration/raven-to-sentry-sdk.md#breadcrumbs)

**Old**:

```python
from raven import breadcrumbs

breadcrumbs.record(
    message='Item added to shopping cart',
    category='action',
    data={
        'isbn': '978-1617290541',
        'cartSize': '3'
    }
)
```

**New**:

```python
sentry_sdk.add_breadcrumb(
  message='Item added to shopping cart',
  category='action',
  data={
    'isbn': '978-1617290541',
    'cartSize': '3'
  }
)
```

## [Filtering Sensitive Data](https://docs.sentry.io/platforms/python/migration/raven-to-sentry-sdk.md#filtering-sensitive-data)

Raven used to have a few built-in heuristics to detect password fields and creditcard numbers. Since those heuristics were the same for everybody, it was impossible to further improve them for a usecase without breaking somebody else's usecase. There is no easy search-and-replace type solution in the new SDK.

We encourage you to consider alternative options outlined at [*Filtering Events*](https://docs.sentry.io/platforms/python/configuration/filtering.md).
