Python UX

The following UX elements are supported by the Python SDK:

  • Print
  • Progress Bars
  • Spinners

The spinner and progress bar APIs in ux are top-level functions: progress_bar_start, progress_bar_advance, progress_bar_stop, spinner_start, and spinner_stop.

ux.print

ux.print(text: str):

Displays text to the user. Locally, prints to the command-line.

Example:

from cto_ai import ux, prompt

def main():
	ux.print('Hello, welcome to the example command')

Output:

Hello, welcome to the example command

ux.spinner_start

ux.start(text: str):

Starts a spinner accompanied with the given message.

ux.spinner_stop

ux.stop(text: Optional[str] = None):

Stops the currently running spinner, replacing the message with the given text.

Example:

from cto_ai import ux

def main():

    ux.spinner_start('Processing...')
		# Do your processing here
    ux.spinner_stop('Processing complete!')

ux.progress_bar_start

progress_bar_start(length: int, initial: int = 0, message: Optional[str] = None):

Creates and displays a progress bar, with length increments of which initial are already ready, and with an accompanying optional message.

ux.progress_bar_advance

progress_bar_advance(increment: int = 1):

Increments the value of a progress bar by increment, or by 1 increment if no argument is provided.

ux.progress_bar_stop

progress_bar_stop(message: Optional[str] = None):

Completes the progress bar, incrementing it to 100% and optionally replacing the message with the given one.

Example:

from cto_ai import ux

def main():

    ux.progress_bar_start(5, 0, 'Do my complicated thing')
		# Do something
    ux.progress_bar_advance()
		# Do something bigger
    ux.progress_bar_advance(2)
		# Finish up
    ux.progress_bar_stop('Complicated thing done')

🚀 What's next?

  • If you want to explore the options offered by our SDKs, go to the Python SDK page
  • To see which prompts we offer for this SDK, you can go to Python Prompts page.