Import/Export by command line
The export/import command-line functions enable you to:
- Export: Export all traces, spans, datasets, prompts, and evaluation rules 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
- Backup: Create local backups of your project data
opik export WORKSPACE_OR_PROJECT
Exports all trace data from the specified workspace or project to local files.
Arguments:
WORKSPACE_OR_PROJECT
: Either a workspace name (e.g., “my-workspace”) to export all projects, or workspace/project (e.g., “my-workspace/my-project”) to export a specific project
Options:
--path, -p
: Directory to save exported data (default:./
)--max-results
: Maximum number of items to export per data type (default: 1000)--filter
: Filter string using Opik Query Language (OQL) to narrow down the search--include
: Data types to include (traces, datasets, prompts)--exclude
: Data types to exclude--all
: Include all data types--name
: Filter items by name using Python regex patterns--trace-format
: Format for exporting traces (json
orcsv
, default:json
)--debug
: Enable debug output to show detailed information about the export process
Examples:
opik import WORKSPACE_FOLDER WORKSPACE_NAME
Imports trace data from local files to the specified workspace or project.
Arguments:
WORKSPACE_FOLDER
: Directory containing JSON files to importWORKSPACE_NAME
: The name of the workspace or workspace/project to import traces to
Options:
--dry-run
: Show what would be imported without actually importing--include
: Data types to include (traces, datasets, prompts)--exclude
: Data types to exclude--all
: Include all data types--name
: Filter items by name using Python regex patterns
Examples:
File Format
JSON Format (Default)
The exported data is stored in JSON files with the following structure:
Each trace file contains:
Each evaluation rule file contains:
CSV Format
When using --trace-format csv
, traces are 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:
CSV Format Benefits:
- Single File: All traces combined into one
traces.csv
file - 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.
Example CSV Structure:
Use Cases
1. Project Migration
2. Data Backup
3. Environment Sync
4. Data Analysis
5. Dataset Management
6. Data Analysis with CSV
Error Handling
The commands include comprehensive error handling:
- Network errors: Automatic retry with user feedback
- Authentication errors: Clear error messages with setup instructions
- File system errors: Proper directory creation and permission handling
- Data validation: JSON format validation and error reporting
Progress Tracking
Both commands show progress indicators:
- Export: Shows number of traces found and export progress
- Import: Shows number of files found and import progress
- Rich output: Color-coded status messages and progress bars
Limitations
- Large datasets: For projects with many traces, consider using filters to limit exports
- Network dependency: Requires active connection to Opik server
- Authentication: Must be properly configured with API keys
- File size: Large trace files may take time to process
Troubleshooting
Common Issues
-
“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
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 trace data between projects while maintaining data integrity and providing visibility into the process. The CSV format is particularly useful for data analysis and reporting.