Import/Export by command line
Import/Export by command line
The export/import command-line functions enable you to:
- Export: Export specific traces, spans, datasets, prompts, and experiments from a project to local JSON or CSV files
- Import: Import data from local JSON files into a project
- Migrate: Move data between projects or environments, including experiments and prompts
- Backup: Create local backups of specific project data
opik export WORKSPACE PROJECT ITEM [NAME]
Exports specific data types from the specified project to local files.
Arguments:
WORKSPACE: The workspace name to export fromPROJECT: The project to export from (every dataset, prompt, and experiment belongs to it)ITEM: The kind of data to export (all,dataset,traces,experiment, orprompt)NAME: Exact name of the item to export (not used withallortraces)
Options:
--path, -p: Directory to save exported data (default:opik_exports)--max-results: Maximum number of items to export per data type (default: 1000)--filter: OQL filter string applied to traces — works withtraces,experiment, andall--force: Re-download items even if they already exist locally--format: Format for exporting data (jsonorcsv, default:json)--debug: Enable debug output to show detailed information about the export process--no-attachments: Skip downloading attachment files.--page-size INTEGER: Number of traces to fetch per API request when exporting traces (1–1000, default:500). Applies totracesandall. Increase for fewer round-trips; decrease if you hit persistent rate-limit errors.
all-specific options:
--include: Comma-separated list of data types to include (datasets,prompts,traces,experiments). Defaults to all four.
experiment-specific options:
--dataset NAME: Filter experiments by dataset name (only experiments using this dataset will be exported)--max-traces INTEGER: Maximum number of traces to export (limits total traces downloaded)
Examples:
Use all when you want to export every data type in one shot — useful for full project backups or bulk migrations:
Use dataset, traces, experiment, or prompt when you need to export a specific data type:
Use --filter to narrow exports to a time window or any OQL predicate — avoids downloading data you don’t need:
Use experiment-specific options to scope large experiment exports:
Use --format csv when the target is a spreadsheet or analysis tool rather than a re-import:
Use --no-attachments to skip downloading attachment files (faster exports when you only need trace/span data):
Miscellaneous options:
opik import WORKSPACE PROJECT ITEM [NAME]
Imports specific data types from local files into the specified project.
Arguments:
WORKSPACE: The source workspace name — used to locate the exported files on disk under<path>/WORKSPACE/projects/. Use--to-workspaceto import into a different destination workspace.PROJECT: The project to import from (matched by name against each exportedproject.json)ITEM: The kind of data to import (all,dataset,traces,experiment, orprompt)NAME: Name pattern to match items (case-insensitive substring matching; not used withallortraces)
Options:
--path, -p: Directory containing exported data (default:opik_exports)--to-project NAME: Destination project to import into. Defaults to the source project’s name (thenamerecorded inproject.json). Use this to restore into a renamed or scratch project. Available onall,traces,dataset,experiment, andprompt.--to-workspace NAME: Destination workspace to import into. Defaults toWORKSPACE. Use this to import data exported from one workspace into a different workspace —WORKSPACEis still used to locate the exported files on disk. Available onall,traces,dataset,experiment, andprompt.--dry-run: Show what would be imported without actually importing--force: Discard the migration manifest and re-import everything from scratch--no-attachments: Skip uploading attachment files.--debug: Enable debug output to show detailed information about the import process
Note: Experiment imports automatically recreate experiments where possible. No additional flags are needed.
Note: PROJECT is matched by name against the name recorded in each
exported project.json (folders on disk are named by project ID). Import uses
the same --path as export — both resolve <path>/<workspace>/projects/<id>/ —
so the same --path round-trips with no path juggling.
Resumable imports
Every import automatically maintains a migration_manifest.db SQLite database
under the project directory, in a per-destination subdirectory
(projects/PROJECT_ID/import_manifests/<destination-key>/migration_manifest.db).
It tracks which files have been imported and the ID mappings needed to link
experiments back to their traces. Keying the manifest by destination means
importing the same export into different --to-project targets keeps independent
resume/completion state.
If an import is interrupted (e.g. network error, Ctrl-C), simply re-run the same command — it will resume from where it left off without creating duplicates:
When a previously completed import is re-run:
Use --force to discard the manifest and start fresh.
Examples:
Basic imports — reads from the default opik_exports directory created by opik export:
Use a name pattern when you want to import multiple items whose names share a substring:
Use --to-project to import into a different (e.g. renamed or scratch) destination project. The source folder is still located by the my-project name; the data is created in my-restore:
Use --to-workspace to import into a different workspace than the data was exported from. WORKSPACE still locates the files on disk; --to-workspace controls which workspace the Opik API writes to:
Use --path when your exported data is not in the default opik_exports directory:
Use --dry-run to preview what would be imported before committing — helpful to verify names and counts:
Resuming and forcing — the manifest under the project directory handles resumption automatically; use --force only to start over:
Use --no-attachments to skip uploading attachment files (faster imports when you only need trace/span data):
Use --debug to see per-file status and API call details:
File Format
JSON Format (Default)
The exported data is stored in JSON files with the following structure:
Folders and files are keyed by ID, not by human name. The project folder is
the project’s UUID, and each item file is named by its own ID
(dataset_<dataset_id>.json, prompt_<prompt_id>.json,
experiment_<experiment_id>.json, trace_<trace_id>.json). The human-readable
names live as data — inside project.json and inside each file. This keeps
paths free of characters like /, :, or spaces that commonly appear in names.
You still pass project and item names on the command line; the CLI resolves
names ↔ IDs for you (on import it matches the name you type against the name
recorded in project.json).
Each trace file contains:
Each evaluation rule file contains:
Each experiment file contains:
Each prompt file contains (the file is named prompt_<id>.json; the id and name are stored inside):
CSV Format
When using --format csv, data is exported as CSV files with flattened data structure. This format is ideal for:
- Data Analysis: Easy to import into Excel, Google Sheets, or data analysis tools
- Large Datasets: More efficient storage for large numbers of traces
- Spreadsheet Integration: Direct compatibility with business intelligence tools
CSV File Structure:
As with JSON, CSV files are named by ID; the human names are stored in the
file contents and in project.json.
CSV Format Benefits:
- Single File: All data combined into one CSV file per data type
- Flattened Structure: Nested JSON data is flattened with dot notation
- Column Headers: Clear column names for easy analysis
- Compatible: Works with Excel, Google Sheets, pandas, etc.
- Universal Format: All data types (datasets, traces, experiments, prompts) support CSV export
Example CSV Structure:
Use Cases
1. Migrating between Opik installations
Migration is a two-step process because the source and destination typically
have different API keys. Export with your source credentials, then import with
your destination credentials. The migration_manifest.db created during
import travels with the exported data and makes the import safe to interrupt
and resume.
Export writes to <--path>/<workspace>/projects/<project_id>/, and import reads
the same layout, so use the same --path on both sides. Add --to-project <NAME>
to import into a different destination project, or --to-workspace <NAME> to
import into a different workspace.
To migrate all data types at once:
2. Data Backup
3. Environment Sync
4. Data Analysis
5. Dataset Management
6. Data Analysis with CSV
7. Prompt Management
8. Experiment Migration
Troubleshooting
Common Issues
-
Import was interrupted and re-running creates duplicates
- This should not happen — the import automatically detects and resumes from the per-destination
migration_manifest.dbunderprojects/PROJECT_ID/import_manifests/<destination-key>/ - If you do not see the “Resuming interrupted import” message, check that you are pointing to the same
--path, project, and--to-projectas the original run - If the manifest database is unreadable, delete the
import_manifests/directory and use--forceto start fresh (this will re-import everything)
- This should not happen — the import automatically detects and resumes from the per-destination
-
“Import already completed. Use —force to re-import.”
- The manifest records that a previous run finished successfully
- If you genuinely need to re-import (e.g. the destination was wiped), use
--force
-
Experiment items are missing after import
- Experiments are linked to traces by ID; if the trace import was interrupted and no manifest was present, some mappings may be missing
- Re-run the project import first (it populates the trace ID map in the manifest), then re-run the experiment import
- Use
--debugto see how many trace IDs were matched
-
“No traces found”
- Check if the project name is correct
- Verify you have access to the project
- Try without filters first
-
“Project directory not found”
- Make sure you’ve exported data first
- Check the input directory path
- Verify the project name matches
-
“Opik SDK not available”
- Ensure Opik is properly installed
- Check your Python environment
- Verify the installation with
opik healthcheck
-
“Dataset/Project/Experiment/Prompt not found”
- Check that the exact name is correct
- Verify you have access to the item
- Use
--debugfor more detailed error information
-
“No datasets/projects found”
- The system will show available items to help you choose the right name
- Check spelling and case sensitivity
- Ensure the item exists in the workspace
-
“Dataset not found”
- The system will show datasets used by matching experiments
- Verify the dataset name is correct
- Use
--debugto see detailed search information
-
Export is slow or keeps hitting rate limits
- The exporter automatically retries 429 responses, honouring
Retry-Afterheaders where present - Reduce
--page-size(e.g.--page-size 100) to lower the per-request payload and decrease the chance of triggering rate limits - The exporter pauses between pages and uses at most 3 concurrent workers to stay within server-side limits; no extra configuration is needed
- The exporter automatically retries 429 responses, honouring
Getting Help
Example Workflow
Here’s a complete example of exporting and importing trace data:
JSON Format Workflow
CSV Format Workflow
This workflow ensures you can safely migrate all data including experiments and prompts between workspaces while maintaining data integrity and providing visibility into the process. The CSV format is particularly useful for data analysis and reporting, while the JSON format preserves the complete structure needed for experiment and prompt recreation. The new command structure provides better organization with separate commands for datasets, traces, experiments, and prompts, all scoped to a project, making it easier to manage specific data types.