Skip to main content

Python wrapper designed to facilitate interaction with the Lenz report API.

Project description

LenzPy

LenzPy is a Python wrapper designed to facilitate interaction with the Lenz report API. Lenz is a dead-simple platform for collecting, analyzing, and visualizing data from your software.

Usage

Before using LenzPy, ensure that you have an API key from Lenz. You can provide the API key directly in function calls or store it as an environment variable named LENZ_API_KEY.

export LENZ_API_KEY=abcdef0123

The @instrument Decorator

The @instrument decorator is a powerful feature of LenzPy that enables you to seamlessly integrate reporting into your functions. It automates the process of submitting reports to Lenz while allowing you to customize the reporting behavior.

A powerful use-case is to decorate the handler function for your web API, to collect data about requests & responses.

from LenzPy import instrument 

@instrument(report_name="example_fnc", flatten_args=True, flatten_res=True, mock=False)
def example_fnc(input, other_inputs, default_none=None, **kwargs):
    # Your function logic here. Example:
    status_codes = {
        200: "OK",
        201: "Created",
        204: "No Content",
        400: "Bad Request",
        401: "Unauthorized",
        403: "Forbidden",
        404: "Not Found",
        500: "Internal Server Error"
    }
    
    code = random.choice(list(status_codes.keys()))
    message = status_codes[code]
    
    return code, message
report_name (str): The name of the report or event.
api_key (str, optional): The API key for authentication. If not provided, it's fetched from the environment variable.
flatten_args (bool, optional): Whether to flatten function arguments before reporting.
included_args (list or None, optional): List of keys to be included in the reported arguments. If not provided, no filtering is performed.
flatten_res (bool, optional): Whether to flatten the return value before reporting.
included_res (list or None, optional): List of keys to be included in the reported return value. If not provided, no filtering is performed.
mock (bool, optional): Whether to print the prepared report without actually submitting it.

Reporting Directly

If you prefer more control, you can submit reports directly using the submit_report function.

from LenzPy import submit_report

# ...
data = {"userId": 17, "latency": 5, "domain": "foo.bar", "path": "/register"}
submit_report(event_name="user_register", body=data)
event_name (str): The name of the event or report.
body (dict): The body of the report containing relevant data.
api_key (str, optional): The API key for authentication. If not provided, it's fetched from the environment variable.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

LenzPy-0.1.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

LenzPy-0.1.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file LenzPy-0.1.1.tar.gz.

File metadata

  • Download URL: LenzPy-0.1.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for LenzPy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b69c0e4372e782c5e3a45cdeaa6d9816876bc04b353b3810e182dee95588aa16
MD5 2e85525a9f0d9bd855679c8625a6686d
BLAKE2b-256 aa366bdf6734f9c7abc33a79384c9c454a6f059898331551b8ce6eee7075cefd

See more details on using hashes here.

File details

Details for the file LenzPy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: LenzPy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for LenzPy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eed774b9469abb322ae10ed3fe631564b0e58334fffbe6c4c0de03b44678aabf
MD5 2a07c899a6b6f3dc74ee978dc9756d3a
BLAKE2b-256 d27435040dae720ec8a48a3610c6777d621f871016dc56de24a0f4d1c8742de4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page