semvec/pypi-packages huggingface dataset:
dynamic-logger 1.0.2
Dynamic Logger Class for logging
License: MIT
Requires Python: >=3.10,<4.0
Keywords: logging,extra_logging,dynamic_logging

# DynamicLogger

DynamicLogger is an extension of logging.Logger to provide additional functionality to log "extra" values quickly and dynamically. </br>

# Installation

## One Liner
```bash
python -m pip install dynamic_logger
```

## Or if you prefer Manual Installation
``` bash
git clone https://github.com/ajatkj/dynamic_logger.git
cd dynamic_logger
pip install .
```

# Usage
```python
import dynamic_logger
import logging
logging.setLoggerClass(dynamic_logger.Logger)

# Set-up log formatter with user-definied attributes
fmt = '[%(asctime)s] <%(app)s> [%(levelname)s] <%(id)s> <%(customer_id)s> --- %(message)s' # Note: format attributes in <> are user-definited

# Load config
logging.basicConfig(format=fmt, datefmt='%d-%b-%y %H:%M:%S', level='INFO')

applogger = logging.getLogger(__name__)

@applogger.log_extras('id',int=0,customer_id='obj.customer_id') # Log value of 'id' and 'obj.customer_id'
def example_1(id=0,id2=0,obj=None):
    applogger.info('This example shows how to log values from function arguments')

if __name__ = "__main__":
    example_1(id=123456,obj={"customer_id":777})
```

Above will produce log output as below for all logging calls from the function:

```
[2022-04-19 12:53:51,658] [INFO] <123456> <customer_id:777> --- This example shows how to log values from function arguments
```

`dynamic_logger` exposes 2 main API's

1. log_extras decorator  
   `log_extras()` will log values dynamically from the decorated function
2. set_extras function  
    `set_extras()` will log static values for all subsequent `logger` calls till you call the `clear()` function.

See more examples in `example.py`

## Some Notes
1. To use with FastAPI, make sure `log_extras()` decorator is added after the path decorator of FastAPI.

# Contribution
Always open to PRs :)

<p align="center"><a href="https://github.com/ajatkj/dynamic_logger/blob/main/LICENSE"><img src="https://img.shields.io/static/v1.svg?style=flat-square&label=License&message=MIT&logoColor=eceff4&logo=github&colorA=4c566a&colorB=88c0d0"/></a></p>
simpleparser 0.1.3
Simple library with simple parser which parses simple expressions.
License: MIT
Requires Python: >=3.7

# SimpleParser
Simple expressions parser.

# Installing
Installing via pip:
```bash
$ pip install simpleparser
```

# Usage
## Parser
To simply parse something, use `Parser.parse` method. With `Parser` you can describe different parsers.
There is ready-made `Defaults.parser`. 
```python
from simpleparser import Defaults
expr = "a + b / 2"
parsed = Defaults.parser.parse(expr)
parsed(a=2, b=4) # returns 4.0
```
`Parser.parse` returns callable `ParsedExpression` object.
### Custom parsers
`Parser` can be easily configured. It is described by a set of operators and constants types (such as numbers or booleans).
See the `Operator` and `ConstantType` documentation below.
```python
from simpleparser import Parser, Defaults
my_parser = Parser(
    operators=[Defaults.plus, Defaults.minus, Defaults.mul, Defaults.div], # using some operators from `Defaults` here
    constants=[Defaults.integers_decimal, Defaults.float_point]
)
```
Here `my_parser` parses simple math expressions with 4 basic operators and decimal numbers, for example `1 + 2.0 * a`.
## Operator
Creating a custom operator:
```python
from simpleparser import Operator, Parser
in_op = Operator(
    name="in",
    operator_type=2,
    func=lambda el, container: el in container,
    signs=("\u2208",),
    priority=3,
)
# creating new parser which uses this operator
new_parser = Parser([in_op], [])
el_in_set_checker = new_parser.parse("a in A")
el_in_set_checker(a=1, A={1, 2, 3}) # True
el_in_set_checker(a=0, A={1, 2, 3}) # False
```
## ConstantType
Describes a type of constants which can be used in expression. Here is the definition of `Defaults.boolean`:
```python
from simpleparser import ConstantType
boolean = ConstantType(r"(True|False|true|false)$", lambda s: True if s in {"True", "true"} else False)
```
Parser with this constant type replaces words which are matched by the `boolean`'s regular expression to `True` or `False`.
```python
parser = Parser([],[boolean])
parser.parse("True")() # True
parser.parse("false")() # False
```