-
-
Notifications
You must be signed in to change notification settings - Fork 684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Add utilities for printing complex JSON objects #1099
base: master
Are you sure you want to change the base?
Conversation
…trailing whitespace
@tiangolo / @svlandeg / @patrick91 - can one of you add the There are a couple little things in this PR which are not strictly necessary (e.g. adding Happy for any feedback. Trying to make API development easier, so folks can just "dump" the JSON responses with some consistent formatting. |
Rationale
Add utilities to make printing complex objects easier. It is common to use
typer
to receive JSON data from servers, and this makes it easier for users to print these JSON objects in a few common formats.Changes
Added a
rich_table.py
:RichTable
class is a thin wrapper derived fromrich.Table
. It contains some default formatting for the tables, since it becomes confusing when tables are nested.rich_table_factory()
to create aRichTable
with appropriate nesting based on the data returned by the data in the object.Added
OutputFormat
andprint_rich_object()
torich_utils.py
:OutputFormat
is an enum suitable to use intyper.Option
with the supported output formatsprint_rich_object()
takes care of formatting the provided object in the specified format, and and prints using the default console.Example
Here's a simple Python example to leverage the new code:
Here's some sample output: