Skip to main content

A container for dicts of sets - alternative to dictset

Project description

This package provides a collection that is basically a “dict of sets”, named MetaSet.

Build status Supported Python versions Wheel status License


Install the package from PyPI, using pip:

pip install metaset

Or from GitHub:

git clone git://

Import it in your code:

>>> from metaset import MetaSet

Usage is quite straight forward, basic set operations are supported via the binary operators + - | ^.

>>> from pprint import pprint
>>> pprint(MetaSet(a={1, 2}, b={3}) | MetaSet(b={4}, c={5}))
{'a': {1, 2}, 'b': {3, 4}, 'c': {5}}

Django Postgres

A custom Django field is available. It is quite straightforward:

>>> from metaset.django_field import MetaSetField
>>> from django.db import models        # doctest: +SKIP

>>> class MyModel(models.Model):        # doctest: +SKIP
        mset = MetaSetField()           # doctest: +SKIP

It is compatible with the following versions:

  • Django 1.11, Python 2.7
  • Django 2.1, Python 3.6

Detailed considerations

They are two ways to consider the “dict of sets” notion, differing on how you handle the empty values for keys.

The easiest idea is to consider that a key with no content is non-existent. This is how the dictset package is implemented.

In this alternative implementation, we chose to keep the empty keys as meaningful elements, allowing for smart unions and intersections.

>>> pprint(MetaSet(a={1}) | MetaSet(a={2}, b=set()))
{'a': {1, 2}, 'b': set()}

>>> MetaSet(a={1}) & MetaSet(a={2}, b={3})
{'a': set()}

So, beware of how empty-keys are handled, and consider using dictset if it is a better match for your use case. The behavior for subtraction and symmetric difference, although sound on a mathematical point of view, may not be what you want.

>>> MetaSet(a={1}) - MetaSet(a={1})
{'a': set()}

>>> MetaSet(a={1}) ^ MetaSet(a={1})
{'a': set()}

Project details

Download files

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

Files for metaset, version 1.2.0
Filename, size File type Python version Upload date Hashes
Filename, size metaset-1.2.0-py2.py3-none-any.whl (6.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size metaset-1.2.0.tar.gz (5.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page