Making finance beautiful

Finance does not have to be boring. Here's how edgartools uses the rich library for beautiful output in the terminal

Making finance beautiful

One of the best libraries in Python is Rich and I have been a Rich user since the beginning of EdgarTools. It's one of the best things about the library - being able to see financial data output beautifully in the terminal.

Rich is used mainly for one pattern throughout the library: displaying an object to the terminal. For example, here is the Filings object.

And here is a Filing

This works by giving each object a__rich__() function and calling this inside __repr__()

    def __rich__(self):
        """
        Produce a table version of this filing e.g.

        :return: a rich table version of this filing
        """
        ticker = find_ticker_safe(self.cik)
        ticker = f"{ticker}" if ticker else ""

        ...

    def __repr__(self):
        return repr_rich(self.__rich__())

This works so well that it is used all over the library. This meant that there was a lack of consistency in how the objects looked since they were developed at different times. Recently I implemented a design guide for Rich within the library and I'm slowly migrating objects to that design guide. This helps with one goal of making the objects look better and, thereby, improve the user experience with a library, but also give visual cues to the data, and so make working with edgartools more productive.

The Style Guide

The library now has a style guide that we will work towards over the next several weeks to months. You can preview what the styles would look like by running the demo.

python -m edgar.display.demo

The first part of the design looks at using cards to display some of the core objects such as Filing and Filings. This uses a simple, crisp design with few colors to add visual distinction to key elements.

Financial statements also follow this minimalistic design with a few colors in key places.

The typography use for statements is shown below. Note that the base colors are greyish with colors for highlights.

This is actually based on an overall color palette for the library.

One of the things I want to try in the library is the use of status messages, style the color similar to what you see on the web.

Conclusion

This is partially a fun diversion to keep things interesting, but also to make the library look good and functionally more useful. Rich has definitely been one of the things that has kept me interested in working on EdgarTools. It is an an excellent library, and I recommend you give it a try.

If you want to see good examples of design in a functional library, then try out edgartools. It is the easiest way to get started with SEC financial data.

Subscribe to EdgarTools

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe