semvec/pypi-packages huggingface dataset:
JSONPath-Lite 0.0.4
A light weight json path utility for Python
Requires Python: >=3.0

# jsonpath-lite
A very light weight utility which parses and uses JSONPath expressions for simple interactions with the Python data structures representing a JSON document.

## Usage
Say you have this JSON:
```
{
    "Things": [
        {
            "Name": "Thing1",
            "Value": "Dog"
        }
    ]
}
```
If you want to get the value of a Thing Named Thing1:  
`get_json_item(JSON Document, '$.Things[?Name="Thing1"].Value')`

If you want to update the value of the Thing Named Thing1 to Cat:  
`update_json_element(JSON Document, '$.Things[?Name="Thing1"].Value', 'Cat')`

If you want to add a new Thing:  
`write_new_json_element(JSON Document, '$.Things', {"Name": "Thing2", "Value": "Manbearpig"})`  
The arguments are: the JSON like object, path to the location of the new item, value of the new item, name of the new item.  
Note that a value is not supplied for newElementName since we are adding a new item to a list (array).

If you want to add a new field to one of the Things:  
`write_new_json_element(JSON Document, $.Things[?Name="Thing1"], True, "IsAGoodBoy")`

## Installation
With pip:
`pip install JSONPath-Lite`  
Otherwise you can just grab the JSONPathLite package from this repo and import it in your project. 

## Notes
This project came to be out of a need to find and manipulate specific pieces of data within a large highly nested JSON structure. As such, it is designed to stop searching and return the first match for a given path. The functionality of returning all matches for a given path will be added at some point in the future.
pysdtw 0.0.5
Torch implementation of Soft-DTW, supports CUDA devices.
Requires Python: >=3.7

# pysdtw

Torch implementation of the [Soft-DTW algorithm](https://github.com/mblondel/soft-dtw), supports both cpu and CUDA hardware.

Note: This repository started as a fork from this [project](https://github.com/Maghoumi/pytorch-softdtw-cuda).

# Installation

This package is available on [pypi](https://pypi.org/project/pysdtw/) and depends on `pytorch` and `numba`.

Install with:

`pip install pysdtw`

# Usage

```python
import pysdtw

# the input data includes a batch dimension
X = torch.rand((10, 5, 7), requires_grad=True)
Y = torch.rand((10, 9, 7))

# optionally choose a pairwise distance function
fun = pysdtw.distance.pairwise_l2_squared

# create the SoftDTW distance function
sdtw = pysdtw.SoftDTW(gamma=1.0, dist_func=fun, use_cuda=False)

# soft-DTW discrepancy, approaches DTW as gamma -> 0
res = sdtw(X, Y)

# define a loss, which gradient can be backpropagated
loss = res.sum()
loss.backward()

# X.grad now contains the gradient with respect to the loss
```
yayc 0.0.2
Yet another YAML configuration library

# yayc

Yet another YAML-based configurator library. Meant for BurstCube and the COSI Telescope, but maybe useful for other projects. 

## Reading a config file


```python
from yayc import Configurator
import yayc.test_data

c = Configurator.open(yayc.test_data.path/"config_example.yaml")
```


```python
c['section:param_int']
```




    1




```python
c['section:param_float']
```




    1.0




```python
c['section:param_string']
```




    'a'




```python
c['section:param_list']
```




    [0, 1, 2, 3]




```python
c['section:param_list2']
```




    ['a', 'b', 'c']



## Overriding a parameter

Usually you have command line programs like this
```
my_app -c config_example.yaml --foo bar
```

You might want to let the user to change the behavior, but also don't want to set a bunch of flags for each option. It's also cumbersome to modify the config file for each run. 

You can have a generic flag that the user can use to change any behavior, e.g.

```
my_app -c config_example.yaml --override "section:param_int = 2" "section:param_string = b"
```

You can parse this using `argparse` and pass the input to `--override` to the `Configurator` object:


```python
override_input = ["section:param_int = 2", "section:param_string = b"]
```


```python
c.override(*override_input)
```


```python
c["section:param_int"]
```




    2




```python
c['section:param_string']
```




    'b'



## Relative paths

It is usually desirable to keep other configuration files together with the yaml file and other logs. this makes it easier to reproduce results. To facilitate this, always use paths relative **to the config file**, not relative to where you executed the progam. Then use this:  


```python
c.absolute_path(c['section:param_path'])
```




    PosixPath('/Users/israel/work/software/yayc/yayc/test_data/my_file.txt')



## Logs

It's good practice to dump the config file, after any override, to the logs:


```python
with open('test.log', 'w') as f:
    f.write(c.dump())
```

## Dynamic initialization

This is a little more advanced. In general, you can initialize any object on the fly if you know the module, the name of the class and the input parameters. We can use this to dynamically instantiate an object of an arbitrary class:


```python
# Creating dummy classes in the current module (__main__)
    
import __main__

class ClassA:
    def __init__(self, *args, **kwargs):
        self._args = args
        self._kwargs = kwargs
    
    def __repr__(self):
        return f"ClassA(args = {self._args}, kwargs = {self._kwargs})"
    
class ClassB:
    def __init__(self, *args, **kwargs):
        self._args = args
        self._kwargs = kwargs
    
    def __repr__(self):
        return f"ClassB(args = {self._args}, kwargs = {self._kwargs})"
```

Initialize the objet on the fly


```python
objects = {label:getattr(__main__, params['class'])(*params['args'], **params['kwargs']) for label,params in c['dynamic_init'].items()}
```


```python
print(objects)
```

    {'objectA': ClassA(args = (1, 'a'), kwargs = {'foo': 2, 'bas': 'b'}), 'objectB': ClassB(args = (), kwargs = {'foo': 3})}