Skip to main content

Convert a dict into an object to access items faster.

Project description

Dictoat

Dictoat is a Python utility designed to simplify accessing data stored in dictionaries. It converts dictionaries into Python objects, allowing for more intuitive access to data via attributes instead of dictionary keys. This is ideal for projects where readability and ease of access to complex data structures are essential.

Installation

You can easily install Dictoat using pip:

pip install dictoat

or via git:

git clone https://github.com/niCodeLine/dictoat.git

or just copy-paste it into your code.

Usage

To use Dictoat, simply import the Dictoat class in your Python project and pass a dictionary as an argument. For example:

from dictoat import Dictoat

# Example of using Dictoat
apple_dict = {"flavor": "sweet", "colors": ["red", "green"],"dimentions": {"weigh": 185, "radius": 5}}
apple = Dictoat(apple_dict)

# Accessing the data
print(apple.flavor_)
print(apple.dimentions_.radius_)
print(apple.colors_)

The output would show:

sweet
5
["red", "green"]

Or a more complete example:

from dictoat import Dictoat

pokedex_dict = {
    "total_pokemons": 2,
    "region": "Kanto",
    "Pokemons": {
        "Pikachu": {
            "type": "Electric",
            "abilities": ["Static", "Lightning Rod"],
            "stats": {
                "hp": 35,
                "attack": 55,
                "defense": 40
            }
        },
        "Squirtle": {
            "type": "Water",
            "abilities": ["Torrent", "Rain Dish"],
            "stats": {
                "hp": 44,
                "attack": 48,
                "defense": 65
            },
            "evolutions": ["Wartortle", "Blastoise"]
        }
    }
}

pokedex = Dictoat(pokedex_dict)

# Accessing the data
print("Total Pokémon in Pokedex:", pokedex.total_pokemons_)
print("Pokedex Region:", pokedex.region_)

print("Pikachu Type:", pokedex.Pokemons_.Pikachu_.type_)
print("Pikachu Abilities:", pokedex.Pokemons_.Pikachu_.abilities_)
print("Pikachu HP:", pokedex.Pokemons_.Pikachu_.stats_.hp_)

print("Squirtle Type:", pokedex.Pokemons_.Squirtle_.type_)
print("Squirtle Abilities:", pokedex.Pokemons_.Squirtle_.abilities_)
print("Squirtle Defense:", pokedex.Pokemons_.Squirtle_.stats_.defense_)
print("Squirtle Evolutions:", pokedex.Pokemons_.Squirtle_.evolutions_)

With its output being:

Total Pokémon in Pokedex: 2
Pokedex Region: Kanto

Pikachu Type: Electric
Pikachu Abilities: ['Static', 'Lightning Rod']
Pikachu HP: 35

Squirtle Type: Water
Squirtle Abilities: ['Torrent', 'Rain Dish']
Squirtle Defense: 65
Squirtle Evolutions: ['Wartortle', 'Blastoise']

Features

  • Simple Conversion: Converts any dictionary into an object for easier access.
  • Deep Nesting Support: Supports nested dictionaries, creating sub-objects for each level.

Contributions

Contributions are welcome! If you have improvements or fixes, please send a pull request or open an issue in the GitHub repository.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contact

Nico Spok - nicospok@hotmail.com GitHub: niCodeLine

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dictoat-1.0.2.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file dictoat-1.0.2.tar.gz.

File metadata

  • Download URL: dictoat-1.0.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for dictoat-1.0.2.tar.gz
Algorithm Hash digest
SHA256 e4d41f2e98d0498a43a2661cb2069a7aea345648189f3f63fcf7256173381fbb
MD5 047c809aa46b32efa376313448180934
BLAKE2b-256 ca513828ab1a5a472b80da2d05d599cddc39adf8a7a2600756e63f83c80df157

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page