semvec/pypi-packages huggingface dataset:
micropython-mpy-env 0.2.0
Simple environment variable loader for MicroPython board.
License: MIT
Keywords: MicroPython

# micropython-env
Simple environment variable loader for MicroPython board.

The loader could load environment variables from the one of file format as below:
- [JSON] (default) : The file name is "env.json" (text mode).
- [MessagePack]: The file name is "env" or "env.msgpack" (binary mode).

## MessagePack
Note:
- MessagePack Array corresponds to  Python Tuple, not List
> Change in v0.2.0

MessagePack predefined extension types:
|Name|Type|Support?|
|:-:|:-:|:-:|
|Timestamp|`-1`|X|

MessagePack application-specific extension types:
|Name|Type|Support?|Description|
|:-:|:-:|:-:|:-:|
|List|`1`|O| Python List, legth limit: 65535. <br><small><i>New in v0.2.0</i></small>|

# How to Use
```python
from mpy_env import load_env, get_env, put_env

# Loading `env.json` at once as default.
# You can invoke below function in `boot.py`
load_env()
# or
load_env(0)

# You can loading environment variables from MessagePack as below.
load_env(1)

# In `main.py` or the other,
# You can invoke below function to get environment variable.
get_env('key')

# You can invoke below function to set environment variable in-memory.
put_env('tuple', ('a', 1))
```

# Testing
Currentl testing environment:
- Python 3.7
- MicroPython unix port 1.12 ＆ 1.13
- MicroPython esp32 port 1.12＆ 1.13

Before tesing, you need to compile Micopython unix port executable first, see [offcial GitHub Wiki] to setup.

After setup, you must set environment variable `MPY_PATH` as path of local MicroPython repository.
> Environment variable`MPY_PATH` is used in shell script `bin/build_micropython.sh`

We use [mpfshell] to interactive with MicroPython board,  please install the latest release from PyPi.
```
pip install mpfshell
```

We use [offcial MessagePack package] to validate custom `msgpack` module, please install the latest release from PyPi.
```
pip install msgpack
```

Next, clone the repository to your local machine.
```
git clone https://github.com/ShenTengTu/micropython-env.git
cd micropython-env
```

You can execute the follow command to build muitiple versions of MicroPython unix port.
```
export MPY_PATH=<local_micropython_repo> && make build-mpy
```
> It will create symbolic links into user binaries directory after building.

To test on Python & MicroPython unix port,  execute the command as below.
```
make testing 
```
>  It will run testing on multiple MicroPython unix port versions.

To test on ESP32 board, execute the follow command.
```
make mpy-testing-esp32
```
>  It will run testing on multiple MicroPython esp32 port versions.

## Development
See "Development guide" in [CONTRIBUTING.md](CONTRIBUTING.md).

[JSON]: https://www.json.org/ 
[MessagePack]: https://msgpack.org/
[offcial GitHub Wiki]: https://github.com/micropython/micropython/wiki/Getting-Started
[mpfshell]: https://github.com/wendlers/mpfshell
[offcial MessagePack package]: https://github.com/msgpack/msgpack-python
witnet-lib 1.0.0
Lightclient implementation library for witnet node
License: MIT
Keywords: witnet blockchain lightclient proto

## Witnet Library

This library is light client implementation for witnet node, capable of directly interacting with witnet node. ( See [Witnet.io](https://witnet.io/) for more information )

### Features

- Allows sending proto messages to witnet node.
- Performs handshake with witnet node.
- Iterates over the nodes in witnet network in a DAG(directed acyclic graph) fashion

### How to use

Performing handshake with witnet node.

```python
from witnet_lib.witnet_client import WitnetClient
from witnet_lib.utils import AttrDict

# Setting config
config = AttrDict({
    "genesis_sec": 1602666000,
    "magic": 40941,
    "sender_addr": "127.0.0.1:21341",
    "time_per_epoch": 45,
})
client = WitnetClient(config)
client.handshake("127.0.0.1:21337")
client.close()
```

Listening to messages from witnet node.

```python
#After performing handshake with node.
msg = client.receive_msg() # this returns serialized message from node
parsed_msg = client.msg_handler.parse_msg(msg) # we need to parse the message
print(parsed_msg)
print(parsed_msg.kind)
```

The connection is of `keep alive` type, so messages are continually sent from witnet node. To listen for all messages:

```python
while True:
    msg = client.receive_msg() # this returns serialized message from node
    parsed_msg = client.msg_handler.parse_msg(msg)
    print(parsed_msg)
```

Sending message to witnet node.

```python
#After performing handshake with node.
cmd = client.msg_handler.version_cmd("127.0.0.1:21337") # this returns a version message
print(cmd)
msg = client.msg_handler.serialize(cmd)# this returns serialized messsage ready to be sent to node
client.send_msg(msg)
msg_from_node = client.receive_msg() # this returns only one whole message from node
msg_from_node_with_msg_len, reced_or_not = client.tcp_handler.receive(30) # this returns x bytes from connection stream
```

Mapping all nodes in the network (DAG fashion)

```python
from witnet_lib import utils
from witnet_lib.map_nodes  import MapNodes
config = utils.AttrDict({
    "genesis_sec": 1602666000,
    "magic": 40941,
    "sender_addr": "127.0.0.1:21341",
    "time_per_epoch": 45,
})
mapper = MapNodes(config, ["127.0.0.1:21337"]) # provide initialisation peers
all_nodes, active_map = mapper.start_mapping_workers(3) # number of connections allowed to be created in parallel
print(all_nodes)
print(active_map) # it contains node id with the list of its peers
```