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
Discord bot for Ukrfans Discord server

Ukrfans Discord Bot Discord bot for Ukrfans Discord server. ๐Ÿ’ก Prerequisites Python โš™๏ธ Build & Run Create an .env file in the root directory and add t

3 Jun 24, 2022
An anime themed telegram bot that can convert telegram media.

ShoukoKomiRobot โ€ข ๐•Ž๐•ฃ๐•š๐•ฅ๐•ฅ๐•–๐•Ÿ ๐•€๐•Ÿ Python3 โ€ข ๐•ƒ๐•š๐•“๐•ฃ๐•’๐•ฃ๐•ช ๐•Œ๐•ค๐•–๐•• Pyrogram โ€ข ๐•Š๐• ๐•—๐•ฅ๐•จ๐•’๐•ฃ๐•– ๐•Œ๐•ค๐•–๐•• Ebook-convert Deploy ๐”ฝ๐• ๐•ฃ๐•œ ๐•ฅ๐•™๐•š๐•ค ๐•ฃ

25 Aug 14, 2022
Rich presence app for playstation 3. Display what game you are playing on the PS3 via Discord

PS3-Rich-Presence-for-Discord Discord Rich Presence script for PS3 consoles on HFW&HEN or CFW. Written in Python. Display what you are playing on your

17 Dec 11, 2022
Unauthenticated enumeration of services, roles, and users in an AWS account or in every AWS account in existence.

Quiet Riot ๐ŸŽถ C'mon, Feel The Noise ๐ŸŽถ An enumeration tool for scalable, unauthenticated validation of AWS principals; including AWS Acccount IDs, roo

Wes Ladd 89 Jan 05, 2023
A python crypto trading bot on Binance using RSI in 25 Lines ๐Ÿš€

RSI Crypto Trading Bot - Binance A Crypto Trading Bot on Binance trading BTCUSDT and ETHUSDT using RSI in 25 Lines of Code Getting Started Note Python

Blankly Finance 10 Dec 26, 2022
Telegram music & video bot direct play music

โšก NOINOI MUSIC PLAYER ๐ŸŽต SUPERFAST MUSIC BOT WHO CAN DIRECT PLAY SONG ON TELEGRAM VOICE CHAT ALSO CAN PLAY VIDEO ON VOICE CHATS โœจ Heroku Deploy YOU CA

noinoi-X 1 Dec 28, 2021
This is a python wrapper for "the best api in the world"

This is a python wrapper for my api api_url = "https://api.dhravya.me/" This wrapper now has async support, its basically the same except it uses asyn

Dhravya Shah 3 Dec 21, 2021
Unofficial Coinbase Python Library

Unofficial Coinbase Python Library Python Library for the Coinbase API for use with three legged oAuth2 and classic API key usage Version 0.3.0 Requir

George Sibble 104 Dec 01, 2022
PS3API - PS3 API for TMAPI and CCAPI in python.

PS3API PS3 API for TMAPI and CCAPI in python. Examples Connecting and Attaching from ps3api import PS3API PS3 = PS3API(PS3API.API_TMAPI) if PS3.Conn

Adam 9 Sep 01, 2022
Probably Overengineered Unimore Booker

POUB Probably Overengineered Unimore Booker A python-powered, actor-based, telegram-facing, timetable-aware booker for unimore (if you know more adjec

Lorenzo Rossi 3 Feb 20, 2022
A simple library for interacting with Amazon S3.

BucketStore is a very simple Amazon S3 client, written in Python. It aims to be much more straight-forward to use than boto3, and specializes only in

Jacobi Petrucciani 219 Oct 03, 2022
Monitor your Binance portfolio

Binance Report Bot The intent of this bot is to take a snapshot of your binance wallet, e.g. the current balances and store it for further plotting. I

37 Oct 29, 2022
A Discord bot that allows you to rapidly deploy Minecraft servers seamlessly and painlessly from Discord.

Lyra - rapidly and painlessly deploy Minecraft servers from Discord Lyra lets you deploy Minecraft server instances via Docker with control through a

1 Dec 23, 2021
Projeto de teste para acesso a API SWAPI.

SwapiTest Projeto de teste para acesso a API Swapi com informaรงรตes sobre Star Wars. Como rodar o programa Foi utilizado o pipenv, entรฃo basta clonar o

Gabriel de Souza Alves 1 Nov 23, 2021
Source code of u/pekofy_bot from reddit.

pekofy-bot Source code of u/pekofy_bot from reddit. Get more info about the bot here: https://www.reddit.com/user/pekofy_bot/comments/krxxol/pekofy_bo

32 Dec 25, 2022
A Simple Telegram Maths Calculator Bot

Calculator-Bot-v1 A Simple Telegram Maths Calculator Bot Demo BOT LINK: Variables Variables Required Variables API_HASH: Get

แ—ชแ—ฉแ–‡K โœžOแ–‡แ—ช 1 Dec 18, 2021
Python client for Invidious' JSON API

Python project template A template for new Python projects. Features Automatically builds PDoc documentation & uploads package to PyPI on new GitHub r

Kevo 2 Jun 05, 2022
ANKIT-OS/TG-SESSION-HACK-BOT: A Special Repository.Telegram Bot Which Can Hack The Victim By Using That Victim Session

๐Ÿ”ฐ แต€แดฑแดธแดฑแดณแดฟแดฌแดน แดดแดฌแถœแดท แดฎแดผแต€ ๐Ÿ”ฐ The owner would not be responsible for any kind of bans due to the bot. โ€ข โšก INSTALLING โšก โ€ข โ€ข ๐Ÿ› ๏ธ Lแด€ษดษขแดœแด€ษขแด‡s Aษดแด… TแดแดสŸs ๐Ÿ”ฐ โ€ข If

ANKIT KUMAR 2 Dec 24, 2021
An Amazon Product Scraper built using scapy module of python

Amazon Product Scraper This is an Amazon Product Scraper built using scapy module of python Features it scrape various things Product Title Product Im

Sudhanshu Jha 1 Dec 13, 2021
Irenedao-nft-generator - Original scripts used to generate IreneDAO NFTs

IreneDAO NFT Generator Scripts to generate IreneDAO NFT. Make sure you have Pill

libevm 60 Oct 27, 2022