Skip to content
/ sparcli Public

Display dynamic metrics as text (sparklines)

License

Notifications You must be signed in to change notification settings

z0u/sparcli

Repository files navigation

Sparcli

Sparcli is a library for visualising metrics on the command line.

Use this library to see the shape of data during execution of data pipelines, simulators and other long-running programs. Each metric is displayed as a sparkline that updates as the data changes. Sparcli is thread-safe and non-blocking.

Build Publish Canary build

Usage

Sparcli is available on PyPI:

pip install sparcli

You can wrap an iterable that produces scalars:

import sparcli

for y in sparcli.gen(ys, name="y"):
    do_something(y)

You can publish metrics using a context manager:

with sparcli.ctx() as ctx:
    for a, b in do_something_else():
        ctx.record(a=a, b=b)

You can also manage the context manually. Just don't forget to close it:

class MyMetricsPlugin:
    def start(self):
        self.ctx = sparcli.context()

    def step(self, metrics: Dict[str, Real]):
        self.ctx.record(**metrics)

    def stop(self):
        self.ctx.close()

some_library.register_plugin(MyMetricsPlugin())

Development

First install Python 3.6+, Poetry and Make. Optionally, use py-make if you don't have GNU Make. If you have Python and pipx installed, you can get started by running:

pipx install poetry
pipx install py-make
alias make='pymake'
make init

Then run the tests and demo:

make
poetry run python demo.py

About

Display dynamic metrics as text (sparklines)

Resources

License

Stars

Watchers

Forks

Packages

No packages published