# @sanity/export

> Export Sanity documents and assets

Latest version **7.1.0** (published 2026-10-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sanity/export
pnpm add @sanity/export
yarn add @sanity/export
bun add @sanity/export
```

Provides the command `detect-corrupt`.

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 7.1.0 |
| Published | 2026-10-27 |
| First published | 2018-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.12 |
| Dependencies | 4 |
| Unpacked size | 249.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 7 |
| Author | Sanity.io |
| Maintainers | sanity-svc.npm, sanity-io |
| Keywords | cms, content, export, headless, ndjson, realtime, sanity |

## Links

- npm: https://www.npmjs.com/package/@sanity/export
- Repository: https://github.com/sanity-io/export
- Homepage: https://www.sanity.io/
- Issues: https://github.com/sanity-io/export/issues
- npm.io page: https://npm.io/package/@sanity/export

## Dependencies (4)

- [obug](https://npm.io/package/obug.md) ^3.0.0
- [get-it](https://npm.io/package/get-it.md) ^9.5.4
- [p-queue](https://npm.io/package/p-queue.md) ^9.0.1
- [modern-tar](https://npm.io/package/modern-tar.md) ^0.8.5

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 7.1.0 (latest) — 2026-10-27
- 6.0.6-alpha.0 (alpha) — 2026-02-26
- 2.36.6 (v2) — 2024-11-07
- 3.37.3-cds-unstable.27 (cds-unstable) — 2024-04-11
- 3.37.2-canary.9 (canary) — 2024-04-09
- 3.36.5-next.86 (next) — 2024-04-09
- 3.36.5-v3-esm.81 (v3-esm) — 2024-04-08
- 3.29.2-pt-input.68 (pt-input) — 2024-02-15
- 3.28.1-pt-input-focuspath.31 (pt-input-focuspath) — 2024-02-13
- 3.23.5-purple-monkey-dishwasher.35 (purple-monkey-dishwasher) — 2024-01-09
- 3.23.5-edx-980.36 (edx-980) — 2024-01-09
- 3.23.5-comments.29 (comments) — 2024-01-09
- 3.23.5-facelift.24 (facelift) — 2024-01-06
- 3.22.3 (stable) — 2023-12-21
- 3.23.2-EDX937.1 (EDX937) — 2023-12-21
- … 1061 more at https://npm.io/package/@sanity/export/versions

## README

# @sanity/export

Exports documents and assets from a Sanity dataset

## Installing

```
npm install --save @sanity/export
```

## Usage

```js
import {exportDataset} from '@sanity/export'

exportDataset({
  // Instance of @sanity/client configured to correct project ID and dataset
  client: someInstantiatedSanityClientInstance,

  // Name of dataset to export
  // Cannot be combined with `mediaLibraryId`.
  dataset: 'myDataset',

  // Path to write tar.gz-archive file to, or `-` for stdout
  outputPath: '/home/your-user/myDataset.tar.gz',

  // Whether or not to export assets. Note that this operation is currently slightly lossy;
  // metadata stored on the asset document itself (original filename, for instance) might be lost
  // Default: `true`
  assets: false,

  // Exports documents only, without downloading or rewriting asset references
  // Default: `false`
  raw: true,

  // Whether or not to export drafts and versions. This also controls the
  // release (`_.releases.*`) and variant definition (`_.variants.*`) system
  // documents those versions depend on.
  // Default: `true`
  drafts: true,

  // Export only given document types (`_type`)
  // Optional, default: all types
  // Includes images/files referenced by these documents. Explicitly include
  // 'sanity.imageAsset' or 'sanity.fileAsset' to include unused assets too.
  types: ['products', 'shops'],

  // Run 12 concurrent asset downloads
  assetConcurrency: 12,

  // What mode to use when exporting documents, can be eiter `stream`(default) or `cursor`.
  // Cursor mode might help when dealing with large datasets, but might yield inconsistent results if the dataset is mutated during export.
  // Default: 'stream'
  mode: 'stream',

  // Export data from a media library, instead of a dataset.
  // Cannot be combined with `dataset`.
  mediaLibraryId: 'myMediaLibrary',

  // Whether to include the `assets.json` assets map. This file is not necessary when creating a
  // media library archive.
  // Caution: customising this option may result in an archive being produced that is impossible to import.
  // Optional, default: `true`
  assetsMap: true,

  // Whether to strictly enforce asset verification (hash and content-length checks against
  // the `x-sanity-sha1` / `x-sanity-md5` response headers). Set to `false` to keep assets
  // that fail verification (with a warning) instead of aborting the export.
  // Caution: disable only when recovering from known-bad source data (e.g. assets where the
  // originally-uploaded bytes are no longer available server-side).
  // Optional, default: `true`
  strictAssetVerification: true,

  // A custom filter function for controlling which documents are exported.
  // Optional, default: `() => true`
  filterDocument: (document) => (document.title ?? '').includes('capybara'),

  // A custom transformation function for controlling how each document is exported.
  // Caution: customising this option may result in an archive being produced that is impossible to import.
  // Optional, default: `document => document`
  transformDocument: (document) => ({
    ...document,
    title: document.title ?? 'capybara',
  }),
})
```

## Future improvements

- Restore original filenames, keep track of duplicates, increase counter (`filename (<num>).ext`)
- Skip archiving on raw/no-asset mode?

## CLI-tool

This functionality is built in to the `@sanity/cli` package as `sanity dataset export`

## License

MIT-licensed. See LICENSE.

### Assets in typed exports

With assets enabled, `types: ['blogPost']` includes the posts and their referenced images
and files, including nested fields and asset metadata. Shared assets download once.
References to other document types, such as authors or categories, are not followed.
Include those types when the destination needs those documents too.

Use `raw: true` to preserve original references without downloading assets when importing
back into a dataset that already has them. `assets: false` removes image/file fields.
Explicit asset types include all assets of those types, including unused assets.

Missing asset documents, missing download URLs, and HTTP 401, 403, or 404 responses are
skipped. This preserves the existing behavior for unavailable files, but the resulting
export may be incomplete. Other download failures still fail the export after any retries.
File outputs replace the destination after the archive is complete; a failed export
preserves an existing destination. Writable-stream consumers must discard output when
the export promise rejects.

Asset documents retrieved separately are read after the selected documents and may have
changed since the export started. This does not repair previously broken archives or
make imports transactional.

---
_Source: https://npm.io/package/@sanity/export · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
