Pymetrix: The Open Source Plug and Play Python Analytics Library

Pymetrix Developer Docs

Posted by Anuran on Saturday, November 20, 2021

TOC

Codacy Code Grade Github Stars GitHub Forks GitHub Repo Size Lines of Code

Pymetrix-Python

What is Pymetrix?

Pymetrix is a plug-and-play analytics library written in Python.

Usage

Pymetrix is really easy to integrate with your projects. Here’s an example:

Let’s say you want to monitor a method foo() defined as:

1
2
3
4
from random import randint

def foo():
    print(f"Hello world {randint(0,1000000)}!")

After adding the required lines, the code will look something like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from random import randint
from metrics.metrics import Metrics

metricman = Metrics(__file__)
foo_obj = None

def foo():
    print(f"Hello world {randint(0,1000000)}!")
    if foo_obj is None:
        ep1 = endpoints.Endpoint(endpoint="/", id=foo)
        foo_obj = flow.FlowNode(ep1, name="Object1")

    metricman.add_to_analytics(foo_obj, layerName="foo")

You can access the metrics of foo() from the metricman object with:

1
metricman.display(id='foo')

To get all the metrics of all the methods at once:

1
metricman.display()

For looking into what more Pymetrix can do, head to tests/flow_test.py.


comments powered by Disqus