Metadata-Version: 2.1
Name: SPYD
Version: 0.1.0
Summary: A smarter python dictionary
Home-page: https://github.com/Mazurex/SPYD
Author: Mazurex
Author-email: Mazurex <business.mazurex@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Mazurex
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyyaml

# Smarter PYthon Dicts (SPYD)

SPYD introduces a new SmartDict object, which has several features that the builtin python dict needs

---

## Table of Contents

1. [Installation](#installation)
2. [Usage](#usage)
3. [License](https://github.com/Mazurex/SPYD/blob/index/LICENSE)

---

## Installation

You can install the library via `pip`:

```bash
pip install spyd
```

You can also find the source code [here](https://github.com/Mazurex/SPYD/tree/index/SPYD)

---

## Usage

After importing the library:

```py
from spyd import SmartDict
```

You can just create a SmartDict as such:

```py
my_dict = SmartDict()
```

If you wish to convert an existing dict into a SmartDict, or you wish to assign values during creation, you can do it as such:

```py
my_dict = SmartDict({"name": "Jeff"})
```

or:

```py
normal_dict = {"name": "Jeff"}
my_dict = SmartDict(normal_dict)
```

One awesome feature of SmartDicts is `dot notation`, it works the same as bracket notation, but easier!
Fortunately, SmartDict accepts both:

```py
my_dict = SmartDict()
# bracket notation
my_dict["hello"] = "world"
# dot notation
my_dict.hello = "world"
```

SmartDicts also automatically create nested SmartDicts when using dot notation:

```py
my_dict = SmartDict()
my_dict.data.name = "Jeff"
```

In the above example, "data" would be created as a SmartDict within the original SmartDict.
Returns:

```py
SmartDict{"data": SmartDict{"name": "Jeff"}}
```

With SmartDicts you can also easily convert to and from JSON and YAML!
Converting a SmartDict to a JSON format is easy:

```py
my_dict = SmartDict()
my_dict.data.name = "test"
my_dict.to_json()
```

The JSON formatted SmartDict can be applied to a JSON like this:

```py
my_dict = SmartDict()
my_dict.data.name = "test"
with open("data.json", "w") as file:
    file.write(my_dict.to_json())
```

The above examples also apply to YAML.

You can also convert JSON and YAML data into SmartDict:

```py
my_dict = SmartDict.from_json()
```

Here you don't have to create a new instance of SmartDict as you're only accessing a static method.
`from_json()` only parameter is formatted JSON or YAML data, which you can get like this:

```py
with open("my_file.json", "r") as file:
    my_dict = SmartDict.from_json(file.read())
```

Once again, the above examples also count for YAML files.

You can also merge a dict into an existing SmartDict:

```py
my_dict = SmartDict()
my_dict.name = "Jeff"
my_dict.hello = "World!"

other_dict = {"hello": "world"}

my_dict.merge(other_dict, overwrite = False)
```

merge simply appends all values from `other_dict` into the existing SmartDict, if the `overwrite` paramter is true, any same key value from the existing SmartDict will be replaced with the new dict's value.

You can also flatten a SmartDict, essentially removing any nesting:

```py
my_dict = SmartDict()
my_dict.data.name = "test"
my_dict.other.address = "321 idk street"
print(my_dict.flatten())
```

Returns:

```py
{'data.name': 'test', 'other.address': '321 idk street'}
```

You can also find keys by looking up values:

```py
my_dict = SmartDict()
my_dict.name = "Jeff"
my_dict.hello = "World!"

print(my_dict.reverse_lookup("World!"))
```

The above print would return "hello" as it is the first occuring key with the value "World!"
