janus package
Submodules
janus.base module
- class janus.base.JanusBase(mode, max_history=50000)[source]
Bases:
objectBase class for Janus state tracking, providing history, undo/redo, and persistence.
JanusBase intercepts attribute assignments and container mutations to build a directed acyclic graph (DAG) of state transitions. This enables features like multiverse branching, state restoration, and timeline squashing.
- create_moment_label(label)[source]
Assign a human-readable label to the current state node.
- Return type:
None
- jump_to(label)[source]
Restore the application state to a previously labeled moment.
- Return type:
None
- get_labeled_moments()[source]
Retrieve a list of all labels assigned in the current history.
- Return type:
list[str]
- apply_plugin_op(path, adapter_name, delta, forward)[source]
Called by the engine to apply a plugin operation to a specific object.
- Parameters:
path (
str) – The relative path to the object within this Janus instance.adapter_name (
str) – The name of the adapter to use.delta (
Any) – The delta blob to apply.forward (
bool) – True if applying forward, False for backward (undo).
- Return type:
None
- tag_moment(**kwargs)[source]
Attach arbitrary metadata tags to the current state node.
- Return type:
None
- get_all_tag_keys(label=None)[source]
Get all metadata keys associated with a specific moment.
- Return type:
tuple[str,...]
- get_all_tag_values(label=None)[source]
Get all metadata values associated with a specific moment.
- Return type:
tuple[Any,...]
- get_all_tags(label=None)[source]
Get all metadata key-value pairs associated with a specific moment.
- Return type:
dict[str,Any]
- get_moment_tag(key, label=None)[source]
Retrieve a specific metadata value by key from a moment.
- Return type:
Any
- label_node(label)[source]
Assign a human-readable label to the current state node.
- Return type:
None
- squash(start_label=None, end_label=None)[source]
Collapse state nodes into a single node.
- Return type:
None
- diff(start_label, end_label)[source]
Compare the state between two moments (labels).
- Return type:
dict[str,Any]
- save(path)[source]
Persist the entire multiverse/timeline history to a .jns file.
- Return type:
None
- class janus.base.TimelineBase(max_history=50000)[source]
Bases:
JanusBaseA linear state tracking implementation.
- class janus.base.MultiverseBase(max_history=50000)[source]
Bases:
JanusBaseA multiversal state tracking implementation supporting branching and merging.
- property current_branch: str
The name of the currently active branch.
- create_moment_label(label)[source]
Alias for branch() to stay compatible with brainstorming terminology.
- Return type:
None
- merge(label, strategy='overshadow')[source]
Merge changes from another branch into the current one.
- Return type:
None
- extract_timeline(label=None, filter_attr=None)[source]
Extract history of operations from root to a specific node or label.
- Return type:
list[dict[str,Any]]
janus.containers module
- class janus.containers.TrackedList(items, engine, name, owner=None)[source]
Bases:
list[Any]A list subclass that automatically logs mutations to the Janus engine.
TrackedList intercepts methods like append, extend, insert, pop, clear, and __setitem__ to ensure the Janus engine can track and revert changes to the collection.
- class janus.containers.TrackedDict(items, engine, name, owner=None)[source]
Bases:
dict[Any,Any]A dict subclass that automatically logs mutations to the Janus engine.
TrackedDict intercepts key assignments, deletions, and updates to ensure the Janus engine can track and revert changes to the collection.
- update(other=(), /, **kwargs)[source]
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- Return type:
None
- pop(key, default=None)[source]
If the key is not found, return the default if given; otherwise, raise a KeyError.
- Return type:
Any
- popitem()[source]
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- Return type:
tuple[str,Any]
janus.options module
- class janus.options.PlottingOptions(backend='mermaid', show_labels=True, color_scheme='default', engine_kwargs=<factory>)[source]
Bases:
objectConfiguration for Multiverse visualization.
- backend
The visualization backend to use (“mermaid” or “matplotlib”).
- show_labels
Whether to show human-readable labels on nodes.
- color_scheme
The color palette for the rendered graph.
- engine_kwargs
Additional arguments passed to the underlying engine.
- backend: str = 'mermaid'
- show_labels: bool = True
- color_scheme: str = 'default'
- engine_kwargs: dict[str, Any]
- class janus.options.Options(plotting=<factory>, max_history=50000, default_mode='multiversal')[source]
Bases:
objectGlobal configuration for Janus objects.
- plotting
Options for graph visualization.
- max_history
The maximum number of nodes to keep in the DAG.
- default_mode
The default engine mode (“linear” or “multiversal”).
- plotting: PlottingOptions
- max_history: int = 50000
- default_mode: str = 'multiversal'
janus.persistence module
- janus.persistence.janus_encoder(obj)[source]
Custom encoder for Janus-tracked objects to ensure msgpack compatibility.
- Return type:
Any
- janus.persistence.janus_decoder(obj)[source]
Custom decoder for Janus-tracked objects to re-hydrate during load.
- Return type:
Any
janus.registry module
- class janus.registry.JanusAdapter(*args, **kwargs)[source]
Bases:
ProtocolProtocol for defining custom object tracking logic.
Adapters allow Janus to track third-party objects (like NumPy arrays or Pandas DataFrames) by defining how to calculate deltas and apply them forward or backward in time.
- get_delta(old_state, new_state)[source]
Calculate the difference (delta) between two states of the object.
- Return type:
Any
- apply_backward(target, delta_blob)[source]
Apply a delta in reverse to restore a previous state.
- Return type:
None
- janus.registry.register_adapter(target_class)[source]
Decorator to register a JanusAdapter for a specific class.
- Return type:
Callable[[TypeVar(T, bound=type)],TypeVar(T, bound=type)]
janus.tachyon_rs module
- class janus.tachyon_rs.TachyonEngine(owner, mode, max_nodes=50000)
Bases:
object- create_branch(label)
- current_branch
- current_node
- delete_branch(label)
- extract_timeline(label=None, filter_attr=None)
- find_nodes_by_metadata(key, value)
- get_diff(start_label, end_label)
- get_graph_data()
- get_graph_state()
- get_metadata(key, node_id=None)
- get_metadata_items(node_id=None)
- get_metadata_keys(node_id=None)
- get_metadata_values(node_id=None)
- get_node_id(label)
- label_node(node_label)
- list_branches()
- list_nodes()
- log_dict_clear(path, keys, old_values)
- log_dict_delete(path, key, old_value)
- log_dict_pop(path, key, old_value)
- log_dict_popitem(path, key, old_value)
- log_dict_setdefault(path, key, value)
- log_dict_update(path, keys, old_values, new_values)
- log_list_clear(path, old_values)
- log_list_extend(path, new_values)
- log_list_insert(path, index, value)
- log_list_pop(path, index, popped_value)
- log_list_remove(path, value)
- log_list_replace(path, index, old_val, new_val)
- log_plugin_op(path, adapter_name, delta_blob)
- log_update_attr(name, old_value, new_value)
- merge_branch(source_label, strategy=None)
- move_to(label)
- move_to_creation()
- move_to_node_id(node_id)
- owner
- redo()
- set_graph_state(state)
- set_metadata(key, value)
- squash(start_label, end_label)
- squash_branch(label=None)
- sync_from_root()
- undo()
janus.utils module
- janus.utils.get_engine(obj)[source]
Find the Janus engine by traversing the view/proxy hierarchy.
- Parameters:
obj (
Any) – The tracked object (or a view of one).- Return type:
Any|None- Returns:
The TachyonEngine if found, otherwise None.
- janus.utils.resolve_path(owner, path)[source]
Resolve a nested path like ‘data[0].key’ relative to an owner object.
- Parameters:
owner (
Any) – The object to start resolution from (usually a JanusBase instance).path (
str) – The dot-separated and bracketed path string.
- Return type:
Any- Returns:
The object reached by the path.
janus.viz module
- class janus.viz.VizBackend(*args, **kwargs)[source]
Bases:
ProtocolProtocol for Janus visualization backends.
- class janus.viz.MermaidBackend[source]
Bases:
objectRenders the multiverse DAG as a Mermaid diagram string.
janus.viz_mpl module
- class janus.viz_mpl.MatplotlibBackend[source]
Bases:
objectRenders the multiverse DAG using Matplotlib and NetworkX.
This backend provides a more traditional node-link diagram with customizable colors and layout.
- plot(obj, **kwargs)[source]
Renders the multiverse graph using Matplotlib.
- Parameters:
obj (
JanusBase) – The Multiverse instance to visualize.show – Whether to call plt.show() immediately.
figsize – Tuple of (width, height) for the figure.
node_size – Size of the nodes in the plot.
font_size – Size of the text labels.
title – Custom title for the plot.
- Return type:
Any- Returns:
A Matplotlib Figure object.