CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-deepdiff

Deep Difference and Search of any Python object/data with delta and hash capabilities.

Pending
Overview
Eval results
Files

cli.mddocs/

Command Line Interface

Full-featured command-line interface providing access to all DeepDiff functionality through terminal commands. The CLI supports file-based operations, various output formats, and extensive configuration options for comparing, searching, hashing, and manipulating Python objects.

Installation

The CLI functionality requires the optional CLI dependencies:

pip install deepdiff[cli]

Capabilities

Deep Diff Command

Compare two objects from files or command line with extensive formatting and filtering options.

# Basic comparison
deep diff file1.json file2.json

# Compare with options
deep diff file1.json file2.json \
  --ignore-order \
  --ignore-case \
  --ignore-type-changes \
  --significant-digits 2 \
  --report-type text \
  --output-file result.json

# Compare with path filtering
deep diff file1.json file2.json \
  --exclude-paths "root['timestamp']" "root['metadata']" \
  --include-paths "root['data']"

# Compare with custom view
deep diff file1.json file2.json \
  --view tree \
  --verbose-level 2 \
  --color-output

Grep Command

Search for objects within files using flexible matching criteria.

# Basic search
deep grep "search_term" data.json

# Search with options
deep grep "pattern" data.json \
  --case-sensitive \
  --match-string \
  --use-regexp \
  --output-file results.json

# Search with path filtering
deep grep "value" data.json \
  --exclude-paths "root['metadata']" \
  --exclude-types "int" "float"

Extract Command

Extract values from nested objects using path notation.

# Extract single value
deep extract "root['user']['name']" data.json

# Extract multiple paths
deep extract \
  "root['user']['name']" \
  "root['user']['email']" \
  "root['settings']['theme']" \
  data.json

# Extract with output formatting
deep extract "root['data']" input.json \
  --output-file extracted.json \
  --format json

Patch Command

Apply delta patches to objects with backup and safety options.

# Apply patch to file
deep patch original.json delta.json

# Apply patch with backup
deep patch original.json delta.json \
  --backup \
  --output-file patched.json

# Apply patch with validation
deep patch original.json delta.json \
  --validate \
  --log-errors

Command Options

Global Options

Options available across all commands:

--help                    # Show help message
--version                 # Show version information
--output-file FILE        # Write output to file instead of stdout
--format FORMAT           # Output format (json, yaml, text)
--verbose                 # Enable verbose output
--quiet                   # Suppress non-error output
--color / --no-color      # Enable/disable colored output

Diff-Specific Options

--ignore-order                    # Ignore order of elements
--ignore-case                     # Ignore string case differences
--ignore-type-changes             # Ignore type changes between compatible types
--ignore-numeric-type-changes     # Ignore numeric type differences
--significant-digits N            # Number of significant digits for floats
--exclude-paths PATH [PATH...]    # Paths to exclude from comparison
--exclude-regex-paths REGEX [REGEX...]  # Regex patterns for paths to exclude
--exclude-types TYPE [TYPE...]    # Types to exclude from comparison
--include-paths PATH [PATH...]    # Paths to include (exclude all others)
--report-type TYPE                # Report type (text, tree, delta)
--view TYPE                       # View type (text, tree)
--verbose-level LEVEL             # Verbosity level (0-2)
--get-deep-distance              # Calculate distance metric
--group-by FIELD                 # Group similar changes
--math-epsilon FLOAT             # Epsilon for float comparisons
--ignore-private-variables       # Ignore private attributes
--ignore-string-type-changes     # Ignore string type differences
--ignore-encoding-errors         # Ignore encoding errors
--cache-size SIZE                # LRU cache size for comparisons

Search-Specific Options

--case-sensitive          # Case sensitive string matching
--match-string           # Match strings partially
--use-regexp             # Treat search term as regular expression
--exclude-paths PATH [PATH...]     # Paths to exclude from search
--exclude-regex-paths REGEX [REGEX...]  # Regex patterns to exclude
--exclude-types TYPE [TYPE...]     # Types to exclude from search
--include-paths PATH [PATH...]     # Paths to include in search
--verbose-level LEVEL    # Verbosity level (0-2)
--return-paths          # Return paths instead of values
--strict-checking       # Use strict type checking

Extract-Specific Options

--default VALUE          # Default value if path not found
--ignore-errors         # Continue on path errors
--validate-paths        # Validate path syntax before extraction
--multiple-paths        # Extract multiple paths (default for multiple arguments)

Patch-Specific Options

--backup                # Create backup before applying patch
--validate              # Validate patch before applying
--log-errors           # Log errors during patch application
--dry-run              # Show what would be changed without applying
--force                # Force application even with warnings
--bidirectional        # Enable bidirectional patch operations

Usage Examples

File Comparison

# Compare JSON files
deep diff config_old.json config_new.json

# Compare with specific options
deep diff database_v1.json database_v2.json \
  --ignore-order \
  --exclude-paths "root['timestamp']" "root['version']" \
  --significant-digits 3 \
  --output-file changes.json

YAML and Other Formats

# Compare YAML files (requires PyYAML)
deep diff config.yaml config_new.yaml --format yaml

# Compare mixed formats
deep diff data.json data.yaml --format json

Searching Data

# Search for specific values
deep grep "john@example.com" users.json

# Regex search
deep grep "^admin" users.json --use-regexp

# Case-insensitive partial match
deep grep "john" users.json --match-string --case-sensitive=false

Extracting Values

# Extract user information
deep extract "root['users'][0]['name']" data.json

# Extract multiple fields
deep extract \
  "root['config']['database']['host']" \
  "root['config']['database']['port']" \
  "root['config']['database']['name']" \
  app_config.json

Applying Patches

# Apply changes from diff
deep diff old.json new.json --output-file changes.delta
deep patch old.json changes.delta --output-file updated.json

# Apply with backup
deep patch production.json hotfix.delta --backup

Pipeline Usage

# Use in shell pipelines
cat data.json | deep grep "error" | jq '.matched_values'

# Combine operations
deep diff old.json new.json | deep extract "root['values_changed']"

Advanced Examples

# Complex diff with multiple options
deep diff \
  production.json \
  staging.json \
  --ignore-order \
  --ignore-type-changes \
  --exclude-regex-paths ".*timestamp.*" ".*id.*" \
  --significant-digits 2 \
  --report-type tree \
  --color-output \
  --output-file production_vs_staging.diff

# Batch processing
for file in configs/*.json; do
  deep diff template.json "$file" --output-file "${file%.json}.diff"
done

# Search and extract pipeline
deep grep "error" logs.json \
  --match-string \
  --output-file errors.json && \
deep extract "root['matched_values']" errors.json \
  --output-file error_paths.json

Input/Output Formats

Supported Input Formats

# JSON files (default)
deep diff file1.json file2.json

# YAML files (requires PyYAML)
deep diff file1.yaml file2.yaml

# Python pickle files
deep diff file1.pkl file2.pkl

# CSV files (converted to list of dictionaries)
deep diff file1.csv file2.csv

Output Formats

# JSON output (default)
deep diff file1.json file2.json --format json

# YAML output
deep diff file1.json file2.json --format yaml

# Plain text output
deep diff file1.json file2.json --format text

# Colored text output
deep diff file1.json file2.json --format text --color-output

Configuration

Environment Variables

export DEEPDIFF_COLOR=true          # Enable colored output by default
export DEEPDIFF_VERBOSE=1           # Set default verbosity level
export DEEPDIFF_CACHE_SIZE=1000     # Set default cache size
export DEEPDIFF_OUTPUT_FORMAT=json  # Set default output format

Configuration File

Create a .deepdiff.yaml configuration file:

# Default options for all commands
defaults:
  color_output: true
  verbose_level: 1
  cache_size: 1000

# Command-specific defaults
diff:
  ignore_order: false
  significant_digits: 7
  report_type: "text"

search:
  case_sensitive: true
  match_string: false

extract:
  ignore_errors: false
  validate_paths: true

Types

# Input file types supported
InputFile = Union[JsonFile, YamlFile, PickleFile, CsvFile]

# Output format options  
OutputFormat = Union['json', 'yaml', 'text', 'tree']

# Report types for diff command
ReportType = Union['text', 'tree', 'delta']

# View types for diff command
ViewType = Union['text', 'tree']

# Verbosity levels
VerbosityLevel = Union[0, 1, 2]  # 0=quiet, 1=normal, 2=verbose

Install with Tessl CLI

npx tessl i tessl/pypi-deepdiff

docs

cli.md

delta.md

difference.md

extract.md

hashing.md

index.md

search.md

tile.json