atom.atom module

class atom.atom.Atom[source]

Bases: atom.catom.CAtom

The base class for defining atom objects.

Atom objects are special Python objects which never allocate an instance dictionary unless one is explicitly requested. The storage for an atom is instead computed from the Member objects declared on the class. Memory is reserved for these members with no over allocation.

This restriction make atom objects a bit less flexible than normal Python objects, but they are between 3x-10x more memory efficient than normal objects depending on the number of attributes.

classmethod members() Mapping[str, atom.catom.Member][source]

Get the members dictionary for the type.


result – The dictionary of members defined on the class. User code should not modify the contents of the dict.

Return type

Mapping[str, Member]

suppress_notifications() Iterator[None][source]

Disable member notifications within in a context.


result – A context manager which disables atom notifications for the duration of the context. When the context exits, the state is restored to its previous value.

Return type


class atom.atom.AtomMeta(name: str, bases: Tuple[type, ...], dct: Dict[str, Any], enable_weakrefs: bool = False, use_annotations: bool = True, type_containers: int = 1)[source]

Bases: type

The metaclass for classes derived from Atom.

This metaclass computes the memory layout of the members in a given class so that the CAtom class can allocate exactly enough space for the object data slots when it instantiates an object.

All classes deriving from Atom will be automatically slotted, which will prevent the creation of an instance dictionary and also the ability of an Atom to be weakly referenceable. If that behavior is required, then a subclasss should declare the appropriate slots.

class atom.atom.ExtendedObserver(funcname: str, attr: str)[source]

Bases: object

A callable object used to implement extended observers.

attr: str

Attribute name on the target object which should be observed.

funcname: str

Name of the function on the owner object which should be used as the observer.

exception atom.atom.MissingMemberWarning[source]

Bases: UserWarning

Signal an expected member is not present.

class atom.atom.ObserveHandler(pairs: List[Tuple[str, Optional[str]]], change_types: atom.catom.ChangeType = ChangeType.ANY)[source]

Bases: object

An object used to temporarily store observe decorator state.

change_types: atom.catom.ChangeType

Types of changes to listen to.

clone() atom.atom.ObserveHandler[source]

Create a clone of the sentinel.

func: Optional[Callable[[Mapping[str, Any]], None]]

Callable to be used as observer callback.

funcname: Optional[str]

Name of the callable. Used by the metaclass.

pairs: List[Tuple[str, Optional[str]]]

List of 2-tuples which stores the pair information for the observers.

atom.atom.add_member(cls: atom.atom.AtomMeta, name: str, member: atom.catom.Member) None[source]

Add or override a member after the class creation.

atom.atom.observe(*names: str, change_types: atom.catom.ChangeType = ChangeType.ANY) atom.atom.ObserveHandler[source]

A decorator which can be used to observe members on a class.

  • *names – The str names of the attributes to observe on the object. These must be of the form ‘foo’ or ‘’.

  • change_types – The flag specifying the type of changes to observe.

class atom.atom.set_default(value: Any)[source]

Bases: object

An object used to set the default value of a base class member.

clone() atom.atom.set_default[source]

Create a clone of the sentinel.

name: Optional[str]

Name of the member for which a new default value should be set. Used by the metaclass.

value: Any

New default value to be set.