PyDottie is a version of Dottie.js written in Python 3.

Overview

PyDottie

PyDottie is a version of Dottie.js written in Python 3.

Table of Contents.

Description

PyDottie helps you to play with nested keys in dictionaries.

Installation

$ pip install pydottie

or

$ pip3 install pydottie

Basic Usage

Get

Gets nested value, or None if unreachable, or a default value if passed.

# PyDottie
import pydottie

values = {
    'some': {
        'nested': {
            'key': 'foobar',
        }
    },
    'some.dot.included': {
        'key': 'barfoo'
    }
}

# returns 'foobar'
print(pydottie.get(values, 'some.nested.key'))

# returns None
print(pydottie.get(values, 'some.undefined.key'))

# returns 'defaultval'
print(pydottie.get(values, 'some.undefined.key', 'defaultval'))

# returns 'barfoo'
print(pydottie.get(values, ['some.dot.included', 'key']))

Set value

Sets nested value, creates nested structure if needed.

# PyDottie
import pydottie

values = {
    'some': {
        'nested': {
            'key': 'foobar',
        }
    },
    'some.dot.included': {
        'key': 'barfoo'
    }
}

pydottie.set_value(values, 'some.nested.value', 'someValue')

pydottie.set_value(values, ['some.dot.included', 'value'], 'someValue')

# force overwrite defined non-object keys into objects if needed
pydottie.set_value(values, 'some.nested.object', 'someValue', force=True)

Transform object

Transform dictionary from keys with dottie notation to nested objects.

# PyDottie
import pydottie

values = {
  'user.name': 'Gummy Bear',
  'user.email': '[email protected]',
  'user.professional.title': 'King',
  'user.professional.employer': 'Candy Mountain'
};

transformed = pydottie.transform(values);

print(transformed);
"""
{
    'user': {
        'name': 'Gummy Bear',
        'email': '[email protected]',
        'professional': {
            'title': 'King',
            'employer': 'Candy Mountain'
        }
    }
}
"""

With a custom delimiter

# PyDottie
import pydottie

values = {
  'user_name': 'Mick Hansen',
  'user_email': '[email protected]'
}
transformed = pydottie.transform(values, delimiter='_');

print(transformed);
"""
{
    'user': {
        'name': 'Mick Hansen',
        'email': '[email protected]'
    }
}
"""

Get paths in dictionary

# PyDottie
import pydottie

values = {
    'a': 1,
    'b': {
        'c': 2,
        'd': {
            'e': 3
        }
    }
}

# ['a', 'b.c', 'b.d.e'];
print(pydottie.paths(values))

Tests

Run the unit tests with the next command.

python3 -m unittest

Credits

Checkout the original source code of dottie.js at https://github.com/mickhansen/dottie.js

LICENSE

MIT

Owner
Jose Noriega
Software Engineer
Jose Noriega
Sample code helps get you started with a simple Python web service using AWS Lambda and Amazon API Gateway

Welcome to the AWS CodeStar sample web service This sample code helps get you started with a simple Python web service using AWS Lambda and Amazon API

0 Jan 20, 2022
The official Magenta Voice Skill SDK used to develop skills for the Magenta Voice Assistant using Voice Platform!

Magenta Voice Skill SDK Development • Support • Contribute • Contributors • Licensing Magenta Voice Skill SDK for Python is a package that assists in

Telekom Open Source Software 18 Nov 19, 2022
A simple telegram bot that resolves video urls using yt-dlp

URL to Video Telegram Bot A simple telegram bot that resolves video urls using yt-dlp Copyright (C) 2021 Vítor Vasconcellos This program is free softw

Vítor 1 Nov 18, 2021
A discord bot consuming Notion API to add, retrieve data to Notion databases.

Notion-DiscordBot A discord bot consuming Notion API to add and retrieve data from Notion databases. Instructions to use the bot: Pre-Requisites: a)In

Servatom 57 Dec 29, 2022
A Python wrapper for Discord RPC API

Discord RPC An Python wrapper for Discord RPC API. Allow you to make own custom RPC Install PyPI pip install discord-rpc Quick example import Discord

LyQuid :3 10 Dec 29, 2022
Telegram Client and Bot that use Artificial Intelligence to auto-reply to scammers and waste their time

scamminator Blocking a scammer is not enough. It is time to fight back. Wouldn't be great if there was a tool that uses Artificial Intelligence to rep

Federico Galatolo 6 Nov 12, 2022
Command-line program to download videos from YouTube.com and other video sites

youtube-dl - download videos from youtube.com or other video platforms INSTALLATION DESCRIPTION OPTIONS CONFIGURATION OUTPUT TEMPLATE FORMAT SELECTION

youtube-dl 116.4k Jan 07, 2023
Self-adjusting, auto-compounding multi-pair DCA crypto trading bot using Python, AWS Lambda & 3Commas API

Self-adjusting, auto-compounding multi-pair DCA crypto trading bot using Python, AWS Lambda & 3Commas API The following code describes how we can leve

Jozef Jaroščiak 21 Dec 07, 2022
Integrating the Daraja-Api with Python language

Mpesa-Daraja-Api Integrating the Daraja-Api with Python language. Credentials.py file This file contains the consumer key and the consumer secrete key

Morvin Ian 3 Nov 09, 2022
A python API for BSCScan (Binance Smart Chain Explorer), available on PyPI.

bscscan-python A complete Python API for BscScan.com, available on PyPI. Powered by BscScan.com APIs. This is a gently modified fork of the etherscan-

Panagiotis Kotsias 246 Dec 31, 2022
Credit Card And SK Checker Written In Python

Credit Card And SK Checker Written In Python

Rimuru Tempest 57 Jan 08, 2023
EpikCord.py - This is an API Wrapper for Discord's API for Python

EpikCord.py - This is an API Wrapper for Discord's API for Python! We've decided not to fork discord.py and start completely from scratch for a new, better structuring system!

EpikHost 28 Oct 10, 2022
Python wrapper for CoWin API's

Cowin Tracker Python API wrapper for CoWin, India's digital platform launched by the government to help citizens register themselves for the vaccinati

Saiprasad Balasubramanian 43 Jun 11, 2022
discord.xp Bot, counts XP for members

discord.xp Bot, counts XP for members. How to setup and run? You must have an mysql database Download libs from the requirements.txt file Configurize

irwing 4 Feb 05, 2022
A code to match you with the perfect Taylor Swift song for your mood and relationship status.

taylorswift A package for matching your current mood and relationship status to a suitable Taylor Swift song. Requirements: Python 2 or 3, and the num

Megan Mansfield 82 Dec 09, 2022
An inline real-time media searching robot without any database.

MediaBuddy A Telegram Inline media searching robot without any database. About mediaBuddy is an inline media searching robot. If you have so many movi

Renjith Mangal 28 Oct 21, 2022
Automatically render tens of thousands of unique NFT images individually as png's.

Blend_My_NFTs Description This project is a work in progress (as of Oct 24th, 2021) and will eventually be an add on to Blender. Blend_My_NFTs is bing

Torrin Leonard 894 Dec 29, 2022
Freqtrade is a free and open source crypto trading bot written in Python.

Freqtrade is a free and open source crypto trading bot written in Python. It is designed to support all major exchanges and be controlled via Telegram. It contains backtesting, plotting and money man

Kazune Takeda 5 Dec 30, 2021
Paginator for Dis-Snek Python Discord API wrapper

snek-paginator Paginator for Dis-Snek Python Discord API wrapper Installation: pip install -U snek-paginator Basic Example: from dis_snek.client impo

1 Nov 04, 2021
Ethereum transactions and wallet information for people you follow on Twitter.

ethFollowing Ethereum transactions and wallet information for people you follow on Twitter. Set up Setup python environment (requires python 3.8): vir

Brian Donohue 2 Dec 28, 2021