• Beta
Python UX
  • 09 Jul 2020
  • 1 Minute To Read
  • Share
  • Dark
    Light

Python UX

  • Share
  • Dark
    Light

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.bold

ux.bold(text: str) -> str

Formats text as boldface for printing with ux.print or as a message in any of the other ux or prompt functions.

Formats correctly in the terminal and in Slack.

Example:

from cto_ai import ux, prompt

permission = prompt.input(
    name="permission",
    message=f"If you are certain you want to {ux.bold("permanently delete")} this repository, enter its name"
)

ux.italic

ux.italic(text: str) -> str

Formats text as italic for printing with ux.print or as a message in any of the other ux or prompt functions.

Formats correctly in the terminal and in Slack, but terminal support for italic text is limited.

Example:

from cto_ai import ux

ux.print(f"We hope you have a {ux.italic("very")} good experience with CTO.ai")

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.
Was This Article Helpful?