Metadata-Version: 2.1
Name: comparator
Version: 0.2.1
Summary: Utility for comparing results between data sources
Home-page: https://github.com/aaronbiller/comparator
Author: Aaron Biller
Author-email: aaronbiller@gmail.com
License: Apache 2.0
Description: ![Comparator](https://raw.githubusercontent.com/aaronbiller/comparator/master/docs/comparator.jpg "Comparator")
        # Comparator
        
        [![pypi](https://img.shields.io/pypi/v/comparator.svg)](https://pypi.org/project/comparator/)
        [![versions](https://img.shields.io/pypi/pyversions/comparator.svg)](https://pypi.org/project/comparator/)
        [![CircleCI](https://circleci.com/gh/aaronbiller/comparator/tree/master.svg?style=shield)](https://circleci.com/gh/aaronbiller/comparator/tree/master)
        [![Coverage Status](https://coveralls.io/repos/github/aaronbiller/comparator/badge.svg?branch=master)](https://coveralls.io/github/aaronbiller/comparator?branch=master)
        
        Comparator is a utility for comparing the results of queries run against two databases. Future development will include support for APIs, static files, and more.
        
        
        ## Installation
        ```bash
        pip install comparator
        ```
        
        ## Usage
        ### Overview
        ```python
        from comparator import Comparator
        from comparator.config import DbConfig
        from comparator.db import PostgresDb
        
        conf = DbConfig()
        
        l = PostgresDb(**conf.default)
        r = PostgresDb(**conf.other_db)
        query = 'SELECT * FROM my_table ORDER BY 1'
        
        c = Comparator(l, r, query)
        c.run_comparisons()
        ```
        ```
        [('first_eq_comp', True)]
        ```
        
        ### Included Comparisons
        There are some basic comparisons included, and they can be imported and passed using constants.
        ```python
        from comparator.comps import BASIC_COMP, LEN_COMP
        
        c = Comparator(l, r, query, comparisons=[BASIC_COMP, LEN_COMP])
        c.run_comparisons()
        ```
        ```
        [('basic_comp', True), ('len_comp', True)]
        ```
        
        ### Queries and Exceptions
        It's possible to run different queries against each database. You can raise exceptions if that's your speed.
        ```python
        lq = 'SELECT * FROM my_table ORDER BY 1'
        rq = 'SELECT id, uuid, name FROM reporting.my_table ORDER BY 1'
        comparisons = [BASIC_COMP, LEN_COMP]
        
        c = Comparator(l, r, left_query=lq, right_query=rq, comparisons=comparisons)
        
        for name, success in c.compare():
            if not success:
                raise Exception('{} check failed!'.format(name))
        ```
        
        ### Custom Comparisons
        Finally, you'll probably want to define your own comparison checks. You can do so by defining functions that accept `left` and `right` args, which, if coming from one of the included database classes, will be a list of tuples representing your query result. Perform whatever magic you like, and return a boolean.
        ```python
        def left_is_longer(left, right):
            # Return True if left contains more rows than right
            return len(left) > len(right)
        
        
        def totals_are_equal(left, right):
            # Return True if sum(left) == sum(right)
            sl = sr = 0
            for row in left:
                sl += int(row[1])
            for row in right:
                sr += int(row[1])
            return sl == sr
        
        
        c = Comparator(l, r, query, comparisons=[left_is_longer, totals_are_equal])
        c.run_comparisons()
        ```
        ```
        [('left_is_longer', False), ('totals_are_equal', True)]
        ```
        
        
        # Changelog
        
        ## 0.2.1 (2018-09-19)
        - officially support Python 2.7, 3.6, and 3.7
        
        ## 0.2.0 (2018-09-18)
        - add `query_df` methods for returning pandas DataFrames
        - add `output` kwarg to Comparator to allow calling the `query_df` method
        
        ## 0.1.0 (2018-09-12)
        - initial release
Keywords: utility compare database
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Topic :: Database
Classifier: Topic :: Utilities
Description-Content-Type: text/markdown
