semvec/pypi-packages huggingface dataset:
notcologger 0.2.1
Not CO Logger, a cloud logging library.
License: MIT
Requires Python: >=3.9,<4.0

# Not-co-logger

Not-co-logger is a simple Python library to help log things to stdout in a 
specific JSON format. It is inspired by the checkout-logger TypeScript 
library (https://github.com/CheckoutFinland/checkout-logger).

## How to use

This guide is short and in need of much verbosity.

The idea behind this library is that typically in a complex cloud environment it makes ones life much easier if apps log to stdout in a consistent JSON format. This library implements in a pretty simple form some practices that have been found useful.

LogSpan(requestId) creates a logspan object, which has error, warn, info and debug methods to log varying levels of messages. All messages have a type (for example "lambda.handler.start"), message, log group (for example technical or session), and optionally user (could be IP or user id) and meta (free form object).

A good logtype is unique or at least easily greppable. We suggest naming them hierarchically, for example 'component.module.subtask' or something like that. A logtype should be informative but not overly rigid or verbose. Message is the typical human readable part of an event. Meta should be understood as a grab bag object for any additional fields that would be considered useful for the particular log event. For example a HTTP request log event could have the requested path included in the meta object.

All log rows are bound together by the requestId when logging them. Timestamps are automatically added.

## Levels

These are suggested guidelines for log levels:

* Error: The system has run into a fatal exception that requires attention from admins.
* Warning: Something went wrong, but admins do not need to be urgently alerted.
* Info: Normal logging.
* Debug: General developer friendly spam that is wanted in the logs for common "what the hell just happened" type of solving.

## Suggested group

Here are some groups that have been found to be useful:

* request: Incoming requests
* response: Outgoing responses
* session: Events related to an active session
* technical: Events related to some technical state or issues

## ExceptionSpan

When you need to log an error but only when an exception is raised, you can use ExceptionSpan context manager:

```
    with ExceptionSpan('mylog.problem', 'Doing something fails') as log:
        do_something_that_fails()
        log.info('mylog.success', 'It worked!', 'technical')
```

If `do_something_that_fails()` fails and raises an exception, the ExceptionSpan logs an error. If the call succeeds, the optional log.info() is called. Note that ExceptionSpan does not catch the exception.
telepy-notify 0.2.1
Send telegram notifications
License: MIT
Requires Python: >=3.6

# What is this?

Super fast (<5min setup) telegram notifications for task-completion, task progress, errors and more. This is a minimal module (one file, no pip dependencies).

# How do I use this?

1. `pip install telepy_notify`

2. Take 30sec to get a token:
  - open up a chat with https://t.me/botfather
  - send `/newbot` to ^
  - copy the token out of the response message

3. DM your bot to initialize it (important!)

4. Use it

```python
from telepy_notify import Notifier

# 
# setup
# 
notify = Notifier(
    # read from file
    token_path="some/file/thats/git/ignored/telegram.token",
    # # OR read from ENV var, ex:
    # token_env_var="TELEGRAM_TOKEN",
    # # OR give the token directly, ex:
    # token="alkdsfjakjfoirj029294ijfoi24j4-2",
    
    # optional: a prefix for all messages (good if multiple machines)
    message_prefix="Lambda Machine: Experiment 19:",
    # optional: set to true when debugging to avoid a million notifications
    disable=False,
)
# NOTE:
#    other people can run your code without setting up a bot
#    because telepy will NEVER throw errors 
#    if a notification fails, or if a token is bad
#    it will intentionally only print warnings instead of
#    crashing whatever long-running process you have

# 
# Basic notification
# 
notify.send("Howdy!")
notify.send("Howdy! <b>I'm bold</b>")
notify.send("Howdy! <b>I'm bold</b>\n<code>thing = [1,3,4]</code>")

# 
# get duration and/or error information
# 
with notify.when_done:
    blah_blah_blah = 10
    for blah in range(blah_blah_blah):
        from time import sleep
        sleep(0.1)
    raise Exception(f'''Hello Telegram :)''')
# """
# process took: 1sec, ended at: Sun Aug 20 11:23:38 2023 however it ended with an error: Exception('Hello Telegram :)')
# """

# 
# Progress notifications
# 
#    - gives ETA and other time-info
#    - can limit notify-rate (by time passed or percent-progress)
#        e.g. percent_per_notify=50 => message me after 50% progress
#        e.g. minutes_per_notify=30 => message once every 30min
#    - notify_iter_delay is used to wait a few iterations before sending an ETA
#      (makes the ETA of the first notification more accurate)
for progress, epoch in notify.progress(range(100), percent_per_notify=50, minutes_per_notify=30, notify_iter_delay=1):
    index = progress.index
    
    # do stuff
    import random
    accuracy = random.random()
    if accuracy > 0.99:
        notify.send("Gottem 🎉🎉🎉")
    # end do stuff
    
    progress.message = f"recent accuracy: <code>{accuracy}</code>"

# that^ outputs:
# message1:
#     [=================>.................] 50.00% 
#     |  50/100 
#     | remaining: 0sec 
#     | eta: 11:52:48 
#     | elapsed: 0sec 
#     | recent accuracy: 0.5086382690344122
# message2:
#     Done in 1sec at 11:52:49


```