edgegraph.structure.base.BaseObject#

class edgegraph.structure.base.BaseObject(*, uid=None, attributes=None, universes=None)#

Bases: object

Top of the object inheritance tree for everything.

That’s not quite a joke – this class is the top of the tree when it comes to object types. All other objects in edgegraph inherit from this one.

It provides a few standardized attributes and access methods:

  • Universal unique identifier

  • Dynamic attributes storage

  • Universe association

Through the “dynamic attributes storage”, this object works as a namespace – it is intended for adding attributes after initialization / instantiation. For example:

>>> b = BaseObject()
>>> dir(b)
[]
>>> b.x = 17
>>> b.x
17
>>> dir(b)
['x']

The attributes provided to the __init__ method also become a part of this operation:

>>> b = BaseObject(attributes={"fifteen": 15})
>>> dir(b)
['fifteen']
>>> b.fifteen
15
__init__(*, uid=None, attributes=None, universes=None)#

Instantiate a BaseObject.

Parameters:
  • uid (int | None) – universally unique identifier of this object, or None. If None, one will automatically be generated.

  • attributes (dict | None) – dictionary of attributes to apply to this object.

  • universes (Iterator[Universe] | None) – a set of universes that this object belongs to.

Raises:

TypeError – if attributes argument is of invalid type

Methods

__init__(*[, uid, attributes, universes])

Instantiate a BaseObject.

add_to_universe(universe)

Add this object to a new universe.

remove_from_universe(universe)

Remove this object from the specified universe.

Attributes

uid

Get the UID of this object.

universes

Get the universes this object belongs to.

add_to_universe(universe)#

Add this object to a new universe.

If it is already there, no action is taken.

Parameters:

universe (Universe) – the new universe to add this object to

remove_from_universe(universe)#

Remove this object from the specified universe.

Parameters:

universe (Universe) – the universe that this object will be removed from

Raises:

ValueError – if this object is not present in the given universe

property uid: int#

Get the UID of this object.

property universes: list[Universe]#

Get the universes this object belongs to.

Note that the copy returned is just that, a copy. Modifications to this list that you may make will have no effect on the object.

See also

add_to_universe(), remove_from_universe() to add or remove this object from a given universe