semvec/pypi-packages huggingface dataset:
nested-dataclasses 0.2
Implements decorator `nested` that adds a parent and children to a dataclass.
Keywords: nested-dataclasses

# nested-dataclasses
Implements decorator `nested` that adds a parent and children to a dataclass.

Both parent and child class should be decorated with nested.

Usage:

Example usage of the parent attribute on a nested dataclass:
```python
from dataclasses import dataclass
from typing import List

from nested_dataclasses import nested


@nested
@dataclass
class TextCount:
    text: str
    count: int

    @property
    def fraction(self):
        return self.count / self.parent.total_count

@nested
@dataclass
class TextCounts:
    counts: List[TextCount]

    @property
    def total_count(self):
        return sum(count.count for count in self.counts)

hello = TextCount("hello", 3)
hi = TextCount("hi", 1)
counts = TextCounts([hello, hi])

counts.validate()

print(counts.counts[0].fraction)
print(counts.children)
print(counts.to_dict())
```

## Installation

We can be installed with:

```bash
pip install nested-dataclasses
```


## Development installation of this project itself

We're installed with [pipenv](https://docs.pipenv.org/), a handy wrapper
around pip and virtualenv. Install that first with `pip install pipenv`. Then run:

```bash
PIPENV_VENV_IN_PROJECT=1 pipenv install --python 3.8 --dev
```

In case you do not have python 3.8 on your machine, install python using 
[pyenv](https://github.com/pyenv/pyenv) and try the previous command again.
See install pyenv below for instructions. 

In order to get nicely formatted python files without having to spend manual
work on it, run the following command periodically:

```bash
pipenv run black nested_dataclasses
```

Run the tests regularly. This also checks with pyflakes, black and it reports
coverage. Pure luxury:

```bash
pipenv run pytest
```

If you need a new dependency (like `requests`), add it in `setup.py` in
`install_requires`. Afterwards, run install again to actually install your
dependency:

```bash
pipenv install --dev
```

## Releasing 
Pipenv installs zest.releaser which allows you to release the package to a git(hub) repo. It has a 
`fullrelease` command that asks you a few questions, which you all respond to with `<enter>`:

```bash
pipenv run fullrelease
```

# Install pyenv
We can install pyenv by running the following commands: 

```bash
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
```

Also make sure to put pyenv in your `.bashrc` or `.zshrc` as instructed by the previous commands. 


Changelog of nested-dataclasses
===================================================


0.1 (2020-06-08)
----------------

- Initial project structure created with cookiecutter and
  https://github.com/PDOK/cookiecutter-python-base

- Added `nested` decorator.

- `nested` decorator uses ValidationMixin and ToDictMixin.
streamlit-ws-localstorage 1.0.6
A simple synchronous way of accessing localStorage from your Streamlit app.
Requires Python: >=3.6
Keywords: python,websocket,cookies,localstorage,streamlit

# streamlit-ws-localstorage
Finally a simple synchronous way of accessing localStorage from your Streamlit app.

[![Downloads](https://static.pepy.tech/personalized-badge/streamlit-ws-localstorage?period=total&units=international_system&left_color=black&right_color=orange&left_text=Downloads)](https://pepy.tech/project/streamlit-ws-localstorage)

# Why
I tried using extra-streamlit-components but found it too complex, because of the way Streamlit components works.
Since the communication between the browser and streamlit app is async, your app is run multiple times, and nested if else blocks may not work properly. A simple call to get all cookies causes the app to be run 4 times in total. And the first call to get all cookies returns an empty dictionary which needs to be handled in the code.

Looking at the complexity, I thought it would be easier to write a synchronous commmunication.


# How to run
Using it is fairly simple:


```python
import streamlit as st
from streamlit_ws_localstorage import injectWebsocketCode, getOrCreateUID

# Main call to the api, returns a communication object
conn = injectWebsocketCode(hostPort='linode.liquidco.in', uid=getOrCreateUID())

st.write('setting into localStorage')
ret = conn.setLocalStorageVal(key='k1', val='v1')
st.write('ret: ' + ret)

st.write('getting from localStorage')
ret = conn.getLocalStorageVal(key='k1')
st.write('ret: ' + ret)
```

You can use the ```linode.liquidco.in``` websocket relay server for testing. Alternately run your websocket relay server from the code in ```websocket-server/ws_server.py```

# Video demo
https://user-images.githubusercontent.com/544881/185042658-43dd3c58-a086-4457-a042-9d4d895e34ba.mp4