Base

Base class

class edsl.base.Base[source]

Bases: RepresentationMixin, PersistenceMixin, DiffMethodsMixin, HashingMixin, ABC

Base class for all classes in the EDSL package.

This abstract base class combines several mixins to provide a rich set of functionality to all EDSL objects. It defines the core interface that all EDSL objects must implement, including serialization, deserialization, and code generation.

All EDSL classes should inherit from this class to ensure consistent behavior and capabilities across the framework.

abstract code()[source]

Generate Python code that recreates this object.

This method must be implemented by all subclasses to provide a way to generate executable Python code that can recreate the object.

Returns:

str: Python code that, when executed, creates an equivalent object

abstract example()[source]

Create an example instance of this class.

This method should be implemented by all subclasses to provide a convenient way to create example objects for testing and demonstration.

Returns:

An instance of the class with sample data

abstract from_dict()[source]

Create an instance from a dictionary.

This class method must be implemented by all subclasses to provide a standard way to deserialize objects from dictionaries.

Returns:

An instance of the class populated with data from the dictionary

get_description() str[source]

Get the description of this object.

get_uuid() str[source]

Get the UUID of this object from the Expected Parrot cloud service based on its hash.

This method calculates the hash of the object and queries the cloud service to find if there’s an uploaded version with the same content. If found, it returns the UUID of that object.

Returns:

str: The UUID of the object in the cloud service if found

Raises:
CoopServerResponseError: If the object is not found or there’s an error

communicating with the server

inspect()[source]

Create an interactive inspector widget for this object.

This method uses the InspectorWidget registry system to find the appropriate inspector widget class for this object’s type and returns an instance of it.

Returns:

InspectorWidget subclass instance: Interactive widget for inspecting this object

Raises:

KeyError: If no inspector widget is registered for this object’s class ImportError: If the widgets module cannot be imported

json()[source]

Get a formatted JSON representation of this object.

Returns:

DisplayJSON: A displayable JSON representation

keys()[source]

Get the key names in the object’s dictionary representation.

This method returns all the keys in the serialized form of the object, excluding metadata keys like version information.

Returns:

list: A list of key names

show_methods(show_docstrings=True)[source]

Display all public methods available on this object.

This utility method helps explore the capabilities of an object by listing all its public methods and optionally their documentation.

Args:
show_docstrings: If True, print method names with docstrings;

if False, return the list of method names

Returns:
None or list: If show_docstrings is True, prints methods and returns None.

If show_docstrings is False, returns a list of method names.

store(d: dict, key_name: str | None = None)[source]

Store this object in a dictionary with an optional key.

Args:

d: The dictionary in which to store the object key_name: Optional key to use (defaults to the length of the dictionary)

Returns:

None

abstract to_dict()[source]

Serialize this object to a dictionary.

This method must be implemented by all subclasses to provide a standard way to serialize objects to dictionaries. The dictionary should contain all the data needed to reconstruct the object.

Returns:

dict: A dictionary representation of the object

to_json()[source]

Serialize this object to a JSON string.

Returns:

str: A JSON string representation of the object

values()[source]

Get the values in the object’s dictionary representation.

Returns:

set: A set containing all the values in the object

yaml()[source]

Get a formatted YAML representation of this object.

Returns:

DisplayYAML: A displayable YAML representation