Skip to main content

utility set of handling dict

Project description

https://travis-ci.org/podhmo/dictknife.svg?branch=master

features

  • deepmerge

  • deepequal

  • walker

deepmerge

from dictknife import deepmerge
d0 = {
    "a": {
        "x": 1
    },
    "b": {
        "y": 10
    },
}
d1 = {
    "a": {
        "x": 1
    },
    "b": {
        "z": 10
    },
    "c": 100
}
actual = self._callFUT(d0, d1)
expected = {
    "a": {
        "x": 1
    },
    "b": {
        "y": 10,
        "z": 10
    },
    "c": 100
}
assert actual == expected

walker

using LooseDictWalkingIterator example.

import json
import pprint
from dictknife import LooseDictWalkingIterator

# from: https://github.com/BigstickCarpet/json-schema-ref-parser
d = json.loads("""
{
  "definitions": {
    "person": {
      "$ref": "schemas/people/Bruce-Wayne.json"
    },
    "place": {
      "$ref": "schemas/places.yaml#/definitions/Gotham-City"
    },
    "thing": {
      "$ref": "http://wayne-enterprises.com/things/batmobile"
    },
    "color": {
      "$ref": "#/definitions/thing/properties/colors/black-as-the-night"
    }
  }
}
""")

refs = []

iterator = LooseDictWalkingIterator(["$ref"])
for path, sd in iterator.iterate(d):
    refs.append((path[:], sd["$ref"]))

pprint.pprint(refs)

output

[(['definitions', 'color', '$ref'],
  '#/definitions/thing/properties/colors/black-as-the-night'),
 (['definitions', 'place', '$ref'],
  'schemas/places.yaml#/definitions/Gotham-City'),
 (['definitions', 'thing', '$ref'],
  'http://wayne-enterprises.com/things/batmobile'),
 (['definitions', 'person', '$ref'], 'schemas/people/Bruce-Wayne.json')]

todo: description about chains and operator and context,…

command

install dictknife via pip install dictknife[command].

  • concat

  • transform

  • diff

TODO: gentle introduction

concat

$ dicknife concat a.yaml b.yaml c.json

transform

$ transform --function misc/transform.py:lift --src src/01transform/properties.yaml --name person
# or
$ dictknife transform --code 'lambda d,name=None: {"definitions": {name: d}}' --src src/01transform/properties.yaml --name person

diff

$ dictknife diff a.yaml b.yaml
$ dictknife diff --sort-keys a.yaml b.yaml

0.3

  • command extras pip install dictknife[command]

  • adding dictknife-concat command

  • adding dictknife-transform command

  • adding dictknife-diff command

0.2

  • external iterator is recommened. (using LooseDictWalkingIterator instead of LooseDictWalker)

0.1

  • yaml/json load extras (pip install dictknife[load])

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

dictknife-0.3.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dictknife-0.3-py2.py3-none-any.whl (11.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file dictknife-0.3.tar.gz.

File metadata

  • Download URL: dictknife-0.3.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dictknife-0.3.tar.gz
Algorithm Hash digest
SHA256 1471b52cf2a2cb6e7f18dc632926c778648659301b2c729fd4542410ac43f201
MD5 452dff98a4c3b531bf1121ed4c21f49d
BLAKE2b-256 30f39d3609ce6547195476c4cb1ac19d4e72af1fe8c171a60f80a2d8c40bae5e

See more details on using hashes here.

File details

Details for the file dictknife-0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for dictknife-0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b9e2e2fc4141b8c34d3d474bae78e45bf29da21461a6841617775c37deb95499
MD5 b3e442cd5b33de89be5eeb98e574e893
BLAKE2b-256 ab600ac8ad7073e21766f4ee0e8d73ac8e1a5ccef4d2088a512c4c72aa6ddbfc

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