semvec/pypi-packages huggingface dataset:
mypyjsondb 0.0.1
A simple and lightweight JSON mock database for small projects
License: MIT
Keywords: calculator

# mypyjsondb

### A simple and lightweight JSON mock database for small projects

create a new database:

```
db = mypyjsondb.newDB("dbname")
```
---
access an existing database:
```
db = mypyjsondb.DB("dbname")
```
---
get the value of the database:
```
print(db.value()) #value in the form of a dict
```
---
set the value of the database:
```
db.set("hello": "world") #this rewrites the whole database file
```
---
update stuff to the datbase file:
```
db.update({"newkey": "newvalue"})
```
---
delete item from the database file:
```
x.delete("unwantedkey")
```
---
format the data in a database:
```
db.format()
```


Change Log
==========

0.0.1
-------------
- first release
lxmlasdict 0.1.0
"lxmlasdict" allows you to treat lxml tree elements as if you were working with a dict
License: MIT

# lxmlasdict

`lxmlasdict` is just wrapper that allows you to treat lxml tree elements as if you were working with a dict. elements are searched only when accessing keys

```sh
pip install lxmlasdict
```

##

There are a few things to remember when working with this wrapper:
- the wrapper returns None only when accessing the keys "#text" and "@attr" if they do not exist, because they are final elements that have no children.
- the wrapper does not return None when accessing other keys that do not exist; instead, it returns an empty wrapper that can be checked for the None value or its length

## Examples

```py
>>> data = lxmlasdict.from_string("""
...     <root a="testa">
...         <child>
...             <item>text 1</item>
...             <item>text 2</item>
...         </child>
...         <example b="testb">
...             example text
...         </example>
...         <test-ns:example xmlns:test-ns="http://test-ns.com/">
...             example text (namespaced)
...         </test-ns:example>
...     </root>
... """)
```

#### Accessing to only one element

```py
>>> print(data['child']['item']['#text'])
elements
```

#### Accessing to multiple elements

```py
>>> for item in data['child']['item']:
...     print(item['#text'])
... 
elements
more elements
```

#### Checking for element presence

```py
>>> if data['child']['item']:
...     print('element exists')
... else:
...     print('element does not exist')
... 
element exists

>>> if data['child']['test']:
...     print('element exists')
... else:
...     print('element does not exist')
... 
element does not exist
```

#### Counting the number of elements

```py
>>> print(len(data['child']['item']))
2
```

### Accessing attributes

```py
>>> print(data['@a'])
testa

>>> print(data['example']['@b'])
testb
```

### Accessing to elements with namespace

```py
>>> print(data['test-ns:example']['#text'])
example text (namespaced)
```


### Convert element and its contents to dict

```py
>>> data = lxmlasdict.to_dict(data)
>>> print(json.dumps(data, indent=4))
{
    "root": {
        "child": {
            "item": [
                "text 1",
                "text 2"
            ]
        },
        "example": {
            "@b": "testb",
            "#text": "example text"
        },
        "test-ns:example": "example text (namespaced)",
        "@a": "testa"
    }
}
```