Skip to main content

Comparable

Build Status
Coverage Status
PyPI Version
PyPI Downloads

Comparable is a library providing abstract base classes that enable subclasses to be compared for “equality” and “similarity” based on their attributes.

Getting Started

Requirements

  • Python 3.3+

Installation

Comparable can be installed with ‘pip’:

pip install Comparable

Or directly from the source code:

git clone https://github.com/jacebrowning/comparable.git
cd comparable
python setup.py install

Basic Usage

After installation, abstract base classes can be imported from the package:

python
>>> import comparable
comparable.__version__
>>> from comparable import SimpleComparable, CompoundComparable

Comparable classes use == as the operation for “equality” and % as the operation for “similarity”. They may also override a threshold attribute to set the “similarity” ratio.

Simple Comparables

Simple comparable types must override the equality and similarity methods to return bool and Similarity objects, respectively. See comparable.simple for examples.

Compound Comparables

Compound comparable types contain multiple simple comparable types. They must override the attributes property to define which attributes should be used for comparison. See comparable.compund for examples.

Examples

Comparable includes many generic comparable types:

python
>>> from comparable.simple import Number, Text, TextEnum, TextTitle
>>> from comparable.compound import Group

A basic script may look similar to the following:

from comparable.simple import TextTitle
from comparable import tools

base = TextTitle("The Cat and the Hat")
items = [TextTitle("cat & hat"), TextTitle("cat & the hat")]

print("Equality: {}".format(base == items[0]))
print("Similarity: {}".format(base % items[0]))

print("Duplicates: {}".format(tools.duplicates(base, items)))

For Contributors

Requirements

Installation

Create a virtualenv:

make env

Run the tests:

make test
make tests  # includes integration tests

Build the documentation:

make doc

Run static analysis:

make pep8
make pep257
make pylint
make check  # includes all checks

Prepare a release:

make dist  # dry run
make upload

Changelog

0.2 (2014/05/12)

  • Added similarity assertions to the TestCase class.

0.1.1 (2014/03/03)

  • README cleanup.

0.1 (2014/03/03)

  • Code cleanup.

0.0.3 (2013/10/13)

  • Comparable.threshold is now an attribute (instead of property)

  • Fixed package-level imports

0.0.2 (2013/10/04)

  • Replaced Comparable.equality_list/similarity_dict with attributes

  • Replaced Comparable.similarity_threshold with threshold

0.0.1 (2013/10/02)

  • Initial release of Comparable.

Release files for Comparable 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Comparable 0.2
File Size Uploaded
Comparable-0.2.tar.gz 14.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Comparable 0.2
File Interpreter ABI Platform
Comparable-0.2-py3-none-any.whl Python 3 none any Details

Total release size: 32.8 kB

Release files / Comparable-0.2.tar.gz

Download URL Comparable-0.2.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d3f8c20d9150ce4ada667cb3bf9ea886ca556507374b51d1105c5cef5037e46f
BLAKE2b-256 checksum
How to use checksums
0005de8f1001fa7d4c1a125f09aa11ed6cbfc96104f4f3c3d5b1c0d0cfcfd851
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / Comparable-0.2-py3-none-any.whl

Download URL Comparable-0.2-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08295b41fee8bfd773065c82fed0b8015cd35a5e53c85f83dc6dc6e9a96cfd30
BLAKE2b-256 checksum
How to use checksums
840e98491158865d4b24f05c5dc49bc6c6b455ca6964e9aba186b7bff2ea20a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.0

2 release files

0.2.1

2 release files

This release

0.2 This release

2 release files

0.1.1

2 release files

0.1

2 release files

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

0.0.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page