# Sanity CLI
> Manage Sanity.io content platform from the command line

## Summary
Official Sanity.io CLI for initializing projects, managing datasets, deploying Sanity Studio, running GraphQL APIs, and handling content data import/export.

## Capabilities
- Initialize and scaffold new Sanity projects
- Run Sanity Studio locally for development
- Deploy Sanity Studio to Sanity hosting
- Export and import datasets for backup and migration
- Deploy and manage GraphQL API endpoints
- Manage datasets and project configuration

## When to Use
- Developing and deploying Sanity.io content projects
- Managing Sanity datasets and content from the terminal
- Exporting or importing Sanity data for backup or migration
- Running Sanity Studio locally during development

## When NOT to Use
- Not using Sanity.io as your content platform
- Prefer the Sanity web UI for all content management
- Managing non-CMS cloud infrastructure

## Key Flags
- `init`: Initialize a new Sanity project
- `start`: Start Sanity Studio in development mode
- `deploy`: Deploy Sanity Studio to Sanity hosting
- `dataset export`: Export a dataset to a local file
- `dataset import`: Import data into a dataset
- `graphql deploy`: Deploy a GraphQL API for the project

## Usage Patterns
### Create a new Sanity project
```
sanity init --project-plan free
```
Scaffolds a new Sanity project with interactive setup

### Start local development
```
sanity start
```
Launches Sanity Studio at localhost:3333 for development

### Export a dataset
```
sanity dataset export production ./backup.tar.gz
```
Exports the production dataset to a compressed archive

### Deploy the Studio
```
sanity deploy
```
Deploys Sanity Studio to the hosted Sanity URL

## Input / Output
- **stdin**: Accepts interactive input for project initialization and confirmations
- **stdout**: Project setup output, deployment status, and dataset information
- **stderr**: Error messages and build warnings

## Installation
- **npm**: `npm i -g @sanity/cli`

## Related Tools
- [contentful-cli](/tools/contentful-cli) (alternative): Contentful CLI manages a competing headless CMS platform
- [hugo](/tools/hugo) (complementary): Hugo can consume Sanity content via API for static site generation

---
Source: https://littlescripts.sh/tools/sanity
