Skip to content

Recorder

dandy.recorder.recorder.Recorder

Bases: Singleton

recordings = dict() class-attribute instance-attribute

renderers = {'html': HtmlRecordingRenderer, 'json': JsonRecordingRenderer, 'markdown': MarkdownRecordingRenderer} class-attribute instance-attribute

add_event classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def add_event(cls, event: Event):
    for recording in cls.recordings.values():
        if recording.is_running:
            recording.event_store.add_event(event)

check_recording_is_valid classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def check_recording_is_valid(cls, recording_name: str = RECORDING_DEFAULT_NAME):
    if recording_name not in cls.recordings:
        choices_message = ''

        if len(cls.recordings.keys()) == 0:
            choices_message = f' Choices are {list(cls.recordings.keys())}'

        raise RecorderCriticalException(f'Recording "{recording_name}" does not exist. {choices_message}')

delete_all_recordings classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def delete_all_recordings(cls):
    cls.recordings.clear()

delete_recording classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def delete_recording(cls, recording_name: str = RECORDING_DEFAULT_NAME):
    cls.check_recording_is_valid(recording_name)
    del cls.recordings[recording_name]

get_recording classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def get_recording(cls, recording_name: str = RECORDING_DEFAULT_NAME) -> Recording:
    cls.check_recording_is_valid(recording_name)
    return cls.recordings[recording_name]

is_recording classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def is_recording(cls):
    return any([recording.is_running for recording in cls.recordings.values()])

start_recording classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def start_recording(cls, recording_name: str = RECORDING_DEFAULT_NAME):
    cls.recordings[recording_name] = Recording(name=recording_name)
    cls.recordings[recording_name].start()

stop_recording classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def stop_recording(cls, recording_name: str = RECORDING_DEFAULT_NAME):
    cls.check_recording_is_valid(recording_name)
    cls.recordings[recording_name].stop()

stop_all_recording classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def stop_all_recording(cls):
    for recording in cls.recordings.values():
        recording.stop()

to_html_file classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def to_html_file(
        cls,
        recording_name: str = RECORDING_DEFAULT_NAME,
        path: Path | str = DEFAULT_RECORDER_OUTPUT_PATH
):
    cls._to_file(
        recording_name,
        'html',
        path
    )

to_html_str classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def to_html_str(
        cls,
        recording_name: str = RECORDING_DEFAULT_NAME,
) -> str:
    return cls._to_str(
        recording_name,
        'html',
    )

to_json_file classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def to_json_file(
        cls,
        recording_name: str = RECORDING_DEFAULT_NAME,
        path: Path | str = DEFAULT_RECORDER_OUTPUT_PATH
):
    cls._to_file(
        recording_name,
        'json',
        path
    )

to_json_str classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def to_json_str(
        cls,
        recording_name: str = RECORDING_DEFAULT_NAME,
) -> str:
    return cls._to_str(
        recording_name,
        'json',
    )

to_markdown_file classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def to_markdown_file(
        cls,
        recording_name: str = RECORDING_DEFAULT_NAME,
        path: Path | str = DEFAULT_RECORDER_OUTPUT_PATH
):
    cls._to_file(
        recording_name,
        'markdown',
        path
    )

to_markdown_str classmethod

Source code in dandy/recorder/recorder.py
@classmethod
def to_markdown_str(
        cls,
        recording_name: str = RECORDING_DEFAULT_NAME,
) -> str:
    return cls._to_str(
        recording_name,
        'markdown',
    )

dandy.recorder.recording.Recording

Bases: BaseModel

name instance-attribute

is_running = False class-attribute instance-attribute

start_datetime = Field(default_factory=datetime.now) class-attribute instance-attribute

stop_datetime = Field(default_factory=datetime.now) class-attribute instance-attribute

token_usage = 0 class-attribute instance-attribute

run_time_seconds = 0.0 class-attribute instance-attribute

event_count = 0 class-attribute instance-attribute

event_store = Field(default_factory=EventStore) class-attribute instance-attribute

clear

Source code in dandy/recorder/recording.py
def clear(self):
    self.start_datetime = datetime.now()
    self.stop_datetime = datetime.now()

start

Source code in dandy/recorder/recording.py
def start(self):
    self.start_datetime = datetime.now()
    self.is_running = True

stop

Source code in dandy/recorder/recording.py
def stop(self):
    self.stop_datetime = datetime.now()
    self.run_time_seconds = self.event_store.events_total_run_time
    self.token_usage = self.event_store.events_total_token_usage
    self.event_count = self.event_store.event_count
    self.is_running = False

dandy.recorder.events

EventType

Bases: str, Enum

RUN = 'run' class-attribute instance-attribute

RETRY = 'retry' class-attribute instance-attribute

REQUEST = 'request' class-attribute instance-attribute

RESPONSE = 'response' class-attribute instance-attribute

RESULT = 'result' class-attribute instance-attribute

SUCCESS = 'success' class-attribute instance-attribute

WARNING = 'warning' class-attribute instance-attribute

FAILURE = 'failure' class-attribute instance-attribute

OTHER = 'other' class-attribute instance-attribute

EventAttribute

Bases: BaseModel

key instance-attribute

value instance-attribute

is_dropdown = False class-attribute instance-attribute

is_card = False class-attribute instance-attribute

is_base64_image = False class-attribute instance-attribute

Event

Bases: BaseModel

id instance-attribute

object_name instance-attribute

callable_name instance-attribute

type instance-attribute

attributes = Field(default_factory=list) class-attribute instance-attribute

start_time = Field(default_factory=perf_counter) class-attribute instance-attribute

token_usage = 0 class-attribute instance-attribute

run_time_seconds = 0.0 class-attribute instance-attribute

calculate_run_time

Source code in dandy/recorder/events.py
def calculate_run_time(self, pre_event: Self):
    self.run_time_seconds = self.start_time - pre_event.start_time

add_attribute

Source code in dandy/recorder/events.py
def add_attribute(self, event_attribute: EventAttribute) -> Self:
    self.attributes.append(event_attribute)

    return self

EventStore

Bases: BaseModel

events = Field(default_factory=list) class-attribute instance-attribute

event_count property

events_total_run_time property

events_total_token_usage property

add_event

Source code in dandy/recorder/events.py
def add_event(self, event: Event) -> Event:
    self.events.append(event)
    self._calculate_event_run_times()

    return event