taggedict package

Technical documentation.

Module contents

Tags-aware dictionary.

Dictionary that uses frozenset of tags as actual key and allows indexing by subset or individual tag. All standard dict operations inherited from dict, but indexing by slice allows some set operations and returns an iterator.

class taggedict.Tagged(*args, **kwargs)

Bases: dict

Initialize tagged dictionary.

Any sequence can be provided as key — it will be converted to frozenset

__delitem__(idx)

Delete object(s) or tag(s).

Parameters:

idx – Dictionary key or slice

  • Raw indexing: convert idx to frozenset and delete an object;

    • if key is not iterable, act like standard dict.

  • del Tagged[tag:] — delete tag from all objects tagged by tag

  • del Tagged[:tags] — delete tags from all objects tagged by all tags

  • del Tagged[::tags] — delete tags from objects tagged by any tag from tags

  • del Tagged[tag:...] — delete objects tagged by tag

  • del Tagged[...:tags] — delete objects tagged by all tags

  • del Tagged[...::tags] — delete objects tagged by any tag from tags

  • del Tagged[:...:tags] — same

__dict__ = mappingproxy({'__module__': 'taggedict', '__doc__': '\n    Initialize tagged dictionary.\n\n    Any sequence can be provided as key it will be converted to frozenset\n    ', '__init__': <function Tagged.__init__>, '__getitem__': <function Tagged.__getitem__>, '_moditem': <function Tagged._moditem>, '__delitem__': <function Tagged.__delitem__>, '__setitem__': <function Tagged.__setitem__>, '__dict__': <attribute '__dict__' of 'Tagged' objects>, '__weakref__': <attribute '__weakref__' of 'Tagged' objects>, '__annotations__': {}})
__getitem__(idx)

Get an object or sequence of objects.

Parameters:

idx – Dictionary key or slice

  • Raw indexing: convert idx to frozenset and get an object;

    • if key is not iterable, act like standard dict.

  • Tagged[tag:] — return iterable over items (pairs) tagged by single tag

  • Tagged[:tags] — return iterable over items (pairs) tagged by all tags

  • Tagged[::tags] — return iterable over items (pairs) tagged by any tag from tags

__init__(*args, **kwargs)

Initialize tagged dictionary.

__module__ = 'taggedict'
__setitem__(idx, value)

Update/set an object or object tag(s).

Parameters:
  • idx – Dictionary key or slice

  • value – Dictionary value or additional tags

  • Raw indexing: convert idx to frozenset if iterable, then act like standard dict.

  • Tagged[tag:] = newtags — add (append tags from) newtags to the objects tagged by tag.

  • Tagged[:tags] = newtags — append newtags to the objects tagged by all tags.

  • Tagged[::tags] = newtags — append newtags to the objects tagged by any tag from tags.

If newtags is not iterable, treat it as a single tag sequence.

__weakref__

list of weak references to the object (if defined)

taggedict.iterable(obj)

Check if object is iterable.

Taken from documentation: https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable

Parameters:

obj – Object to check

Returns:

Iterator over object, False if object is not iterable