---
title: "openemail.exports"
description: "Every method in this namespace: its signature, its parameters, what it returns and an example."
url: "https://openemail.uk/docs/python/reference/exports"
area: "Python"
category: "Reference"
---

# openemail.exports

Every method in this namespace: its signature, its parameters, what it returns and an example.

## Methods

A zip of the whole workspace, as the Export page makes it: see what it would hold, start one, follow it while it is made and download it once it is ready.

### `exports.preview()`

See what an export would hold

```python
def preview(
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> ExportPreviewResource
```

Returns whether the workspace can be exported by the caller now, when the next export can start, the export still being made, if there is one, and how much an export would hold: conversations, attachments and their size, contacts, audiences, calendar events, templates, rules, labels, notes and addresses. When `allowed` is `False`, `reason` says why and `counts` is `None`.

Only the workspace owner, or a member whose role holds every permission, can export the workspace: an API key, or an access token connected with every address. A key or token limited to particular addresses or domains is 422 `capability_unsupported`, and an account the workspace cannot export for is 403 `export_not_permitted`.

Scopes: `threads:read`.

**Parameters**

- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `OpenEmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`ExportPreviewResource` with `allowed`, `reason`, `nextAvailableAt`, `activeExportId` and `counts`.

**Example**

```python
from openemail import openemail

preview = openemail.exports.preview()

if preview['allowed'] and preview['nextAvailableAt'] is None:
    print('An export can start now:', preview['counts'])
else:
    print('Not now:', preview['reason'], preview['nextAvailableAt'])
```

**Notes**

- `reason` is `not-permitted`, `mailbox-login` or `two-factor-required`, and `EXPORT_REFUSALS` names them.

Also available in: API [`GET /exports/preview`](https://openemail.uk/docs/api/reference/exports#get-exports-preview); TypeScript [`exports.preview()`](https://openemail.uk/docs/sdk/reference/exports#preview); Ruby [`exports.preview`](https://openemail.uk/docs/ruby/reference/exports#preview); CLI [`openemail exports preview`](https://openemail.uk/docs/cli/reference/exports#exports-preview).

### `exports.list()`

List the exports

```python
def list(
    *,
    limit: int | None = None,
    offset: int | None = None,
    api_key: str | None = None,
    timeout: float | None = None,
) -> ExportListResource
```

Returns the exports of the workspace, newest first, a page at a time, each with its status, its progress through the conversations and, once it is `ready`, its size, file name and when it is deleted. Pages are counted by position: raise `offset=` by `limit=` while `hasMore` is `True`.

Only the workspace owner, or a member whose role holds every permission, can export the workspace: an API key, or an access token connected with every address. A key or token limited to particular addresses or domains is 422 `capability_unsupported`, and an account the workspace cannot export for is 403 `export_not_permitted`.

Scopes: `threads:read`.

**Parameters**

- `limit` (`int`): Exports per page, from 1 to 100. The server defaults to 25.
- `offset` (`int`): How many exports to skip.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `OpenEmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`ExportListResource`, a dict with `data`, the exports on this page, `total` and `hasMore`.

**Example**

```python
from openemail import openemail

page = openemail.exports.list(limit=10)

ready = [export for export in page['data'] if export['status'] == 'ready']

print(f'{page["total"]} exports, {len(ready)} ready to download')
```

**Notes**

- A workspace can be exported once a day, and each export is kept for a year, so the list stays short.

Also available in: API [`GET /exports`](https://openemail.uk/docs/api/reference/exports#get-exports); TypeScript [`exports.list()`](https://openemail.uk/docs/sdk/reference/exports#list); Ruby [`exports.list`](https://openemail.uk/docs/ruby/reference/exports#list); CLI [`openemail exports list`](https://openemail.uk/docs/cli/reference/exports#exports-list).

### `exports.get()`

Retrieve an export

```python
def get(
    id: str,
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> ExportResource
```

Returns one export: its `status`, `phase` and progress while it is made, and once it is `ready` its size, file name and when it is deleted.

Only the workspace owner, or a member whose role holds every permission, can export the workspace: an API key, or an access token connected with every address. A key or token limited to particular addresses or domains is 422 `capability_unsupported`, and an account the workspace cannot export for is 403 `export_not_permitted`.

Scopes: `threads:read`.

**Parameters**

- `id` (`str`, required): The export id from `start` or `list`.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `OpenEmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`ExportResource` with `id`, `status`, `phase`, `threadsDone`, `threadsTotal`, `sizeBytes`, `fileName`, `error`, `createdBy` and its timestamps.

**Example**

```python
import time

from openemail import openemail

export = openemail.exports.get('exp_8c1e4a7f2b9d3e6a0c5f1b28')

for _ in range(30):
    if export['status'] in ('ready', 'failed', 'expired'):
        break

    time.sleep(10)
    export = openemail.exports.get(export['id'])
    print(export['phase'], export['threadsDone'], 'of', export['threadsTotal'])

print(export['status'], export['fileName'], export['sizeBytes'])
```

**Notes**

- An unknown id is a 404, which raises `OpenEmailApiError` with `is_not_found` set.

Also available in: API [`GET /exports/{id}`](https://openemail.uk/docs/api/reference/exports#get-exports-id); TypeScript [`exports.get()`](https://openemail.uk/docs/sdk/reference/exports#get); Ruby [`exports.get`](https://openemail.uk/docs/ruby/reference/exports#get); CLI [`openemail exports get`](https://openemail.uk/docs/cli/reference/exports#exports-get).

### `exports.start()`

Start an export

```python
def start(*, api_key: str | None = None, timeout: float | None = None) -> ExportResource
```

Starts making a zip of the whole workspace, as Export now on the Export page does, and returns the export, `queued`. It is made in the background: poll `get` until `status` is `ready`, then `download` it. One export runs at a time, and a workspace can be exported once a day.

Only the workspace owner, or a member whose role holds every permission, can export the workspace: an API key, or an access token connected with every address. A key or token limited to particular addresses or domains is 422 `capability_unsupported`, and an account the workspace cannot export for is 403 `export_not_permitted`.

Scopes: `threads:read`.

**Parameters**

- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `OpenEmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`ExportResource` for the new export.

**Example**

```python
from openemail import OpenEmailApiError, openemail

try:
    export = openemail.exports.start()
except OpenEmailApiError as error:
    if error.code in ('already_running', 'export_limit_reached'):
        print('No new export yet:', error.message)
    else:
        raise
else:
    print(export['id'], export['status'])
```

**Notes**

- With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 `step_up_required`, and `is_step_up_required` on the error says so. An API key is never asked.
- An export already being made is 409 `already_running`, and a workspace exported in the last day is 429 `export_limit_reached`.
- The SDK does not retry it.

Also available in: API [`POST /exports`](https://openemail.uk/docs/api/reference/exports#post-exports); TypeScript [`exports.start()`](https://openemail.uk/docs/sdk/reference/exports#start); Ruby [`exports.start`](https://openemail.uk/docs/ruby/reference/exports#start); CLI [`openemail exports start`](https://openemail.uk/docs/cli/reference/exports#exports-start).

### `exports.download()`

Download an export

```python
def download(
    id: str,
    *,
    api_key: str | None = None,
    timeout: float | None = None,
) -> bytes
```

Returns the zip of a `ready` export as `bytes`, the same file the Download action on the Export page saves.

Only the workspace owner, or a member whose role holds every permission, can export the workspace: an API key, or an access token connected with every address. A key or token limited to particular addresses or domains is 422 `capability_unsupported`, and an account the workspace cannot export for is 403 `export_not_permitted`.

Scopes: `threads:read`.

**Parameters**

- `id` (`str`, required): The export id from `start` or `list`.
- `api_key` (`str`): Overrides the client's API key for this call only.
- `timeout` (`float`): Seconds this call may take, the response included, before it raises `OpenEmailNetworkError` with `is_timeout`. It overrides the client's `timeout` for this call, and `0` turns the limit off.

**Returns**

`bytes` holding the zip.

**Example**

```python
from pathlib import Path

from openemail import openemail

export = openemail.exports.get('exp_8c1e4a7f2b9d3e6a0c5f1b28')
archive = openemail.exports.download(export['id'], timeout=600)

target = Path(export['fileName'] or 'openemail-export.zip')
target.write_bytes(archive)

print(f'Saved {len(archive)} bytes to {target}')
```

**Notes**

- With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 `step_up_required`, and `is_step_up_required` on the error says so. An API key is never asked.
- Before the export is `ready` the call is 409 `export_not_ready`, and an export older than a year is 409 `expired`.
- The whole zip is held in memory, and a large workspace makes a large zip. Give the call a longer `timeout=` for a large one, since the limit covers reading the whole file.

Also available in: API [`GET /exports/{id}/content`](https://openemail.uk/docs/api/reference/exports#get-exports-id-content); TypeScript [`exports.download()`](https://openemail.uk/docs/sdk/reference/exports#download); Ruby [`exports.download`](https://openemail.uk/docs/ruby/reference/exports#download); CLI [`openemail exports download`](https://openemail.uk/docs/cli/reference/exports#exports-download).
