class histogrammar.defs.Factory[source]

Bases: object

Interface for a container factory, always named as imperative verbs, such as “Count” and “Bin”.

Each factory has:

  • a custom __call__ method to create an active container than can aggregate data.
  • a custom ed method to create a fixed container that cannot aggregate data, only merge with the + operator.
  • a uniform fromJsonFragment method that can reconstruct a fixed container from its JSON representation. This is used by the Factory object’s fromJson entry point. (Click on the “t” in a circle in the upper-left to see the Factory object’s documentation, rather than the Factory trait.

In Python, no class distinction is made between active and fixed containers (e.g. “Counting” and “Counted” are both just “Count”). The distinction is maintained at runtime by which methods are available.

Also particular to Python, the Container classes are their own Factories. Thus, Count.ing() makes a Count.

static fromJson(json)

User’s entry point for reconstructing a container from JSON text.

static fromJsonFragment(json, nameFromParent)

Reconstructs a container of known type from JSON. General users should call the Factory object’s fromJson, which uses header data to identify the container type. (This is called by fromJson.)

static register(factory)

Add a new Factory to the registry, introducing a new container type on the fly. General users usually wouldn’t do this, but they could. This method is used internally to define the standard container types.


Explicitly invoke histogrammar.specialized.addImplicitMethods on this object, usually right after construction (in each of the methods that construct: __init__, ed, ing, fromJsonFragment, etc).

Objects used as default parameter arguments are created too early for this to be possible, since they are created before the histogrammar.specialized module can be defined. These objects wouldn’t satisfy any of addImplicitMethod‘s checks anyway.