Skip to main content

dukepy

collection of useful python snippets

pip install dukepy

config

Confiuration manager (using json) with the ability to

  • add new keys
  • remove deprecated keys (i.e. keys not in defaults)
  • backup the older versions of the (json) configuration file

Generated sample file -

C:\Users\xyz.myconfig\config.json

{
    "newkey1": "newvalue1",
    "newkeygroup1": {
        "newkey2": "newvalue2"
    },
    "newkey3": [
        "newvalue4",
        "newvalue4"
    ],
    "newkey5": "newvalue5"
}

Usage example -

import os

from dukepy.config import Config

config_dir = os.path.join(os.path.expanduser("~"), ".myconfig")
config_file = os.path.join(config_dir, "config.json")
Config(path=config_file, defaults={
    "newkey1": "newvalue1",
    "newkeygroup1": {
        "newkey2": "newvalue2"
    },
    "newkey3": ["newvalue4", "newvalue4"]
})

Config()["newkey5"] = "newvalue5"
Config().commit()

converge

To find the extremes of a finite sequence, given that the sequence is continuous. Provide at least two known numbers in the sequence, and a method to check the validity of the number predicted by the algorithm.

Usage example -

def check_validity(val):
    if val > -30 and val < 101:
        return True
    else:
        return False


low, high = Converge(-28, 50, check_validity).run()
print(low)
print(high)

Output -

-29
100

dict_diff

  • To find the recursive differences between two dictionaries.
  • To update one dictionary with the other (each one optional)-
    • Add keys from the other
    • Remove keys which are not part of the other
    • Update values from the keys of the other

Usage example -

dictionary_1 = {"abc": "value_abc",
                    "prs": "value_prs"}
    dictionary_2 = {"abc": "value_abc",
                    "xyz": "value_xyz"}
    dict_diff(dictionary_1, dictionary_2)
    print(dictionary_1)
    print(dictionary_2)

    dict_diff(dictionary_1, dictionary_2,
              udpate_added_keys=True)

    print(dictionary_1)
    print(dictionary_2)

Output -

:
 -  prs  :  value_prs
 :
 +  xyz  :  value_xyz
{'abc': 'value_abc', 'prs': 'value_prs'}
{'abc': 'value_abc', 'xyz': 'value_xyz'}
 :
 -  prs  :  value_prs
 :
 +  xyz  :  value_xyz
{'abc': 'value_abc', 'prs': 'value_prs', 'xyz': 'value_xyz'}
{'abc': 'value_abc', 'xyz': 'value_xyz'}

logger

mail_bot

safe_dict

singleton

taces

Prints the origin of the exception, not just the exception string. Usage example -

mydict = dict()
    try:
        print(mydict["sdf"])
    except Exception as e:
        print_exception_traces(e)

Output -

Traceback (most recent call last):
  File "C:/Dev/libpython/src/dukepy/traces.py", line 16, in <module>
    print(mydict["sdf"])
KeyError: 'sdf'

Download files

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

Source Distribution

dukepy-1.3.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

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

dukepy-1.3.0-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file dukepy-1.3.0.tar.gz.

File metadata

  • Download URL: dukepy-1.3.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for dukepy-1.3.0.tar.gz
Algorithm Hash digest
SHA256 6c92b93d353e1fddf6ae59d1e77653946da535416f0695da6f71367f5062463c
MD5 7690adc0dca0b195cd7405b308d26225
BLAKE2b-256 2928bf95262b49dbd1407444c5aec16f203979f2682aafda801ed0df88f95098

See more details on using hashes here.

File details

Details for the file dukepy-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: dukepy-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for dukepy-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34027be43d9ac6523b7aac09ff2cf46d6a12b8f89eacfea9cc6f6797db6b2aa9
MD5 51fe72e12a6da39ee7d9d7a493b97c86
BLAKE2b-256 8de6c966ab0248c384c4dd13d52d5b4c5847404d87577bff84ec93de8457d681

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

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