Skip to main content

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

Build status Supported Python versions Wheel status License

Quickstart

Install the package from PyPI, using pip:

pip install metaset

Or from GitHub:

git clone git://github.com/lionel-panhaleux/metaset.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. Note it is only available with PostgreSQL≥9.4 and Psycopg2≥2.5.4, as it is stored as a JSONB column. 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.7, Python 2.7, 3.4 (requires jsonfield)

  • Django 1.8, Python 2.7, 3.5 (requires jsonfield)

  • Django 1.9, Python 2.7, 3.5

  • Django 1.10, Python 2.7, 3.5

Note when you use Django>=1.9 you have access to JSON-specific lookups not available when using jsonfield on earlier versions:

>>> MyModel.objects.filter(mset__a__contains=[1, 2])            # doctest: +SKIP
>>> MyModel.objects.filter(mset__a__contained_by=range(10))     # doctest: +SKIP
>>> MyModel.objects.filter(mset__has_key='a')                   # doctest: +SKIP
>>> MyModel.objects.filter(mset__has_keys=('a', 'b'))           # doctest: +SKIP
>>> MyModel.objects.filter(mset__has_any_keys=('a', 'b'))       # doctest: +SKIP

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()}

Download files

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

Source Distribution

metaset-1.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

metaset-1.1.0-py2.py3-none-any.whl (9.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file metaset-1.1.0.tar.gz.

File metadata

  • Download URL: metaset-1.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for metaset-1.1.0.tar.gz
Algorithm Hash digest
SHA256 a1fb92bb046e6e7c1fcd5c618dc077aa7d0eba9fcb318d71599276735709b184
MD5 723744ae8c31f391e9a77cb1243edc96
BLAKE2b-256 345fbcf82dd0d0f5893dab1bb7c63b5000094a1e77f244c82a0e112c55fe1283

See more details on using hashes here.

File details

Details for the file metaset-1.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for metaset-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fb1b9152addfb3ad6e56bd6f4a72befe5a13828f4fd8ee8bb3327d2ab5fe36c9
MD5 310d3f74495a53f1693ef765f0428d98
BLAKE2b-256 38952c65298fb6835d18a2e07aeee78e53384689e2e8816b5d06ad75b9a380d8

See more details on using hashes here.

Release history Release notifications | RSS feed

2.0.0

2 files

1.4.1

2 files

1.4.0

2 files

1.3.0

2 files

1.2.0

2 files

1.1.2

2 files

1.1.1

2 files

This release

1.1.0 This release

2 files

1.0.3

1 file

1.0.2

1 file

1.0.1

2 files

1.0.0

1 file

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