Skip to main content

UNKNOWN

Project description

https://travis-ci.org/rshk/differ.svg?branch=master https://coveralls.io/repos/rshk/differ/badge.png

Python library to calculate differences between objects.

Right now, it supports calculating differences between objects built up of dicts, lists, tuples and base types.

The major advantage compared to other diff tools is it is able to detect “slightly” changed objects that were repositioned in a list:

from differ import compare_objects

seq1 = [
    {'a': 1, 'b': 1, 'c': 1},
    {'a': 2, 'b': 2, 'c': 2},
    {'a': 3, 'b': 3, 'c': 3},
]

seq2 = [
    {'a': 30, 'b': 30, 'c': 3},
    {'a': 2, 'b': 20, 'c': 2},
    {'a': 1, 'b': 1, 'c': 10},
]

diff = compare_objects(seq1, seq2)

Result:

{'added': [],
 'changed': [0, 1, 2],
 'distance': 1.0,
 'equal': [],
 'removed': [],
 'total': 3,
 'changes': {
    0: {
        'diff': {
            'added': [],
            'changed': ['c'],
            'changes': {'c': {'distance': 1.0, 'left': 1, 'right': 10}},
            'distance': 0.3333333333333333,
            'equal': ['a', 'b'],
            'removed': [],
            'total': 3},
        'distance': 0.3333333333333333,
        'pos': 2},
    1: {
        'diff': {
            'added': [],
            'changed': ['b'],
            'changes': {'b': {'distance': 1.0, 'left': 2, 'right': 20}},
            'distance': 0.3333333333333333,
            'equal': ['a', 'c'],
            'removed': [],
            'total': 3},
        'distance': 0.3333333333333333,
        'pos': 1},
    2: {
        'diff': {
            'added': [],
            'changed': ['a', 'b'],
            'changes': {'a': {'distance': 1.0, 'left': 3, 'right': 30},
                        'b': {'distance': 1.0, 'left': 3, 'right': 30}},
            'distance': 0.6666666666666666,
            'equal': ['c'],
            'removed': [],
            'total': 3},
        'distance': 0.6666666666666666,
        'pos': 0}}}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

differ-0.1a.tar.gz (2.7 kB view details)

Uploaded Source

File details

Details for the file differ-0.1a.tar.gz.

File metadata

  • Download URL: differ-0.1a.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for differ-0.1a.tar.gz
Algorithm Hash digest
SHA256 bd73e357df4f1b112d45826dc86b6f2db685ba8b3caf9e8411333b5a458bb9c0
MD5 4bab655aa4da6965de97de48bf658f9a
BLAKE2b-256 1d1cdc2bc2ddf9c58b96f589ae0e30e01f97ff8cb5c36c8214ae79cdd2eed665

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page